[FIX] Try Get

This commit is contained in:
2026-01-24 10:18:48 +02:00
parent f43a0e039c
commit 018f3555c3

View File

@@ -107,13 +107,33 @@ class AstromicFormController {
} }
/// Safely attempts to retrieve a value, returning `null` if the node is missing or of a different type. /// Safely attempts to retrieve a value, returning `null` if the node is missing or of a different type.
// T? tryGet<T>(String id) {
// if (_nodes.containsKey(id)) {
// final n = _nodes[id];
// if (n is AstromicFieldNode<T>) {
// return n.value;
// }
// }
// return null;
// }
T? tryGet<T>(String id) { T? tryGet<T>(String id) {
if (_nodes.containsKey(id)) { final n = _nodes[id];
final n = _nodes[id]; if (n == null) return null;
if (n is AstromicFieldNode<T>) {
return n.value; // 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<T>()) {
return null;
}
return null; return null;
} }