Skip to content

Commit 26a4b1f

Browse files
authored
推荐使用 useInheritedMediaQuery 为 false (#485)
1 parent 1479ea4 commit 26a4b1f

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lib/src/screenutil_init.dart

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class ScreenUtilInit extends StatefulWidget {
3939
this.designSize = ScreenUtil.defaultSize,
4040
this.splitScreenMode = false,
4141
this.minTextAdapt = false,
42-
this.useInheritedMediaQuery = true,
42+
this.useInheritedMediaQuery = false,
4343
this.scaleByHeight = false})
4444
: super(key: key);
4545

@@ -76,15 +76,17 @@ class _ScreenUtilInitState extends State<ScreenUtilInit>
7676
wrappedInMediaQuery = true;
7777
return data;
7878
}
79+
} else {
80+
final data = MediaQuery.maybeOf(context);
81+
82+
if (data != null) {
83+
return data;
84+
}
7985
}
8086

8187
return MediaQueryData.fromView(View.of(context));
8288
}
8389

84-
Widget get child {
85-
return widget.builder.call(context, widget.child);
86-
}
87-
8890
_updateTree(Element el) {
8991
el.markNeedsBuild();
9092
el.visitChildren(_updateTree);
@@ -148,7 +150,7 @@ class _ScreenUtilInitState extends State<ScreenUtilInit>
148150
widget.designSize.height
149151
: deviceSize.width,
150152
height: deviceSize.height,
151-
child: child,
153+
child: widget.builder(__context, widget.child),
152154
),
153155
));
154156
},
@@ -176,7 +178,7 @@ class _ScreenUtilInitState extends State<ScreenUtilInit>
176178
widget.designSize.height
177179
: deviceSize.width,
178180
height: deviceSize.height,
179-
child: child,
181+
child: widget.builder(_context, widget.child),
180182
),
181183
));
182184
}

0 commit comments

Comments
 (0)