-
Notifications
You must be signed in to change notification settings - Fork 501
Integration with device_preview to correctly update MediaQueryData #578
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
Comments
Thanks @paulocagol, although your code snippet helped me, I still have to do a hot-restart so the changes update (correctly on every preview-ed device). But it's still better than before. |
Thank you for this code snippet, it saved my life. |
what for the font size (sp) its not working with device preview ? |
Some widgets don’t update when the device model changes in DevicePreview. Use this to force a rebuild: void rebuildAllChildren(BuildContext context) {
void rebuild(Element el) {
el.markNeedsBuild();
el.visitChildren(rebuild);
}
(context as Element).visitChildren(rebuild);
} Apply it inside ScreenUtilInit: runApp(
DevicePreview(
enabled: App.device.isWeb || App.device.isIPad,
builder: (context) {
return ScreenUtilInit(
designSize: const Size(360, 690),
minTextAdapt: true,
splitScreenMode: true,
useInheritedMediaQuery: true,
builder: (context, child) {
ScreenUtil.configure(data: MediaQuery.of(context));
rebuildAllChildren(context); // Force rebuild
return const EzStore();
},
);
},
),
); |
Issue Description
When using
flutter_screenutil
withdevice_preview
, theMediaQueryData
may not be updated correctly, causing widgets to use the physical device's dimensions instead of the preview dimensions. This can be resolved by configuringScreenUtil
correctly.Solution
Ensure
ScreenUtil.configure
is used to update theMediaQueryData
within theScreenUtilInit
builder. Here's an example:Additional Information
This ensures the MediaQueryData from device_preview is used correctly by ScreenUtil.
References
I hope it helps
The text was updated successfully, but these errors were encountered: