KeyedArchive class Null safety

A container for a dynamic data object that can be decoded into Coding objects.

A KeyedArchive is a Map, but it provides additional behavior for decoding Coding objects and managing JSON Schema references ($ref) through methods like decode, decodeObject, etc.

You create a KeyedArchive by invoking KeyedArchive.unarchive and passing data decoded from a serialization format like JSON and YAML. A KeyedArchive is then provided as an argument to a Coding subclass' Coding.decode method.

    final json = json.decode(...);
    final archive = KeyedArchive.unarchive(json);
    final person = Person()..decode(archive);

You may also create KeyedArchives from Coding objects so that they can be serialized.

    final person = Person() = "Bob";
    final archive = KeyedArchive.archive(person);
    final json = json.encode(archive);
Mixed in types


KeyedArchive(Map<String, dynamic> _map)
Use unarchive instead.
KeyedArchive.unarchive(Map<String, dynamic> _map, {bool allowReferences = false})
Unarchives data into a KeyedArchive that can be used by Coding.decode to deserialize objects. [...]


entries Iterable<MapEntry<String, dynamic>>
The map entries of this.
read-only, inherited
hashCode int
The hash code for this object. [...]
read-only, inherited
isEmpty bool
Whether there is no key/value pair in the map.
read-only, inherited
isNotEmpty bool
Whether there is at least one key/value pair in the map.
read-only, inherited
keys Iterable<String>
The keys of this. [...]
read-only, override
length int
The number of key/value pairs in the map.
read-only, inherited
referenceURI Uri?
A reference to another object in the same document. [...]
read / write
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
values Iterable
The values of this. [...]
read-only, inherited


addAll(Map<String, dynamic> other) → void
Adds all key/value pairs of other to this map. [...]
addEntries(Iterable<MapEntry<String, dynamic>> newEntries) → void
Adds all key/value pairs of newEntries to this map. [...]
cast<RK, RV>() Map<RK, RV>
Provides a view of this map as having RK keys and RV instances, if necessary. [...]
castValues(Map<String, Cast>? schema) → void
Typecast the values in this archive. [...]
clear() → void
Removes all entries from the map. [...]
containsKey(Object? key) bool
Whether this map contains the given key. [...]
containsValue(Object? value) bool
Whether this map contains the given value. [...]
decode<T>(String key) → T?
Returns the object associated by key. [...]
decodeObject<T extends Coding>(String key, T inflate()) → T?
Returns the instance of T associated with key. [...]
decodeObjectMap<T extends Coding>(String key, T inflate()) Map<String, T?>?
Returns a map of Ts associated with key. [...]
decodeObjects<T extends Coding>(String key, T? inflate()) List<T?>?
Returns a list of Ts associated with key. [...]
encode(String key, dynamic value) → void
Encodes value into this object for key. [...]
encodeObject(String key, Coding? value) → void
Encodes a Coding object into this object for key. [...]
encodeObjectMap<T extends Coding?>(String key, Map<String, T>? value) → void
Encodes map of Coding objects into this object for key. [...]
encodeObjects(String key, List<Coding?>? value) → void
Encodes list of Coding objects into this object for key. [...]
forEach(void action(String key, dynamic value)) → void
Applies action to each key/value pair of the map. [...]
map<K2, V2>(MapEntry<K2, V2> transform(String key, dynamic value)) Map<K2, V2>
Returns a new map where all entries of this map are transformed by the given convert function.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
putIfAbsent(String key, dynamic ifAbsent()) → dynamic
Look up the value of key, or add a new entry if it isn't there. [...]
remove(Object? key) → dynamic
Removes key and its associated value, if present, from the map. [...]
removeWhere(bool test(String key, dynamic value)) → void
Removes all entries of this map that satisfy the given test.
resolveOrThrow(ReferenceResolver coder) → void
Validates referenceURIs for this object and any objects it contains. [...]
toPrimitive() Map<String, dynamic>
toString() String
A string representation of this object. [...]
update(String key, dynamic update(dynamic value), {dynamic ifAbsent()?}) → dynamic
Updates the value for the provided key. [...]
updateAll(dynamic update(String key, dynamic value)) → void
Updates all values. [...]


operator ==(Object other) bool
The equality operator. [...]
operator [](covariant Object key) → dynamic
The value for the given key, or null if key is not in the map. [...]
operator []=(covariant String key, dynamic value) → void
store the key/value pair into the map

Static Methods

archive(Coding root, {bool allowReferences = false}) Map<String, dynamic>
Archives a Coding object into a Map that can be serialized into format like JSON or YAML. [...]