[FIX] Error Stream in constructor.
This commit is contained in:
@@ -7,6 +7,10 @@ import './models/models.exports.dart';
|
||||
/// Manages a registry of reactive [AstromicFieldNode]s, handles dynamic group creation via UUIDs,
|
||||
/// and provides a robust validation mechanism covering both visible and hidden fields.
|
||||
class AstromicFormController {
|
||||
AstromicFormController({
|
||||
this.errorStream,
|
||||
});
|
||||
|
||||
/// The global key attached to the [Form] widget for integrated Flutter validation.
|
||||
final GlobalKey<FormState> key = GlobalKey<FormState>();
|
||||
|
||||
@@ -20,10 +24,10 @@ class AstromicFormController {
|
||||
/// Accessor for the map of group definitions currently registered in the controller.
|
||||
Map<String, AstromicFormGroupDefinition> get groupDefs => _groupDefs;
|
||||
|
||||
final StreamController<List<(String code, String? message)>> _errorStreamController = StreamController.broadcast();
|
||||
// final StreamController<List<(String code, String? message)>> _errorStreamController = StreamController.broadcast();
|
||||
|
||||
/// A stream that emits a list of error codes and messages for external handling.
|
||||
Stream<List<(String code, String? message)>> get errorStream => _errorStreamController.stream;
|
||||
final Stream<List<(String code, String? message)>>? errorStream;
|
||||
|
||||
/// Registers a [AstromicFormGroupDefinition] to the controller to enable dynamic instance handling.
|
||||
void registerGroup(AstromicFormGroupDefinition def) {
|
||||
@@ -67,7 +71,7 @@ class AstromicFormController {
|
||||
return newNode;
|
||||
}
|
||||
|
||||
throw Exception("Node $id not found and cannot be lazy-inited for type $T. Provide an initialValue.");
|
||||
throw Exception('Node $id not found and cannot be lazy-inited for type $T. Provide an initialValue.');
|
||||
}
|
||||
|
||||
Type _typeOf<T>() => T;
|
||||
@@ -130,7 +134,7 @@ class AstromicFormController {
|
||||
/// Adds a new instance to a dynamic group, generating a UUID and initializing all schema fields.
|
||||
String addGroupInstance(String groupId, {String? parentUuid, Map<String, dynamic>? initialData}) {
|
||||
final def = _groupDefs[groupId];
|
||||
if (def == null) throw Exception("Group $groupId not registered.");
|
||||
if (def == null) throw Exception('Group $groupId not registered.');
|
||||
|
||||
final newUuid = DateTime.now().microsecondsSinceEpoch.toString();
|
||||
|
||||
@@ -228,6 +232,5 @@ class AstromicFormController {
|
||||
if (n is AstromicFieldNode) n.disposeUI();
|
||||
n.dispose();
|
||||
}
|
||||
_errorStreamController.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +79,9 @@ class _AstromicStringFormFieldState extends State<AstromicStringFormField> {
|
||||
}
|
||||
}
|
||||
|
||||
widget.formController.errorStream.listen(_handleApiErrors);
|
||||
if (widget.formController.errorStream != null) {
|
||||
widget.formController.errorStream!.listen(_handleApiErrors);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user