Message class
One message of a conversation: text, media, or a tool call or result.
Equality is structural: == and hashCode compare every field, and the
media by content, so two messages built from the same bytes in different
buffers are equal. imageBytes and images are compared as separate
fields. Both read every media byte on each call and cache nothing, so key
widgets by an id of your own or by ObjectKey(message), not by
ValueKey(message).
A message keeps what it is given: copyWith and the factories do not copy
the media bytes, and the constructor keeps the caller's images and
toolCalls lists. Do not change them while the message is a Set member
or a Map key.
- Available extensions
Constructors
-
Message({required String text, bool isUser = false, Uint8List? imageBytes, List<
Uint8List> images = const [], Uint8List? audioBytes, MessageType type = MessageType.text, String? toolName, List<FunctionCallResponse> toolCalls = const [], String? toolCallId}) -
const
- Message.audioOnly({required Uint8List audioBytes, bool isUser = false, String text = ''})
-
factory
- Message.imageOnly({required Uint8List imageBytes, bool isUser = false, String text = ''})
-
factory
-
Message.imagesOnly({required List<
Uint8List> imageBytes, bool isUser = false, String text = ''}) -
factory
- Message.systemInfo({required String text, String? icon})
-
factory
- Message.text({required String text, bool isUser = false})
-
factory
- Message.thinking({required String text})
-
factory
-
Message.toolCall({String? text, List<
FunctionCallResponse> calls = const []}) -
The model's tool call(s) in a history.
factory
-
Message.toolResponse({required String toolName, required Map<
String, dynamic> response, String? toolCallId}) -
A tool result.
toolCallIdnames the call it answers when that call had an id. Onlyflutter_edge_ai_llamareads it; the other engines pair the result with its call bytoolName, in order.factory - Message.withAudio({required String text, required Uint8List audioBytes, bool isUser = false})
-
factory
- Message.withImage({required String text, required Uint8List imageBytes, bool isUser = false})
-
factory
-
Message.withImages({required String text, required List<
Uint8List> imageBytes, bool isUser = false}) -
factory
Properties
- audioBytes → Uint8List?
-
final
- hasAudio → bool
-
no setter
- hashCode → int
-
Media is hashed by content, as
==compares it: the same bytes in different buffers, or in views at different offsets, hash alike (#823). See Message for the cost and for mutation.no setteroverride - hasImage → bool
-
no setter
- imageBytes → Uint8List?
-
final
-
images
→ List<
Uint8List> -
final
- isUser → bool
-
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- text → String
-
final
- toolCallId → String?
-
The FunctionCallResponse.id a MessageType.toolResponse answers, or
null when its call had none; ignored on any other type. Only
flutter_edge_ai_llamareads it; the other engines pair a result with its call by toolName, in order.final -
toolCalls
→ List<
FunctionCallResponse> -
The calls a MessageType.toolCall message carries, or empty when it was
built from text alone; ignored on any other type. An engine reads them
through
toolCallsOf(package:flutter_edge_ai/engine.dart), which also parses text for a message saved with text alone. One model turn may be several consecutive toolCall messages (genai writes one per call, and a streamed text call is recorded as it completes); an engine that replays calls merges such a run into one turn.final - toolName → String?
-
final
- type → MessageType
-
final
Methods
-
copyWith(
{String? text, bool? isUser, Uint8List? imageBytes, List< Uint8List> ? images, Uint8List? audioBytes, MessageType? type, String? toolName, List<FunctionCallResponse> ? toolCalls, String? toolCallId}) → Message -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
-
transformToChatPrompt(
{ModelType type = ModelType.general, ModelFileType fileType = ModelFileType.binary}) → String -
Available on Message, provided by the MessageExtension extension
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override