toDate function

DateTime? toDate(
  1. String str
)

Converts the string to a DateTime.

Returns null if the string cannot be parsed.

Example:

toDate('2024-01-15'); // DateTime(2024, 1, 15)
toDate('not-a-date'); // null

Implementation

DateTime? toDate(String str) => DateTime.tryParse(str.trim());