decode static method
- dynamic input, [
- DecodeOptions? options
Decodes a String or Map<String, dynamic> into a Map<String, dynamic>.
Providing custom options
will override the default behavior.
Implementation
static Map<String, dynamic> decode(dynamic input, [DecodeOptions? options]) {
options ??= const DecodeOptions();
if (!(input is String? || input is Map<String, dynamic>?)) {
throw ArgumentError.value(
input,
'input',
'The input must be a String or a Map<String, dynamic>',
);
}
if (input?.isEmpty ?? true) {
return <String, dynamic>{};
}
final Map<String, dynamic>? tempObj = input is String
? _$Decode._parseQueryStringValues(input, options)
: input;
if (options.parseLists &&
options.listLimit > 0 &&
(tempObj?.length ?? 0) > options.listLimit) {
options = options.copyWith(parseLists: false);
}
Map<String, dynamic> obj = {};
// Iterate over the keys and setup the new object
if (tempObj?.isNotEmpty ?? false) {
for (final MapEntry<String, dynamic> entry in tempObj!.entries) {
obj = Utils.merge(
obj,
_$Decode._parseKeys(
entry.key,
entry.value,
options,
input is String,
),
options,
);
}
}
return Utils.compact(obj);
}