Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Australian MaterialLocalizations has incorrect mm/dd/yyyy dateHelpText #70341

@MichaelMarner

Description

@MichaelMarner

Flutters en_AU localizations give the wrong dateHelpText. Specifically, they inherit from MaterialLocalizationEn - which uses US style mm/dd/yyyy. That's not how things are done in Australia.

While the help text is incorrect, the underlying DateFormat locale uses the correct d/m/yyyy formatting. This confuses the user, because when they enter a date as specified by the help desk, the parsed DateTime result is incorrect.

Steps to Reproduce

  1. Run flutter create bug.
  2. Follow the Internationalization guide to configure localizations
  3. Add flutter_localizations to pubspec
  4. Set the app's supported locale to en_AU
  5. Render the helpText.

Minimal Example

pubspec.yaml

name: dateformat
description: A new Flutter project.
publish_to: "none"
version: 1.0.0+1
environment:
  sdk: ">=2.7.0 <3.0.0"
dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter
dev_dependencies:
  flutter_test:
    sdk: flutter
flutter:
  uses-material-design: true

main.dart

import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Date Format Test',
      localizationsDelegates: [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      supportedLocales: [
        const Locale('en', 'AU'),
        // ... other locales the app supports
      ],
      home: Scaffold(
        appBar: AppBar(title: Text('Date Format Test')),
        body: Builder(builder: (context) {
          final locale = Localizations.localeOf(context);
          final localizations = MaterialLocalizations.of(context);
          final date = DateTime(2020, 11, 12);
          return ListView(
            children: [
              Text('Current Locale: ${locale.toString()}'),
              Text('dateHelpText: ${localizations.dateHelpText}'),
              Text('Compact Date: ${localizations.formatCompactDate(date)}'),
              Text('Short Date: ${localizations.formatShortDate(date)}'),
              Text('Medium Date: ${localizations.formatMediumDate(date)}'),
              Text('Full Date: ${localizations.formatFullDate(date)}'),
            ],
          );
        }),
      ),
    );
  }
}

Expected results:

Help text should be dd/mm/yyyy

Actual results:

Help text shows as mm/dd/yyyy

Logs

no errors when flutter run --verbose

Analyzing dateformat...
No issues found! (ran in 4.2s)

[✓] Flutter (Channel beta, 1.23.0-18.1.pre, on Mac OS X 10.15.7 19H2 x86_64, locale en-AU)
    • Flutter version 1.23.0-18.1.pre at /Users/michael/.bin/flutter
    • Framework revision 198df796aa (4 weeks ago), 2020-10-15 12:04:33 -0700
    • Engine revision 1d12d82d9c
    • Dart version 2.11.0 (build 2.11.0-213.1.beta)


[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at /Users/michael/Library/Android/sdk
    • Platform android-29, build-tools 29.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 12.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.0, Build version 12A7209
    • CocoaPods version 1.9.3

[✓] Android Studio (version 3.6)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 45.1.1
    • Dart plugin version 192.7761
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)

[✓] VS Code (version 1.51.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.16.0

[✓] Connected device (1 available)
    • iPhone 11 (mobile) • F3EA93B5-C2C5-4293-BF6C-B8E48251D7E0 • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-0 (simulator)

Metadata

Metadata

Assignees

Labels

a: internationalizationSupporting other languages or locales. (aka i18n)f: material designflutter/packages/flutter/material repository.found in release: 3.3Found to occur in 3.3found in release: 3.7Found to occur in 3.7frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer version

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions