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.
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:
Any lines of code in the app that reference context.locale become non-functional. e.g.:
My main.dart
My app.dart
My flutter doctor summary
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.