tryString2Model<T> function

T tryString2Model<T>(
  1. String data,
  2. T parse(
    1. Map<String, dynamic> json
    ),
  3. T orElse()
)

Implementation

T tryString2Model<T>(String data, T Function(Map<String, dynamic> json) parse, T Function() orElse) {
  try {
    return parse(jsonDecode(data));
  } catch (_) {
    return orElse.call();
  }
}