[FIX] Error Stream in constructor.

This commit is contained in:
2026-01-23 22:51:00 +02:00
parent 5ccc04736a
commit f50d1d6576
3 changed files with 14 additions and 9 deletions

View File

@@ -7,6 +7,10 @@ import './models/models.exports.dart';
/// Manages a registry of reactive [AstromicFieldNode]s, handles dynamic group creation via UUIDs, /// 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. /// and provides a robust validation mechanism covering both visible and hidden fields.
class AstromicFormController { class AstromicFormController {
AstromicFormController({
this.errorStream,
});
/// The global key attached to the [Form] widget for integrated Flutter validation. /// The global key attached to the [Form] widget for integrated Flutter validation.
final GlobalKey<FormState> key = GlobalKey<FormState>(); final GlobalKey<FormState> key = GlobalKey<FormState>();
@@ -20,10 +24,10 @@ class AstromicFormController {
/// Accessor for the map of group definitions currently registered in the controller. /// Accessor for the map of group definitions currently registered in the controller.
Map<String, AstromicFormGroupDefinition> get groupDefs => _groupDefs; 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. /// 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. /// Registers a [AstromicFormGroupDefinition] to the controller to enable dynamic instance handling.
void registerGroup(AstromicFormGroupDefinition def) { void registerGroup(AstromicFormGroupDefinition def) {
@@ -67,7 +71,7 @@ class AstromicFormController {
return newNode; 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; 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. /// 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}) { String addGroupInstance(String groupId, {String? parentUuid, Map<String, dynamic>? initialData}) {
final def = _groupDefs[groupId]; 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(); final newUuid = DateTime.now().microsecondsSinceEpoch.toString();
@@ -228,6 +232,5 @@ class AstromicFormController {
if (n is AstromicFieldNode) n.disposeUI(); if (n is AstromicFieldNode) n.disposeUI();
n.dispose(); n.dispose();
} }
_errorStreamController.close();
} }
} }

View File

@@ -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 @override

View File

@@ -14,7 +14,7 @@ packages:
description: description:
path: "." path: "."
ref: master ref: master
resolved-ref: "02dd66516d8da7fb5f927249529e72eb00785bf0" resolved-ref: ad116fd32b1fb75b2facca66ab9ded0f13bf86b6
url: "https://git.micazi.dev/micazi/astromic_elements.git" url: "https://git.micazi.dev/micazi/astromic_elements.git"
source: git source: git
version: "0.1.3" version: "0.1.3"
@@ -230,10 +230,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: meta name: meta
sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.16.0" version: "1.17.0"
nested: nested:
dependency: transitive dependency: transitive
description: description: