Skip to content

[Bug] DateFormat.x([locale]) constructors return an error if the 'locale' dynamic parameter is not a 'String?' #14

@ramsestom

Description

@ramsestom

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());

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestpackage:intltype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions