Base class for message content parts.
To create a custom part implementation, extend this class and ensure the following requirements are met for a robust implementation:
- Equality and Hashing: Override operator == and hashCode to ensure value-based equality.
- Serialization: Implement a
toJson()method that returns a JSON-encodable Map. The map must contain atypefield with a unique string identifier for the custom part. See defaultPartConverterRegistry for the default registry and existing part types. - Deserialization: Implement a
JsonToPartConverterthat can recreate the part from its JSON representation. - Pass extended defaultPartConverterRegistry to all methods
fromJsonthat accept a converter registry.
- Implementers
- Annotations
-
- @immutable
Constructors
- Part()
-
Creates a new part.
const
-
Part.fromJson(Map<
String, Object?> json, {required Map<String, JsonToPartConverter< converterRegistry})Part> > -
Deserializes a part from a JSON map.
factory
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
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toJson(
) → Map< String, Object?> - Serializes the part to a JSON map.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited