flutter easy localization language does not change at runtime

184 Views Asked by At

I use provider and easy localization.

I run my app like this:

runApp(
    MultiProvider(
      providers: [...ApplicationProvider.instance.dependItems],
      child: EasyLocalization(
        supportedLocales: LanguageManager.instance.supportedLocales,
        path: ApplicationConstants.LANG_ASSET_PATH,
        child: const MyApp(),
      ),
    ),
  )

dependItems like this:

List<SingleChildWidget> dependItems = [
    ChangeNotifierProvider(
      create: (context) => ThemeNotifier(),
    ),
    Provider.value(value: NavigationService.instance)
  ];

supportedLocales like this:

  final enLocale = const Locale('en', 'US');
  final trLocale = const Locale('tr', 'TR');

  List<Locale> get supportedLocales => [enLocale, trLocale];

I use like this:

Text(
        LocaleKeys.appName.locale,
        style: const TextStyle(
          color: Colors.black,
        ),

I change language like this:

  onPressed: () {
          context.locale.languageCode == 'tr'
              ? EasyLocalization.of(context)
                  ?.setLocale(LanguageManager.instance.enLocale)
              : EasyLocalization.of(context)
                  ?.setLocale(LanguageManager.instance.trLocale);
        },
      )

when ı press the button language change but interface not update. When I run the application again, the interface is updated as the language I updated. I want the interface to be updated as soon as I press the button

0

There are 0 best solutions below