[FIX] Field Groups hydration
This commit is contained in:
@@ -145,15 +145,22 @@ class AstromicFormController {
|
|||||||
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.');
|
||||||
|
|
||||||
|
// Use a more robust ID to prevent any possibility of collision on fast clicks
|
||||||
final newUuid = '${DateTime.now().microsecondsSinceEpoch}_${_nodes.length}';
|
final newUuid = '${DateTime.now().microsecondsSinceEpoch}_${_nodes.length}';
|
||||||
|
|
||||||
def.schema.forEach((fieldName, config) {
|
def.schema.forEach((fieldName, config) {
|
||||||
final nodeKey = '${groupId}_${fieldName}_$newUuid';
|
final nodeKey = '${groupId}_${fieldName}_$newUuid';
|
||||||
final startVal = initialData?[fieldName] ?? config.initialValue;
|
|
||||||
|
// THE FIX: Explicitly check for null initialData before indexing
|
||||||
|
// This prevents the null-pointer crash on Web
|
||||||
|
final dynamic startVal = (initialData != null && initialData.containsKey(fieldName)) ? initialData[fieldName] : config.initialValue;
|
||||||
|
|
||||||
config.register(nodeKey, startVal, _createTypedNode);
|
config.register(nodeKey, startVal, _createTypedNode);
|
||||||
});
|
});
|
||||||
|
|
||||||
for (var sub in def.subGroups) {
|
// Handle subGroups safely
|
||||||
|
final subGroups = def.subGroups;
|
||||||
|
for (var sub in subGroups) {
|
||||||
final subKey = '${groupId}_${sub}_${newUuid}_manifest';
|
final subKey = '${groupId}_${sub}_${newUuid}_manifest';
|
||||||
_nodes[subKey] = AstromicFieldNode<List<String>>(
|
_nodes[subKey] = AstromicFieldNode<List<String>>(
|
||||||
[],
|
[],
|
||||||
|
|||||||
Reference in New Issue
Block a user