Parsing
parse and tryParse read strings written in the same pattern syntax as format, including do ordinals and [literal] or 'literal' text, so formatting and parsing round-trip.
parse / tryParse
strict: truerejects out-of-range values such as February 30.utc: truereturns a UTCDateTime.tryParsereturnsnullinstead of throwing aFormatException.- Input is read in the formatter's locale: month and weekday names must be in that language. The sample input follows the locale selected in the dark bar.
LOADING…
⚙ TRY IT
⚡ OUTPUT
final formatter = FlutterDateFormatter('do MMMM yyyy', 'en');
formatter.parse('');
formatter.tryParse(''); // null instead of throwing
parseAny
Use parseAny when an input may use more than one known pattern. Patterns are
tried in order and the first successful parse is returned.
final value = FlutterDateFormatter.parseAny(
'2025-03-10',
patterns: ['yyyy-MM-dd', 'dd/MM/yyyy'],
locale: 'en',
strict: true,
);
If every pattern fails, parseAny throws the last FormatException. Passing
an empty pattern list throws an ArgumentError.
For validation UIs, use parseAnyDetailed to inspect every attempt without
throwing when no pattern matches:
final result = FlutterDateFormatter.parseAnyDetailed(
input,
patterns: ['yyyy-MM-dd', 'dd/MM/yyyy'],
);
if (result.matched) {
print(result.value);
} else {
for (final attempt in result.attempts) {
print('${attempt.pattern}: ${attempt.error?.message}');
}
}
Ordinals
For do, the parser tries each ordinal suffix of the locale and keeps the result whose day actually takes that suffix, so 2st March is rejected.