-
Notifications
You must be signed in to change notification settings - Fork 58
Description
All the DateFormat.x([locale]) constructors (DateFormat.d([locale]), DateFormat.yMMMMd([locale]), DateFormat.MMMd([locale])... ) return an error if locale is not a String? object. For exemple, trying to call them with a Locale object results in:
The following _TypeError was thrown building Builder:
type 'Locale' is not a subtype of type 'String?'
This is because these constructors are defined as:
DateFormat.x([locale]) : this('x', locale);
But in the default constructor, the optional locale parametter must be of type String?.
Before null-safety, this used to work fine because Dart was silently calling the Object.toString() method on the dynamic locale object to convert it to a String before passing it to the default constructor. But this is no longer the case. So the DateFormat.x([locale]) should either be transformed to DateFormat.x([String? locale]) or explicitly call the .toString() method on the locale dynamic object before passing it to the default constructor: DateFormat.x([locale]) : this('x', locale?.toString());