SnapshotDecoder class
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 type | to type | format | description |
---|---|---|---|
String | DateTime | null | uses DateTime.parse |
num | DateTime | 'epoch' | milliseconds since epoch |
String | Uri | null | uses Uri.parse |
String | int | 'radix:{radix}' | uses int.parse with radix |
String | int | 'string' | uses int.parse |
String | double | 'string' | uses double.parse |
String | num | 'string' | uses num.parse |
String | DateTime | '{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
Methods
-
convert<
T> (Snapshot input, {String? format}) → T -
Converts
input
to an object of type T -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent 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
no setter