ofOrNull static method
Assumes unknown
is a TFieldRecord or FieldModel and
tries to construct a FieldModel, otherwise returns null
.
Implementation
static FieldModel? ofOrNull(dynamic unknown) {
try {
final fieldPath = fieldPathOrNull(unknown)!;
final fieldType = fieldTypeOrNull(unknown) ?? 'dynamic';
final nullable = nullableOrNull(unknown);
final children = childrenOrNull(unknown); // New method for children
final primaryKey = primaryKeyOrNull(unknown); // New method for primaryKey
final foreignKey = foreignKeyOrNull(unknown); // New method for foreignKey
final fallback = fallbackOrNull(unknown); // New method for fallback
final description = descriptionOrNull(unknown);
return FieldModel(
fieldPath: fieldPath,
fieldType: fieldType,
nullable: nullable,
children: children,
primaryKey: primaryKey,
foreignKey: foreignKey,
fallback: fallback,
description: description,
);
} catch (_) {
return null; // Return null if any property retrieval fails
}
}