SnapshotDecoder class Null safety

Holds methods to convert Snapshots to objects of specific types.

The SnapshotDecoder.defaultDecoder handles conversions of common dart types. The following conversions are available by default:

from typeto typeformatdescription
StringDateTimenulluses DateTime.parse
numDateTime'epoch'milliseconds since epoch
StringUrinulluses Uri.parse
Stringint'radix:{radix}'uses int.parse with radix
Stringint'string'uses int.parse
Stringdouble'string'uses double.parse
Stringnum'string'uses num.parse
StringDateTime'{date-format}'uses intl.DateFormat.parse

A custom decoder can be created by calling one of the constructors and registering new conversion functions. Before a decoder can be used, it needs to be sealed by calling SnapshotDecoder.seal. Once sealed, it is not allowed to register any additional converters.

Constructors

SnapshotDecoder()
Create a new, unsealed SnapshotDecoder containing the default converters
SnapshotDecoder.empty()
Create a new, unsealed empty SnapshotDecoder
SnapshotDecoder.from(SnapshotDecoder other)
Create a new, unsealed SnapshotDecoder containing the converters in the decoder other.

Properties

hashCode int
The hash code for this object.
read-onlyinherited
isSealed bool
true when this decoder is sealed
read-only
runtimeType Type
A representation of the runtime type of the object.
read-onlyinherited

Methods

convert<T>(Snapshot input, {String? format}) → T
Converts input to an object of type T
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
inherited
register<S, T>(T converter(S), {Pattern? format}) → void
Registers a conversion function
seal() → void
Seals this decoder
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

defaultDecoder SnapshotDecoder
The default, sealed SnapshotDecoder
read-only