5

I am having problems switching the language in a flutter-web application. I added the required dependencies to the package.yml.

dependencies:
  flutter:
    sdk: flutter
  intl: ^0.16.1

  flutter_localizations:
      sdk: flutter

dev_dependencies:
  flutter_test:
    sdk: flutter
  intl_translation: ^0.17.9

Then I initialized the intl stuff in the MaterialApp.

 [...]
 child: MaterialApp(
        localizationsDelegates: [
          GlobalMaterialLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate,
          S.delegate,
        ],
        supportedLocales: S.delegate.supportedLocales,
        [...]

Here is the code I expect to change the locale.

                Text(S.of(context).language),
                RaisedButton(
                  child: Text("deutsch"),
                  onPressed: () {
                    S.load(Locale('de'));
                  },
                ),
                RaisedButton(
                  child: Text("englisch"),
                  onPressed: () {
                    S.load(Locale('en'));
                  },

Here are two arb files containing the translation.

{
    "language": "Deutsch"
}
{
    "language": "English"
}

Everything compiles and I can access the S.of(context) classes. I am sure I missed something. Since the switching of the language doesn't work either if I start in the Android Emulator.

Switching the system locale in the emulator changes the language.

I would appreciate any help or hints.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.