0

I'm currently using the EasyLocalization package in my Flutter app. This works great with the predefined translation files, but I want to request some data from a server again, if the locale has changed.

Is there a way to listen to locale changes in the app? I have tried to do so using WidgetsBindingObserver and PlatformDispatcher.instance.onLocaleChanged, but this does not seem to work with in app locale changes.

My code currently looks like this:

AppBar(
    title: Padding(
      padding: const EdgeInsets.symmetric(horizontal: 8.0),
      child:
      SpeedDial(
        backgroundColor: Colors.transparent,
        direction: SpeedDialDirection.down,
        switchLabelPosition: true,
        children: [
          SpeedDialChild(
            label: 'deutsch',
            labelStyle: getTextStyle(const Locale('de', 'DE')),
            onTap: () => context.setLocale(const Locale('de', 'DE')),
          ),
          // more languages here
          SpeedDialChild(
            label: 'español',
            labelStyle: getTextStyle(const Locale('es', 'ES')),
            onTap: () => context.setLocale(const Locale('es', 'ES')),
          ),
        ],
        child: Icon(
          Icons.language,
          size: SizeConfig.blockSizeHorizontal * 8,
        ),
      ),
    ),
  )

For state management, I use Provider

Sebb
  • 121
  • 2
  • 10
  • I believe you have a way to switch the language from your application. With this, when a new language is selected, you can make the request you want and update the app state. – Tayo.dev May 11 '23 at 09:04
  • Can you provide some code for this? I know how to change the apps language, but I want it to trigger the the request automatically. – Sebb May 11 '23 at 09:49
  • what state management are you using on the app? Can you update your post with the code showing Dropdown or any other widget you are using to switch the app language? – Tayo.dev May 11 '23 at 10:56
  • I have updated my original question :) – Sebb May 12 '23 at 19:24

0 Answers0