From 018f3555c392e7a89a50e769dd29a1623e179437 Mon Sep 17 00:00:00 2001 From: Michael Aziz Date: Sat, 24 Jan 2026 10:18:48 +0200 Subject: [PATCH] [FIX] Try Get --- lib/src/form/src/controller.dart | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/lib/src/form/src/controller.dart b/lib/src/form/src/controller.dart index 940f0c6..bb9fc7a 100644 --- a/lib/src/form/src/controller.dart +++ b/lib/src/form/src/controller.dart @@ -107,13 +107,33 @@ class AstromicFormController { } /// Safely attempts to retrieve a value, returning `null` if the node is missing or of a different type. + // T? tryGet(String id) { + // if (_nodes.containsKey(id)) { + // final n = _nodes[id]; + // if (n is AstromicFieldNode) { + // return n.value; + // } + // } + // return null; + // } + T? tryGet(String id) { - if (_nodes.containsKey(id)) { - final n = _nodes[id]; - if (n is AstromicFieldNode) { - return n.value; - } + final n = _nodes[id]; + if (n == null) return null; + + // Access the value via dynamic to bypass the strict Node type check + final dynamic value = n.value; + + // Check if the value is actually of type T (or null) + if (value is T) { + return value; } + + // Fallback for null-safety: if T is nullable and value is null + if (value == null && _isNullable()) { + return null; + } + return null; }