tryParse static method

DateTime? tryParse(
  1. String string,
  2. DateFormat format
)

Returns null if format.parse() throws.

Implementation

static DateTime? tryParse(String string, DateFormat format) {
  if (string.isNotEmpty) {
    try {
      return format.parse(string);
    } catch (e) {
      // print('Error parsing date: $e');
    }
  }
  return null;
}