Flutter global material localizations and initialize date formatting not working together
I solved the problem by adding in pubspec.yaml the following dependency:
dependencies:
...
flutter_localizations:
sdk: flutter
...
be careful with the indentation.
I too had this issue and, after playing around a little, found that when using Material localisations it appears default to US if you do not specify the supported locales.
Adding the following supported locales allowed the UK date format to be shown rather than the US one.
localizationsDelegates: [
const DemoLocalizationsDelegate(),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: [
const Locale('en', 'US'), // English US
const Locale('en', 'GB'), // English UK
// ... other locales the app supports
],
I didn't have to explicitly initialise the DateFormat class as Material appears to handle this too.