[FIX] Field Groups hydration
This commit is contained in:
@@ -148,32 +148,32 @@ 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}';
|
||||||
|
|
||||||
|
// 1. Fields loop (Keep as is)
|
||||||
def.schema.forEach((fieldName, config) {
|
def.schema.forEach((fieldName, config) {
|
||||||
final nodeKey = '${groupId}_${fieldName}_$newUuid';
|
final nodeKey = '${groupId}_${fieldName}_$newUuid';
|
||||||
|
|
||||||
// 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;
|
final dynamic startVal = (initialData != null && initialData.containsKey(fieldName)) ? initialData[fieldName] : config.initialValue;
|
||||||
|
|
||||||
config.register(nodeKey, startVal, _createTypedNode);
|
config.register(nodeKey, startVal, _createTypedNode);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handle subGroups safely
|
// 2. THE FIX: Defensive check for null subGroups
|
||||||
final subGroups = def.subGroups;
|
final subGroupsList = def.subGroups;
|
||||||
for (var sub in subGroups) {
|
if (subGroupsList != null) {
|
||||||
|
for (var sub in subGroupsList) {
|
||||||
final subKey = '${groupId}_${sub}_${newUuid}_manifest';
|
final subKey = '${groupId}_${sub}_${newUuid}_manifest';
|
||||||
_nodes[subKey] = AstromicFieldNode<List<String>>(
|
_nodes[subKey] = AstromicFieldNode<List<String>>(
|
||||||
[],
|
<String>[],
|
||||||
formatter: (v) => v.length.toString(),
|
formatter: (v) => v.length.toString(),
|
||||||
parser: (v) => [],
|
parser: (v) => <String>[],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Update the Parent Manifest
|
||||||
final manifest = getManifest(groupId, parentUuid);
|
final manifest = getManifest(groupId, parentUuid);
|
||||||
manifest.value = [...manifest.value, newUuid];
|
manifest.value = [...manifest.value, newUuid];
|
||||||
|
|
||||||
return newUuid;
|
return newUuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user