Skip to content

Commit f9651f8

Browse files
Depend on View instead of MediaQuery
1 parent 9f63be0 commit f9651f8

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

lib/src/screen_util.dart

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ class ScreenUtil {
141141
bool minTextAdapt = false,
142142
FontSizeResolver? fontSizeResolver,
143143
}) {
144+
final view = View.maybeOf(context);
144145
return configure(
145-
data: MediaQuery.maybeOf(context),
146+
data: view != null ? MediaQueryData.fromView(view) : null,
146147
designSize: designSize,
147148
splitScreenMode: splitScreenMode,
148149
minTextAdapt: minTextAdapt,
@@ -158,8 +159,8 @@ class ScreenUtil {
158159
FontSizeResolver? fontSizeResolver,
159160
}) {
160161
return ScreenUtil.ensureScreenSize().then((_) {
161-
return configure(
162-
data: MediaQuery.maybeOf(context),
162+
return init(
163+
context,
163164
designSize: designSize,
164165
minTextAdapt: minTextAdapt,
165166
splitScreenMode: splitScreenMode,
@@ -251,8 +252,11 @@ class ScreenUtil {
251252
if (kIsWeb) {
252253
deviceType = DeviceType.web;
253254
} else {
254-
bool isMobile = defaultTargetPlatform == TargetPlatform.iOS || defaultTargetPlatform == TargetPlatform.android;
255-
bool isTablet = (orientation == Orientation.portrait && screenWidth >= 600) || (orientation == Orientation.landscape && screenHeight >= 600);
255+
bool isMobile = defaultTargetPlatform == TargetPlatform.iOS ||
256+
defaultTargetPlatform == TargetPlatform.android;
257+
bool isTablet =
258+
(orientation == Orientation.portrait && screenWidth >= 600) ||
259+
(orientation == Orientation.landscape && screenHeight >= 600);
256260

257261
if (isMobile) {
258262
deviceType = isTablet ? DeviceType.tablet : DeviceType.mobile;

lib/src/screenutil_init.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,9 @@ class _ScreenUtilInitState extends State<ScreenUtilInit>
126126
}
127127

128128
MediaQueryData? _newData() {
129-
MediaQueryData? mq = MediaQuery.maybeOf(context);
130-
if (mq == null) mq = MediaQueryData.fromView(View.of(context));
131-
132-
return mq;
129+
final view = View.maybeOf(context);
130+
if (view != null) return MediaQueryData.fromView(view);
131+
return null;
133132
}
134133

135134
Future<void> _validateSize() async {

0 commit comments

Comments
 (0)