Skip to content

When validatorof TextFormField widget returns an AppLozalizations.of(context).translationKey value, error message does not refresh with locale change #143729

@fulstadev

Description

@fulstadev

Steps to reproduce

  1. Create a Form in your Flutter App using a TextFormField().
  2. Localize your Flutter app according to the docs.
  3. Build simple form validation according to the docs, by returning a localized string via the validator (e.g. AppLocalizations.of(context).myTranslation).
  4. Test the app using flutter run, and provide invalid input and trigger validation.
  5. This will show an according error message displayed in the current app locale.
  6. Trigger a locale language switch in your app (we're currently doing this using a provider to whose value the locale property of the MaterialApp / CupertinoApp listens to).

Expected results

The locale should be switched in the entire app, to the language to which the locale switch occurred.

Actual results

Every string present in the app via AppLocalizations.of(context)... changes, except for the strings returned via the validator property in the TextFormField() widget & displayed in the way mentioned above before the language switch. Only a new call to formKey.currentState.validate() will refresh the validation error messages according to the newly selected language.

This issue has also been mentioned on so, still without a really viable solution.

Code sample

Code sample
you may consider https://stackoverflow.com/questions/52217090/internationalization-problem-when-i-switch-languages as an example.

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.16.4, on macOS 14.2.1 23C71 darwin-arm64, locale de-CH)
    • Flutter version 3.16.4 on channel stable at /Users/inkognito/dev/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2e9cb0aa71 (2 months ago), 2023-12-11 14:35:13 -0700
    • Engine revision 54a7145303
    • Dart version 3.2.3
    • DevTools version 2.28.4

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/inkognito/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15A507
    • CocoaPods version 1.14.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)

[✓] IntelliJ IDEA Ultimate Edition (version 2023.3.3)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin version 77.3.1
    • Dart plugin version 233.13763.5

[✓] Connected device (3 available)
    • iPhone 15 Pro Max (mobile) • 1EF3E08B-D6C6-4D80-89B7-A97F5CDA6C61 • ios            •
      com.apple.CoreSimulator.SimRuntime.iOS-17-0 (simulator)
    • macOS (desktop)            • macos                                • darwin-arm64   • macOS 14.2.1 23C71
      darwin-arm64
    • Chrome (web)               • chrome                               • web-javascript • Google Chrome
      119.0.6045.159

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projecta: internationalizationSupporting other languages or locales. (aka i18n)found in release: 3.19Found to occur in 3.19found in release: 3.21Found to occur in 3.21frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-text-inputOwned by Text Input teamtriaged-text-inputTriaged by Text Input team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions