toDate method

DateTime? toDate(
  1. String format, {
  2. DateTime? defaultDate,
})

Covente string para DateTime

format Indica o formato que a data está

Implementation

DateTime? toDate(String format, {DateTime? defaultDate}) {
  if (this == null) return defaultDate ?? null;
  try {
    return DateFormat(format).parse(this!);
  } catch (e) {
    print(e);
    return defaultDate ?? null;
  }
}