Open phamconganh opened 3 months ago
e.g. I have a nullable list ['text', null] and write a safe conversion
@JsonKey(fromJson: safeList<String>) List<String> property;
List<T> safeList<T extends Object>(dynamic value, {List<T> defaultValue = const []}) => safeNullableList<T>(value) ?? defaultValue; List<T>? safeNullableList<T extends Object>(dynamic value) { if (value is List<T>) return value; if (value is List<Object?>) return value.whereType<T>().toList(); return null; }
e.g. I have a nullable list ['text', null] and write a safe conversion