[FIX] Try Get
This commit is contained in:
@@ -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 is AstromicFieldNode<T>) {
|
if (n == null) return null;
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user