model_helpers library

Functions

checkedKey(Map<String, dynamic> json, String key) → dynamic
Reads a key that is required to be present in json but whose value may legitimately be null (OpenAPI 3.1 type: [T, "null"] combined with required). A plain json[key] as T? cast would otherwise accept a missing key as a null value, silently violating required. Throws FormatException when the key is absent.
listHash<T>(List<T>? list) int
A deep hash of a nullable list — consistent with listsEqual. Two lists that compare equal under listsEqual produce the same hash. Null hashes to 0.
listsEqual<T>(List<T>? a, List<T>? b) bool
Check if two nullable lists are deeply equal.
mapHash<K, V>(Map<K, V>? map) int
A deep hash of a nullable map — consistent with mapsEqual. Two maps that compare equal under mapsEqual produce the same hash. Null hashes to 0.
mapsEqual<K, V>(Map<K, V>? a, Map<K, V>? b) bool
Check if two nullable maps are deeply equal.
parseFromJson<T>(String className, Map<String, dynamic> json, T build()) → T
Runs build to construct a fromJson-parsed value of type T, converting any TypeError (e.g. an unexpected null or a cast failure on a required field) into a FormatException that names the class and includes the offending JSON. Generated fromJson factories delegate to this so callers that catch Exception treat malformed bodies as a parse error, not a crash.