OpenFlutter / flutter_screenutil

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

Theme fails to update when themeMode is on system mode and app is rendered inside screenutil #479

Closed milindgoel15 closed 1 year ago

milindgoel15 commented 1 year ago

Basically, When the material app is rendered in screen util builder, when the user changes the theme in the system from light to dark or vice versa, the theme in the app doesn't update.

When we render the app without screen util, it works fine. Note that the system chrome system UI mode should be there in the main function

Steps to reproduce:

  1. Run this code: https://katb.in/xefitizubus
  2. Try to change the theme via system settings.
  3. theme in the app doesn't change

Affected versions: flutter: 3.10 screen util: 5.8.1

Last working versions: flutter: 3.7.12 screen util: 5.7.0

expected behaviour: Theme does changes

actual behaviour: theme doesn't change

Screen recording: https://github.com/OpenFlutter/flutter_screenutil/assets/45682747/ce01900a-26f6-4789-a543-d0b28d7692f9

lizhuoyuan commented 1 year ago

update 5.8.2 or add this:

      useInheritedMediaQuery: true,
 return ScreenUtilInit(
      useInheritedMediaQuery: true,
      builder: (context, child) => MaterialApp(
...

5.8.2 change useInheritedMediaQuery default value to true

milindgoel15 commented 1 year ago

Hi, I just checked the documentation about useInheritedMediaQuery which says it avoids the keyboard overlay on text fields. But I am not able to understand its relation to the issue I had. Can you explain?

lizhuoyuan commented 1 year ago

Don't worry, the new version will respond to theme changes normally even if useInheritedMediaQuery is false