Part class abstract base

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 a type field with a unique string identifier for the custom part. See defaultPartConverterRegistry for the default registry and existing part types.
  • Deserialization: Implement a JsonToPartConverter that can recreate the part from its JSON representation.
  • Pass extended defaultPartConverterRegistry to all methods fromJson that accept a converter registry.
Implementers
Annotations
  • @immutable

Constructors

Part()
Creates a new part.
const
Part.fromJson(Map<String, Object?> json, {required Map<String, JsonToPartConverter<Part>> converterRegistry})
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

Constants

typeKey → const String
The key of the part type in the JSON representation.