Skip to main content

Factories and Constructors

This page uses factory_test.dart and the domain entity factory in assistant_message.dart.

Hide the public constructor

(generateJson: true, hidePublicConstructor: true)
abstract class $TestWithFactory {
String get id;

static TestWithFactory create({required String id}) =>
TestWithFactory._(id: id);
}

This keeps instantiation controlled while still letting generated code construct instances.

Static factory helpers

(generateJson: true)
abstract class $AssistantMessage implements $$ChatMessage {

ChatMessageRole get role => ChatMessageRole.assistant;

static AssistantMessage create({
required String text,
DateTime? createdAt,
List<Attachment>? attachments,
}) => AssistantMessage(
text: text,
attachments: attachments ?? [],
role: ChatMessageRole.assistant,
createdAt: createdAt ?? DateTime.now(),
);
}