dateFromJson static method

DateTime? dateFromJson(
  1. Map<String, dynamic> json,
  2. String attribute, {
  3. DateTime? defaultValue,
})

Implementation

static DateTime? dateFromJson(Map<String, dynamic> json, String attribute,
    {DateTime? defaultValue}) {
  try {
    return json[attribute] != null
        ? DateTime.parse(json[attribute]).toLocal()
        : defaultValue;
  } catch (e) {
    throw Exception('Error while parsing $attribute[$e]');
  }
}