core/utils/safe_json library
Defensive Map-value parsers for JSON read from a not-fully-trusted
source (an old save file, cloud data from a different app version, a
hand-edited local file). Never throw — always fall back on a type
mismatch or null instead of crashing the whole load over one bad field.
Functions
-
asBoolOr(
Object? v, bool fallback) → bool -
Reads
vas abool. -
asDoubleOr(
Object? v, double fallback) → double -
Reads
vas adouble, accepting a JSON integer for it too (see asIntOr for whydart:convertcan hand back either). -
asIntOr(
Object? v, int fallback) → int -
Reads
vas anint.dart:convertdecodes a whole-number JSON value asintbut a value with.0may come back asdouble(or vice versa depending on the source) — both are accepted here. -
asStringOr(
Object? v, String fallback) → String -
Reads
vas aString(empty string is a valid value, not a miss).