ReflectiveCodec<T> class
Codec for simple objects using field definitions.
Instead of code generation, you provide a constructor function and a map of field accessors. This allows manual but type-safe serialization without the build_runner overhead.
Usage:
final codec = ReflectiveCodec<User>(
(map) => User(name: map['name'] as String, age: map['age'] as int),
{
'name': FieldAccessor<User>((u) => u.name),
'age': FieldAccessor<User>((u) => u.age),
},
);
Constructors
-
ReflectiveCodec(T constructor(Map<
String, dynamic> ), Map<String, FieldAccessor< fields)T> > -
Create a ReflectiveCodec with a
constructorandfields.
Properties
-
constructor
→ T Function(Map<
String, dynamic> ) -
Constructor function that creates a
Tfrom a map.final -
fields
→ Map<
String, FieldAccessor< T> > -
Map of field names to their accessors.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
fromMap(
Map< String, dynamic> map) → T -
Deserialize an object from a map representation.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toMap(
T value) → Map< String, dynamic> -
Serialize an object to a map representation.
override
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited