mirror of
https://github.com/we-promise/sure.git
synced 2026-07-12 12:55:20 +00:00
* feat(mobile): show account detail context * fix(mobile): show current account holdings * fix(mobile): tidy account detail review states
34 lines
881 B
Dart
34 lines
881 B
Dart
class JsonParsing {
|
|
static String? parseString(dynamic value) {
|
|
if (value == null) return null;
|
|
return value.toString();
|
|
}
|
|
|
|
static String parseRequiredString(dynamic value, String fieldName) {
|
|
final parsed = parseString(value);
|
|
if (parsed == null) {
|
|
throw FormatException('Missing $fieldName');
|
|
}
|
|
return parsed;
|
|
}
|
|
|
|
static int? parseInt(dynamic value) {
|
|
if (value == null) return null;
|
|
if (value is int) return value;
|
|
return int.tryParse(value.toString());
|
|
}
|
|
|
|
static DateTime? parseDateTime(dynamic value) {
|
|
if (value == null) return null;
|
|
return DateTime.tryParse(value.toString());
|
|
}
|
|
|
|
static DateTime parseRequiredDateTime(dynamic value, String fieldName) {
|
|
final parsed = parseDateTime(value);
|
|
if (parsed == null) {
|
|
throw FormatException('Invalid $fieldName date');
|
|
}
|
|
return parsed;
|
|
}
|
|
}
|