DataObject class abstract
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"}');
- Inheritance
-
- Object
- PrimitiveAccessor<
String> - ValueAccessor<
String> - DataElement<
String> - DataObject
- Implementers
Constructors
- DataObject.new()
-
Default
const
constructor to allow extending this abstract class.const - 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 usingmap
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
asBigInt
.inherited -
getBool(
String key) → bool -
Returns a value at
key
asbool
.inherited -
getDouble(
String key, {double? min, double? max}) → double -
Returns a value at
key
asdouble
.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
asint
.inherited -
getNum(
String key, {num? min, num? max}) → num -
Returns a value at
key
asnum
.inherited -
getString(
String key) → String -
Returns a value at
key
asString
.inherited -
getTimeUTC(
String key, {DateTime parse(Object?)?}) → DateTime -
Returns a value at
key
asDateTime
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 usingmap
function.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
asBigInt
or null if missing.inherited -
tryBool(
String key) → bool? -
Returns a value at
key
asbool
or null if missing.inherited -
tryDouble(
String key, {double? min, double? max}) → double? -
Returns a value at
key
asdouble
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
asint
or null if missing.inherited -
tryNum(
String key, {num? min, num? max}) → num? -
Returns a value at
key
asnum
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
asString
or null if missing.inherited -
tryTimeUTC(
String key, {DateTime parse(Object?)?}) → DateTime? -
Returns a value at
key
asDateTime
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