A data format that can encode different types of data.
The role of this interface is to convert the supported types into encoded data. Different implementations of this interface can support different data types and encoding strategies.
Encoding is performed by an SelfEncodable or Encodable implementation calling one of the typed Encoder.encode...() methods of this interface.
/// Example of a [Encodable.encode] implementation:
@override
void encode(Data value, Encoder encoder) {
encoder.encodeString(value.stringProperty);
}
A data format may only support a subset of the encoding types. If the Encoder is not able to encode the provided data, it should throw an exception with a detailed message.
An SelfEncodable or Encodable implementation is expected to call exactly one of the encoding methods a single time. Never more or less.
- Implementers
- Available extensions
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
canEncodeCustom<
T> () → bool -
Checks if the encoder can encode the custom type
T
. -
encodeBool(
bool value) → void - Encodes a boolean value.
-
encodeBoolOrNull(
bool? value) → void - Encodes a nullable boolean value.
-
encodeDouble(
double value) → void - Encodes a double value.
-
encodeDoubleOrNull(
double? value) → void - Encodes a nullable double value.
-
encodeFuture<
T> (Future< T> value, {Encodable<T> ? using}) → void -
Available on Encoder, provided by the AsyncEncoder extension
Encodes a Future ofT
using the provided Encodable. -
encodeFutureOrNull<
T> (Future< T> ? value, {Encodable<T> ? using}) → void -
Available on Encoder, provided by the AsyncEncoder extension
Encodes a Future ofT
or null using the provided Encodable. -
encodeInt(
int value) → void - Encodes an integer value.
-
encodeIntOrNull(
int? value) → void - Encodes a nullable integer value.
-
encodeIterable<
E> (Iterable< E> value, {Encodable<E> ? using}) → void -
Encodes an iterable of
E
. -
encodeIterableOrNull<
E> (Iterable< E> ? value, {Encodable<E> ? using}) → void -
Encodes a nullable iterable of
E
. -
encodeIterated(
) → IteratedEncoder - Starts encoding an iterated collection or nested values.
-
encodeKeyed(
) → KeyedEncoder - Starts encoding a keyed collection or key-value pairs.
-
encodeMap<
K, V> (Map< K, V> value, {Encodable<K> ? keyUsing, Encodable<V> ? valueUsing}) → void -
Encodes a map of
K
andV
. -
encodeMapOrNull<
K, V> (Map< K, V> ? value, {Encodable<K> ? keyUsing, Encodable<V> ? valueUsing}) → void -
Encodes a nullable map of
K
andV
. -
encodeNull(
) → void - Encodes 'null'.
-
encodeNum(
num value) → void - Encodes a num value.
-
encodeNumOrNull(
num? value) → void - Encodes a nullable num value.
-
encodeObject<
T> (T value, {Encodable< T> ? using}) → void -
Encodes an object of type
T
. -
encodeObjectOrNull<
T> (T? value, {Encodable< T> ? using}) → void -
Encodes a nullable object of type
T
. -
encodeReference<
T> (T value, {Encodable< T> ? using}) → void -
Available on Encoder, provided by the ReferenceEncoder extension
Encodes a Reference ofT
using the provided Encodable. -
encodeReferenceOrNull<
T> (T? value, {Encodable< T> ? using}) → void -
Available on Encoder, provided by the ReferenceEncoder extension
Encodes a Reference ofT
or null using the provided Encodable. -
encodeStream<
T> (Stream< T> value, {Encodable<T> ? using}) → void -
Available on Encoder, provided by the AsyncEncoder extension
Encodes a Stream ofT
using the provided Encodable. -
encodeStreamOrNull<
T> (Stream< T> ? value, {Encodable<T> ? using}) → void -
Available on Encoder, provided by the AsyncEncoder extension
Encodes a Stream ofT
or null using the provided Encodable. -
encodeString(
String value) → void - Encodes a string value.
-
encodeStringOrNull(
String? value) → void - Encodes a nullable string value.
-
isHumanReadable(
) → bool - Whether a Encodable implementation should prefer to encode their human-readable form.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited