OpenFlutter / flutter_screenutil

Flutter screen adaptation, font adaptation, get screen information
https://pub.dartlang.org/packages/flutter_screenutil
Apache License 2.0
3.88k stars 494 forks source link

ScreenUtil doesnt adapt when running DevicePreview #404

Closed xalikoutis closed 2 years ago

xalikoutis commented 2 years ago

Hi i am using version 5.5.3+2 with DevicePreview to run some tests, but doesnt work. Everything is a mess with large text and widget sizes. It used to work very well in previous versions. What am i doing wrong?

return DevicePreview(
        enabled: generalConfig.isTest,
        builder: (BuildContext context) {
          return ScreenUtilInit(
              minTextAdapt: true,
              designSize: Size(AppConstants.screenWidth, AppConstants.screenHeight),
              builder: (BuildContext context, Widget? child) {
                return ThemeSwitcherWidget(
                  initialTheme: themeConfig.defaultTheme,
                  child: OverlaySupport.global(
                    child: KeyboardDismisser(
                      child: CubitsProvider(
                        child: MaterialApp.router(
                          localizationsDelegates: GlobalMaterialLocalizations.delegates,
                          supportedLocales: <Locale>[
                            Locale(generalConfig.languageCode),
                          ],
                          useInheritedMediaQuery: true,
                          locale: DevicePreview.locale(context),
                          builder: DevicePreview.appBuilder,
                          theme: themeConfig.defaultTheme,
                          debugShowCheckedModeBanner: false,
                          routeInformationParser: appRouter.defaultRouteParser(),
                          routerDelegate: appRouter.delegate(initialRoutes: [LandingPageRoute()]),
                        ),
                      ),
                    ),
                  ),
                );
              });
        });

image

xalikoutis commented 2 years ago

Ver 5.0.4 using ScreenUtil.setContext(context) inside builder works

github-actions[bot] commented 2 years ago

This issue is stale because it has been open for 30 days with no activity.

Mounir-Bouaiche commented 2 years ago

Ver 5.0.4 using ScreenUtil.setContext(context) inside builder works

Hello, try adding useInheritedMediaQuery: true in ScreenUtilInit params.

github-actions[bot] commented 2 years ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 2 years ago

This issue was closed because it has been inactive for 14 days since being marked as stale.