DataObject class abstract interface

An interface for a data object with property values accessed by String keys.

See samples below to create a copied data object, a view wrapping an instance of the standard Map, and decoding one from JSON.

final copied = DataObject.of({'foo': 1, 'bar': 'two'});

final map = {'foo': 1, 'bar': 'two', 'other', null};
final view = DataObject.view(map);

final json = DataObject.decodeJson('{"foo": 1, "bar": "two"}');

As this class is defined with the class modifier interface, the class can only be implemented, but not extended. This class also provides factory methods constructing instances of the default implementation provided by DataObjectView.

Implemented types
Implementers

Constructors

DataObject.decodeJson(String source)
Creates a data object from source containing an encoded JSON Object.
factory
DataObject.empty()
Creates an empty data object.
factory
DataObject.of([Map<String, Object?> source = const {}])
Creates a data object with items copied from source.
factory
DataObject.view(Map<String, Object?> source)
Creates a data object view backed by source.
factory

Properties

arrays Iterable<DataArray>
Returns an iterable for childs that can be represented as DataArray.
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
isEmpty bool
Returns true if the collection has no elements.
no setterinherited
isNotEmpty bool
Returns true if the collection has at least one element.
no setterinherited
keys Iterable<String>
Returns map keys.
no setter
length int
Returns the number of elements in this collection.
no setterinherited
objects Iterable<DataObject>
Returns an iterable for childs that can be represented as DataObject.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

array(String key) DataArray
Returns a child data array at key.
inherited
arraysToList<T extends Object>(T map(DataArray array), {int? limit}) List<T>
Returns a list of T mapped from child data arrays using map function.
inherited
encodeJson({Object encodeTime(DateTime time)?}) String
Encodes this element into a JSON string.
inherited
exists(String key) bool
Returns true if the key references an existing value, null or non-null.
inherited
existsNonNull(String key) bool
Returns true if a value at key exists and that value is non-null.
inherited
existsNull(String key) bool
Returns true if a value at key exists and that value is null.
inherited
getBigInt(String key, {BigInt? min, BigInt? max}) BigInt
Returns a value at key as BigInt.
inherited
getBool(String key) bool
Returns a value at key as bool.
inherited
getDouble(String key, {double? min, double? max}) double
Returns a value at key as double.
inherited
getId(String key) Identifier
Returns a value at key as Identifier.
inherited
getInt(String key, {int? min, int? max}) int
Returns a value at key as int.
inherited
getNum(String key, {num? min, num? max}) num
Returns a value at key as num.
inherited
getString(String key) String
Returns a value at key as String.
inherited
getTimeUTC(String key, {DateTime parse(Object?)?}) DateTime
Returns a value at key as DateTime in the UTC time zone.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
object(String key) DataObject
Returns a child data object at key.
inherited
objectsToList<T extends Object>(T map(DataObject object), {int? limit}) List<T>
Returns a list of T mapped from child data objects using map function.
inherited
toJson() → dynamic
Returns data as an encodable object compatible with json.encode().
inherited
toNullableValueMap<T extends Object>() Map<String, T?>
Returns map items (key-value pairs) with values represented as T?.
toString() String
A string representation of this object.
inherited
toValueMap<T extends Object>() Map<String, T>
Returns map items (key-value pairs) with values represented as T.
tryArray(String key) DataArray?
Returns a child data array at key or null if missing.
inherited
tryBigInt(String key, {BigInt? min, BigInt? max}) BigInt?
Returns a value at key as BigInt or null if missing.
inherited
tryBool(String key) bool?
Returns a value at key as bool or null if missing.
inherited
tryDouble(String key, {double? min, double? max}) double?
Returns a value at key as double or null if missing.
inherited
tryId(String key) Identifier?
Returns a value at key as Identifier or null if missing.
inherited
tryInt(String key, {int? min, int? max}) int?
Returns a value at key as int or null if missing.
inherited
tryNum(String key, {num? min, num? max}) num?
Returns a value at key as num or null if missing.
inherited
tryObject(String key) DataObject?
Returns a child data object at key or null if missing.
inherited
tryString(String key) String?
Returns a value at key as String or null if missing.
inherited
tryTimeUTC(String key, {DateTime parse(Object?)?}) DateTime?
Returns a value at key as DateTime in the UTC time zone, or null.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited
operator [](String key) Object?
Returns a value at key, the result can be of any object or null.
inherited

Static Methods

from<K extends Object, V extends Object>(Map<K, V> source, MapEntry<String, Object> convert(K, V)) DataObject
Creates a data object with items mapped from source of K - V pairs.