flutter_device_preview icon indicating copy to clipboard operation
flutter_device_preview copied to clipboard

DevicePreview.locale isn't working with GetMaterialApp

Open divan opened this issue 2 years ago • 5 comments

Hey, it seems like locale setting doesn't work with GetMaterialApp from GetX. It supposed to be a wrapper around MaterialApp so should work transparently, but it messes up with some internals so switching locale in DevicePreview doesn't work.

  runApp(
    DevicePreview(
      enabled: !kReleaseMode,
      builder: (context) => const App(), // Wrap your app
      availableLocales: const [
        Locale('en'),
        Locale('uk'),
      ],
    ),
  );

class App extends StatelessWidget {
  const App({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      title: 'My App',
      localizationsDelegates: const [
        AppLocalizations.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
      ],
      supportedLocales: const [
        Locale('en'),
        Locale('uk'),
      ],
      debugShowCheckedModeBanner: false,
      useInheritedMediaQuery: true,
      locale: DevicePreview.locale(context), // not working
      builder: DevicePreview.appBuilder,
      home: MainApp(),
    );
  }
}

Any ideas how to solve this issue?

PS. There is a issue in GetX for that, but not sure it has got any attention.

divan avatar Feb 16 '23 22:02 divan

any updates ?

Obada2020 avatar Mar 10 '23 09:03 Obada2020

same issue

FakharAlyas119 avatar Mar 13 '23 18:03 FakharAlyas119

same issue , any updates ?

MostafaElswefy avatar Mar 29 '23 00:03 MostafaElswefy

i faced this problem and solved , there was confliction between packages maybe device preview not latest version and there was conflict with intl in my case , just i solved by downgrading for intl.

AbdalazizAbdallah avatar Apr 01 '23 10:04 AbdalazizAbdallah

I use the device_preview: ^1.1.0 it works for me. let's try it

vignesh235 avatar Apr 15 '23 11:04 vignesh235