Committed by
GitHub
推荐使用 useInheritedMediaQuery 为 false (#485)
Showing
1 changed file
with
9 additions
and
7 deletions
| @@ -39,7 +39,7 @@ class ScreenUtilInit extends StatefulWidget { | @@ -39,7 +39,7 @@ class ScreenUtilInit extends StatefulWidget { | ||
| 39 | this.designSize = ScreenUtil.defaultSize, | 39 | this.designSize = ScreenUtil.defaultSize, |
| 40 | this.splitScreenMode = false, | 40 | this.splitScreenMode = false, |
| 41 | this.minTextAdapt = false, | 41 | this.minTextAdapt = false, |
| 42 | - this.useInheritedMediaQuery = true, | 42 | + this.useInheritedMediaQuery = false, |
| 43 | this.scaleByHeight = false}) | 43 | this.scaleByHeight = false}) |
| 44 | : super(key: key); | 44 | : super(key: key); |
| 45 | 45 | ||
| @@ -76,15 +76,17 @@ class _ScreenUtilInitState extends State<ScreenUtilInit> | @@ -76,15 +76,17 @@ class _ScreenUtilInitState extends State<ScreenUtilInit> | ||
| 76 | wrappedInMediaQuery = true; | 76 | wrappedInMediaQuery = true; |
| 77 | return data; | 77 | return data; |
| 78 | } | 78 | } |
| 79 | + } else { | ||
| 80 | + final data = MediaQuery.maybeOf(context); | ||
| 81 | + | ||
| 82 | + if (data != null) { | ||
| 83 | + return data; | ||
| 84 | + } | ||
| 79 | } | 85 | } |
| 80 | 86 | ||
| 81 | return MediaQueryData.fromView(View.of(context)); | 87 | return MediaQueryData.fromView(View.of(context)); |
| 82 | } | 88 | } |
| 83 | 89 | ||
| 84 | - Widget get child { | ||
| 85 | - return widget.builder.call(context, widget.child); | ||
| 86 | - } | ||
| 87 | - | ||
| 88 | _updateTree(Element el) { | 90 | _updateTree(Element el) { |
| 89 | el.markNeedsBuild(); | 91 | el.markNeedsBuild(); |
| 90 | el.visitChildren(_updateTree); | 92 | el.visitChildren(_updateTree); |
| @@ -148,7 +150,7 @@ class _ScreenUtilInitState extends State<ScreenUtilInit> | @@ -148,7 +150,7 @@ class _ScreenUtilInitState extends State<ScreenUtilInit> | ||
| 148 | widget.designSize.height | 150 | widget.designSize.height |
| 149 | : deviceSize.width, | 151 | : deviceSize.width, |
| 150 | height: deviceSize.height, | 152 | height: deviceSize.height, |
| 151 | - child: child, | 153 | + child: widget.builder(__context, widget.child), |
| 152 | ), | 154 | ), |
| 153 | )); | 155 | )); |
| 154 | }, | 156 | }, |
| @@ -176,7 +178,7 @@ class _ScreenUtilInitState extends State<ScreenUtilInit> | @@ -176,7 +178,7 @@ class _ScreenUtilInitState extends State<ScreenUtilInit> | ||
| 176 | widget.designSize.height | 178 | widget.designSize.height |
| 177 | : deviceSize.width, | 179 | : deviceSize.width, |
| 178 | height: deviceSize.height, | 180 | height: deviceSize.height, |
| 179 | - child: child, | 181 | + child: widget.builder(_context, widget.child), |
| 180 | ), | 182 | ), |
| 181 | )); | 183 | )); |
| 182 | } | 184 | } |
-
Please register or login to post a comment