Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DevicePreview locale not working well with easy_localization #257

Open
Dan1ell opened this issue Feb 14, 2025 · 0 comments
Open

DevicePreview locale not working well with easy_localization #257

Dan1ell opened this issue Feb 14, 2025 · 0 comments

Comments

@Dan1ell
Copy link

Dan1ell commented Feb 14, 2025

I'm using EasyLocalization (and GoRouter, in case it is relevant).

EasyLocalization requires: locale: context.locale,
DevicePreview requires: locale: DevicePreview.locale(context),

When setting the line to what DevicePreview needs, locale switching becomes unreliable. In particular:

  • from my app ui: doesn't work at all
  • from device preview console: only direction switching works, so if going from english to arabic, the text will go RTL, but nothing else will change.

Any lines of code in the app that reference context.locale become non-functional. e.g.:

 value: context.locale,
   onChanged: (value) {
      context.setLocale(value!);
   },

final languageCode = context.locale.languageCode;

etc.

My main.dart

  runApp(
    DevicePreview(
      enabled: !kReleaseMode,
      tools: const [
        ...DevicePreview.defaultTools,        
      ],
      builder: (context) => EasyLocalization(
          supportedLocales: locales,
          path: 'assets/translations',
          fallbackLocale: const Locale('en'),
          child: MultiProvider(
            providers: [
              ChangeNotifierProvider(create: (context) => ThemeChangeNotifier()),
            ],
            child: App(),
          )),
    ),
  );

My app.dart

  return MaterialApp.router(
      routerDelegate: router.routerDelegate,
      routeInformationParser: router.routeInformationParser,
      routeInformationProvider: router.routeInformationProvider,
      debugShowCheckedModeBanner: false,
      restorationScopeId: 'app',
      localizationsDelegates: context.localizationDelegates,
      supportedLocales: context.supportedLocales,
      locale: context.locale, // works in my app, but not in device preview
      locale: DevicePreview.locale(context), // does not work in my app, works poorly in device preview
      theme: lightThemeData,
      darkTheme: darkThemeData,
      themeMode: context.watch<ThemeChangeNotifier>().themeMode,
      builder: DevicePreview.appBuilder,
    );

My flutter doctor summary

[✓] Flutter (Channel stable, 3.27.4, on macOS 15.2 24C101 darwin-arm64,
    locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version
    34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.2)
[✓] VS Code (version 1.97.2)
[✓] Connected device (3 available)
[✓] Network resources

What I would like is to set 'locale: DevicePreview.locale(context)' once, and have locale switching continue to work normally from both my app ui and from the device preview console.

@Dan1ell Dan1ell changed the title DevicePreview locale not working with easy localization DevicePreview locale not working well with easy localization Feb 14, 2025
@Dan1ell Dan1ell changed the title DevicePreview locale not working well with easy localization DevicePreview locale not working well with easy_localization Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant