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