registerFluenticModel<T> function
void
registerFluenticModel<T>({
- required FromJsonFunction<
T> fromJson, - required T exampleInstance,
Public function for users to explicitly register their CUSTOM model types. Built-in types (int, String, List
Implementation
void registerFluenticModel<T>({
required FromJsonFunction<T> fromJson,
required T exampleInstance,
}) {
final Type type = T;
if (isPlainFluenticType(type)) {
// Added check
dev.log(
"WARNING: Attempting to register a plain Fluentic type: $type. "
"Plain types are handled belleza and do not require explicit registration. Skipping.",
);
return;
}
if (fluenticTypeAdapters.containsKey(type)) {
dev.log("INFO: FluenticModel for $type already registered. Skipping.");
return;
}
// Verify exampleInstance has toJson (by convention for custom types)
bool hasToJson = false;
try {
(exampleInstance as dynamic).toJson();
hasToJson = true;
} catch (_) {
// This is a strong warning or could even be an error preventing registration
dev.log(
"CRITICAL WARNING: Example instance for $type (type: ${exampleInstance.runtimeType}) "
"does not appear to have a toJson() method. "
"This method is crucial for generating JSON structure hints for the LLM. "
"Registration will proceed, but prompt generation might be suboptimal or fail for this type.",
);
}
if (!hasToJson && !isPlainFluenticType(exampleInstance.runtimeType)) {
// Double check if instance itself isn't plain
// Consider stricter action if toJson is missing for a custom type
}
dev.log("INFO: Registering FluenticModel for $type.");
fluenticTypeAdapters[type] = FluenticTypeAdapter<T>(
fromJson: fromJson,
exampleInstance: exampleInstance,
);
dev.log(
"INFO: FluenticModel for $type registered successfully. Total custom adapters: ${fluenticTypeAdapters.length}.",
);
}