From 1263bc6ff329030b4c8cb2a60076065538b769e2 Mon Sep 17 00:00:00 2001 From: Michael Aziz Date: Sat, 24 Jan 2026 18:04:56 +0200 Subject: [PATCH] [FIX] Field Groups hydration --- lib/src/form/src/controller.dart | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/src/form/src/controller.dart b/lib/src/form/src/controller.dart index f2cbe66..241dd47 100644 --- a/lib/src/form/src/controller.dart +++ b/lib/src/form/src/controller.dart @@ -145,15 +145,22 @@ 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}'; def.schema.forEach((fieldName, config) { 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); }); - for (var sub in def.subGroups) { + // Handle subGroups safely + final subGroups = def.subGroups; + for (var sub in subGroups) { final subKey = '${groupId}_${sub}_${newUuid}_manifest'; _nodes[subKey] = AstromicFieldNode>( [],