DynamicValue class

Data access with type conversion, it is convenient to use when parsing JSON.

Examples:

final jsonResponse = jsonDecode(response);
final data = DynamicValue(jsonResponse);
data['message']['id'].toInt
data['message']['text'].toStr
data['message']['timestamp'].toDateTime
data['message']['tags'][0]['text'].toStr

Constructors

DynamicValue(dynamic value)
Creates an instance of the DynamicValue by wrapping the value.

Properties

hashCode int
The hash code for this object.
no setteroverride
isNotNull bool
Returns true if value is not null.
no setter
isNull bool
Returns true if value is null.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
toBool bool
no setter
toDateTime DateTime?
no setter
toDouble double?
no setter
toInt int?
no setter
toNum num?
no setter
toStr String?
no setter
type DynamicValueType
no setter
value → dynamic
Raw type
final

Methods

has(dynamic key) bool
Returns true if this map contains the given key or index.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
to<T>({T? defaultValue, DynamicValueItemBuilder<T>? builder, DynamicValueRawItemBuilder<T>? rawBuilder}) → T?
Convert value to T type
toList<T>({List<T>? defaultValue, DynamicValueItemBuilder<T>? itemBuilder, DynamicValueRawItemBuilder<T>? itemRawBuilder}) List<T>?
Convert value to List of T types
toMap<K, V>({Map<K, V>? defaultValue, DynamicValueKeyBuilder<K>? keyBuilder, DynamicValueMapItemBuilder<K, V>? valueBuilder, DynamicValueRawMapItemBuilder<K, V>? valueRawBuilder}) Map<K, V?>?
Convert value to typed Map
toString() String
A string representation of this object.
override

Operators

operator ==(covariant DynamicValue other) bool
The equality operator.
override
operator [](dynamic key) DynamicValue
Returns the DynamicValue for the given key or DynamicValue(null) if key is not in the map.

Static Properties

builders Map<Type, dynamic Function(DynamicValue data)>
Type converters from DynamicValue type
getter/setter pair
rawBuilders Map<Type, dynamic Function(dynamic value)>
Type converters from raw data type
getter/setter pair