Skip to content

locale resets after closing and opening the app #143

Description

@baimamboukar

Describe the bug

My active locale resets when I close and reopen the app.

  • I'm persisting my rawLocale 'fr', 'en', and 'de' using hydrated_bloc
  • The raw locale is being persisted pretty fine
  • But when I close and reopen the app, the active locale resets itself and goes to fallback locale, which is 'en', Meanwhile my persisted raw locale is pretty fine

This is my app.dart

BlocBuilder<ThemeCubit, bool>(
        builder: (BuildContext context, bool isDarkMode) {
          return BlocBuilder<LanguageCubit, String>(
            builder: (context, lang) {
              return MaterialApp.router(
                theme: theme.toThemeData(Brightness.light),
                //theme: FlexThemeData.light(scheme: FlexScheme.hippieBlue),
                darkTheme: theme.toThemeData(Brightness.dark),
                themeMode: isDarkMode ? ThemeMode.dark : ThemeMode.light,
                localizationsDelegates: AppLocalizations.localizationsDelegates,
                supportedLocales: AppLocaleUtils.supportedLocales,
                locale: Locale(lang), // was TranslationProvider.of(context).flutterLocale
                routerConfig: _router.config(
                  navigatorObservers: () => <NavigatorObserver>[
                    FirebaseAnalyticsObserver(
                      analytics: FirebaseAnalytics.instance,
                    ),
                    EliteRouterObserver(),
                  ],
                ),
                debugShowCheckedModeBanner: false,
              );
            },
          );
        },
      ),

This is how I wrapped my MaterialApp widget with TranslationProvider

await runZonedGuarded(
    () async => runApp(
      TranslationProvider(
        child: await builder(),
      ),
    ),
    (error, stackTrace) => log(error.toString(), stackTrace: stackTrace),
  );

To Reproduce
Steps to reproduce the behavior:

  1. Wrap material with TranslationProvider
  2. use TranslationProvider.of(context)flutterLocale as MaterialApp locale's attribute
  3. Persist your locale
  4. Trigger interaction that changes active locale
  5. The locale is changed

Expected behavior
The locale changes and updates screen, but when you close and reopen app, the locale is reset and goes to fallback locale

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinginvalidThis doesn't seem right

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions