Showing
2 changed files
with
16 additions
and
22 deletions
| @@ -4,7 +4,7 @@ | @@ -4,7 +4,7 @@ | ||
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | import 'dart:math' show min, max; | 6 | import 'dart:math' show min, max; |
| 7 | -import 'dart:ui' show FlutterWindow; | 7 | +import 'dart:ui' show FlutterView; |
| 8 | import 'dart:async' show Completer; | 8 | import 'dart:async' show Completer; |
| 9 | 9 | ||
| 10 | import 'package:flutter/widgets.dart'; | 10 | import 'package:flutter/widgets.dart'; |
| @@ -55,7 +55,7 @@ class ScreenUtil { | @@ -55,7 +55,7 @@ class ScreenUtil { | ||
| 55 | /// ) | 55 | /// ) |
| 56 | /// ``` | 56 | /// ``` |
| 57 | static Future<void> ensureScreenSize([ | 57 | static Future<void> ensureScreenSize([ |
| 58 | - FlutterWindow? window, | 58 | + FlutterView? window, |
| 59 | Duration duration = const Duration(milliseconds: 10), | 59 | Duration duration = const Duration(milliseconds: 10), |
| 60 | ]) async { | 60 | ]) async { |
| 61 | final binding = WidgetsFlutterBinding.ensureInitialized(); | 61 | final binding = WidgetsFlutterBinding.ensureInitialized(); |
| 1 | import 'package:flutter/widgets.dart'; | 1 | import 'package:flutter/widgets.dart'; |
| 2 | 2 | ||
| 3 | import 'screen_util.dart'; | 3 | import 'screen_util.dart'; |
| 4 | -import 'dart:ui' show FlutterWindow; | ||
| 5 | 4 | ||
| 6 | typedef RebuildFactor = bool Function(MediaQueryData old, MediaQueryData data); | 5 | typedef RebuildFactor = bool Function(MediaQueryData old, MediaQueryData data); |
| 7 | 6 | ||
| @@ -32,8 +31,8 @@ class RebuildFactors { | @@ -32,8 +31,8 @@ class RebuildFactors { | ||
| 32 | 31 | ||
| 33 | class ScreenUtilInit extends StatefulWidget { | 32 | class ScreenUtilInit extends StatefulWidget { |
| 34 | /// A helper widget that initializes [ScreenUtil] | 33 | /// A helper widget that initializes [ScreenUtil] |
| 35 | - const ScreenUtilInit({ | ||
| 36 | - Key? key, | 34 | + const ScreenUtilInit( |
| 35 | + {Key? key, | ||
| 37 | required this.builder, | 36 | required this.builder, |
| 38 | this.child, | 37 | this.child, |
| 39 | this.rebuildFactor = RebuildFactors.size, | 38 | this.rebuildFactor = RebuildFactors.size, |
| @@ -41,8 +40,8 @@ class ScreenUtilInit extends StatefulWidget { | @@ -41,8 +40,8 @@ class ScreenUtilInit extends StatefulWidget { | ||
| 41 | this.splitScreenMode = false, | 40 | this.splitScreenMode = false, |
| 42 | this.minTextAdapt = false, | 41 | this.minTextAdapt = false, |
| 43 | this.useInheritedMediaQuery = false, | 42 | this.useInheritedMediaQuery = false, |
| 44 | - this.scaleByHeight = false | ||
| 45 | - }) : super(key: key); | 43 | + this.scaleByHeight = false}) |
| 44 | + : super(key: key); | ||
| 46 | 45 | ||
| 47 | final ScreenUtilInitBuilder builder; | 46 | final ScreenUtilInitBuilder builder; |
| 48 | final Widget? child; | 47 | final Widget? child; |
| @@ -133,13 +132,11 @@ class _ScreenUtilInitState extends State<ScreenUtilInit> | @@ -133,13 +132,11 @@ class _ScreenUtilInitState extends State<ScreenUtilInit> | ||
| 133 | builder: (__context) { | 132 | builder: (__context) { |
| 134 | final deviceData = MediaQuery.maybeOf(__context); | 133 | final deviceData = MediaQuery.maybeOf(__context); |
| 135 | final deviceSize = deviceData?.size ?? widget.designSize; | 134 | final deviceSize = deviceData?.size ?? widget.designSize; |
| 136 | - ScreenUtil.init( | ||
| 137 | - __context, | 135 | + ScreenUtil.init(__context, |
| 138 | designSize: widget.designSize, | 136 | designSize: widget.designSize, |
| 139 | splitScreenMode: widget.splitScreenMode, | 137 | splitScreenMode: widget.splitScreenMode, |
| 140 | minTextAdapt: widget.minTextAdapt, | 138 | minTextAdapt: widget.minTextAdapt, |
| 141 | - scaleByHeight: widget.scaleByHeight | ||
| 142 | - ); | 139 | + scaleByHeight: widget.scaleByHeight); |
| 143 | return Container( | 140 | return Container( |
| 144 | width: deviceSize.width, | 141 | width: deviceSize.width, |
| 145 | height: deviceSize.height, | 142 | height: deviceSize.height, |
| @@ -154,20 +151,17 @@ class _ScreenUtilInitState extends State<ScreenUtilInit> | @@ -154,20 +151,17 @@ class _ScreenUtilInitState extends State<ScreenUtilInit> | ||
| 154 | height: deviceSize.height, | 151 | height: deviceSize.height, |
| 155 | child: child, | 152 | child: child, |
| 156 | ), | 153 | ), |
| 157 | - ) | ||
| 158 | - ); | 154 | + )); |
| 159 | }, | 155 | }, |
| 160 | ), | 156 | ), |
| 161 | ); | 157 | ); |
| 162 | } | 158 | } |
| 163 | 159 | ||
| 164 | - ScreenUtil.init( | ||
| 165 | - _context, | 160 | + ScreenUtil.init(_context, |
| 166 | designSize: widget.designSize, | 161 | designSize: widget.designSize, |
| 167 | splitScreenMode: widget.splitScreenMode, | 162 | splitScreenMode: widget.splitScreenMode, |
| 168 | minTextAdapt: widget.minTextAdapt, | 163 | minTextAdapt: widget.minTextAdapt, |
| 169 | - scaleByHeight: widget.scaleByHeight | ||
| 170 | - ); | 164 | + scaleByHeight: widget.scaleByHeight); |
| 171 | final deviceData = MediaQuery.maybeOf(_context); | 165 | final deviceData = MediaQuery.maybeOf(_context); |
| 172 | 166 | ||
| 173 | final deviceSize = deviceData?.size ?? widget.designSize; | 167 | final deviceSize = deviceData?.size ?? widget.designSize; |
| @@ -178,13 +172,13 @@ class _ScreenUtilInitState extends State<ScreenUtilInit> | @@ -178,13 +172,13 @@ class _ScreenUtilInitState extends State<ScreenUtilInit> | ||
| 178 | fit: BoxFit.none, | 172 | fit: BoxFit.none, |
| 179 | alignment: Alignment.center, | 173 | alignment: Alignment.center, |
| 180 | child: Container( | 174 | child: Container( |
| 181 | - width: widget.scaleByHeight ? (deviceSize.height * | ||
| 182 | - widget.designSize.width) / widget.designSize.height : deviceSize | ||
| 183 | - .width, | 175 | + width: widget.scaleByHeight |
| 176 | + ? (deviceSize.height * widget.designSize.width) / | ||
| 177 | + widget.designSize.height | ||
| 178 | + : deviceSize.width, | ||
| 184 | height: deviceSize.height, | 179 | height: deviceSize.height, |
| 185 | child: child, | 180 | child: child, |
| 186 | ), | 181 | ), |
| 187 | - ) | ||
| 188 | - ); | 182 | + )); |
| 189 | } | 183 | } |
| 190 | } | 184 | } |
-
Please register or login to post a comment