diff --git a/lib/src/form/src/controller.dart b/lib/src/form/src/controller.dart index f7c296f..2c50cc1 100644 --- a/lib/src/form/src/controller.dart +++ b/lib/src/form/src/controller.dart @@ -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 key = GlobalKey(); @@ -20,10 +24,10 @@ class AstromicFormController { /// Accessor for the map of group definitions currently registered in the controller. Map get groupDefs => _groupDefs; - final StreamController> _errorStreamController = StreamController.broadcast(); + // final StreamController> _errorStreamController = StreamController.broadcast(); /// A stream that emits a list of error codes and messages for external handling. - Stream> get errorStream => _errorStreamController.stream; + final Stream>? 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; @@ -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? 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(); } } diff --git a/lib/src/form/src/widgets/string_form_field.dart b/lib/src/form/src/widgets/string_form_field.dart index 3c6565a..140b8d0 100644 --- a/lib/src/form/src/widgets/string_form_field.dart +++ b/lib/src/form/src/widgets/string_form_field.dart @@ -79,7 +79,9 @@ class _AstromicStringFormFieldState extends State { } } - widget.formController.errorStream.listen(_handleApiErrors); + if (widget.formController.errorStream != null) { + widget.formController.errorStream!.listen(_handleApiErrors); + } } @override diff --git a/pubspec.lock b/pubspec.lock index b52d955..59f4529 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -14,7 +14,7 @@ packages: description: path: "." ref: master - resolved-ref: "02dd66516d8da7fb5f927249529e72eb00785bf0" + resolved-ref: ad116fd32b1fb75b2facca66ab9ded0f13bf86b6 url: "https://git.micazi.dev/micazi/astromic_elements.git" source: git version: "0.1.3" @@ -230,10 +230,10 @@ packages: dependency: transitive description: name: meta - sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c + sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394" url: "https://pub.dev" source: hosted - version: "1.16.0" + version: "1.17.0" nested: dependency: transitive description: