[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
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user