tryParse static method

Date? tryParse(
  1. String isoString
)

Parses an ISO 8601 date string, returning null if the string is invalid. If the input string includes timezone information, it will be converted to UTC. The resulting Date will always be in UTC.

⚠️ you should always generate the ISO string using toIso8601String because it includes the Z suffix to indicate UTC. If the string does not include the Z suffix, the date will be assumed to be in the local timezone, and will get converted to UTC.

Implementation

static Date? tryParse(String isoString) =>
    switch (DateTime.tryParse(isoString)) {
      final DateTime dateTime => Date(dateTime),
      _ => null
    };