Mounir Bouaiche

Depend on View instead of MediaQuery

... ... @@ -141,8 +141,9 @@ class ScreenUtil {
bool minTextAdapt = false,
FontSizeResolver? fontSizeResolver,
}) {
final view = View.maybeOf(context);
return configure(
data: MediaQuery.maybeOf(context),
data: view != null ? MediaQueryData.fromView(view) : null,
designSize: designSize,
splitScreenMode: splitScreenMode,
minTextAdapt: minTextAdapt,
... ... @@ -158,8 +159,8 @@ class ScreenUtil {
FontSizeResolver? fontSizeResolver,
}) {
return ScreenUtil.ensureScreenSize().then((_) {
return configure(
data: MediaQuery.maybeOf(context),
return init(
context,
designSize: designSize,
minTextAdapt: minTextAdapt,
splitScreenMode: splitScreenMode,
... ... @@ -251,8 +252,11 @@ class ScreenUtil {
if (kIsWeb) {
deviceType = DeviceType.web;
} else {
bool isMobile = defaultTargetPlatform == TargetPlatform.iOS || defaultTargetPlatform == TargetPlatform.android;
bool isTablet = (orientation == Orientation.portrait && screenWidth >= 600) || (orientation == Orientation.landscape && screenHeight >= 600);
bool isMobile = defaultTargetPlatform == TargetPlatform.iOS ||
defaultTargetPlatform == TargetPlatform.android;
bool isTablet =
(orientation == Orientation.portrait && screenWidth >= 600) ||
(orientation == Orientation.landscape && screenHeight >= 600);
if (isMobile) {
deviceType = isTablet ? DeviceType.tablet : DeviceType.mobile;
... ...
... ... @@ -126,10 +126,9 @@ class _ScreenUtilInitState extends State<ScreenUtilInit>
}
MediaQueryData? _newData() {
MediaQueryData? mq = MediaQuery.maybeOf(context);
if (mq == null) mq = MediaQueryData.fromView(View.of(context));
return mq;
final view = View.maybeOf(context);
if (view != null) return MediaQueryData.fromView(view);
return null;
}
Future<void> _validateSize() async {
... ...