jsonDecodeSafe static method
Safely decodes a JSON string, returning null on error.
Implementation
static dynamic jsonDecodeSafe(String? jsonString) {
jsonString = jsonString?.trim();
if (jsonString == null || jsonString.isEmpty || jsonString == 'null') return null;
if (!isJson(jsonString)) return null;
try {
return dc.jsonDecode(jsonString);
} on Object catch (e, stackTrace) {
// ignore: avoid_print_error - debugPrint is appropriate for utility packages (stripped in release builds, no external dependencies)
debugPrint('JsonUtils.jsonDecodeSafe failed: $e\n$stackTrace');
return null;
}
}