李卓原

空安全优化

@@ -75,14 +75,16 @@ class ScreenUtil { @@ -75,14 +75,16 @@ class ScreenUtil {
75 75
76 /// Initializing the library. 76 /// Initializing the library.
77 static void init( 77 static void init(
78 - BuildContext context, { 78 + BuildContext? context, {
79 Orientation? orientation, 79 Orientation? orientation,
80 Size? deviceSize, 80 Size? deviceSize,
81 Size designSize = defaultSize, 81 Size designSize = defaultSize,
82 bool splitScreenMode = false, 82 bool splitScreenMode = false,
83 bool minTextAdapt = false, 83 bool minTextAdapt = false,
84 }) { 84 }) {
85 - final deviceData = MediaQuery.maybeOf(context).nonEmptySizeOrNull(); 85 + final deviceData = context != null
  86 + ? MediaQuery.maybeOf(context).nonEmptySizeOrNull()
  87 + : null;
86 88
87 deviceSize ??= deviceData?.size ?? designSize; 89 deviceSize ??= deviceData?.size ?? designSize;
88 orientation ??= deviceData?.orientation ?? 90 orientation ??= deviceData?.orientation ??
@@ -97,7 +99,7 @@ class ScreenUtil { @@ -97,7 +99,7 @@ class ScreenUtil {
97 .._orientation = orientation 99 .._orientation = orientation
98 .._screenWidth = deviceSize.width 100 .._screenWidth = deviceSize.width
99 .._screenHeight = deviceSize.height 101 .._screenHeight = deviceSize.height
100 - ..context = deviceData != null ? context : null; 102 + ..context = context;
101 } 103 }
102 104
103 ///获取屏幕方向 105 ///获取屏幕方向
@@ -2,7 +2,6 @@ name: flutter_screenutil @@ -2,7 +2,6 @@ name: flutter_screenutil
2 description: A flutter plugin for adapting screen and font size.Guaranteed to look good on different models 2 description: A flutter plugin for adapting screen and font size.Guaranteed to look good on different models
3 version: 5.4.0 3 version: 5.4.0
4 homepage: https://github.com/OpenFlutter/flutter_screenutil 4 homepage: https://github.com/OpenFlutter/flutter_screenutil
5 -publish_to: https://pub.dev  
6 5
7 environment: 6 environment:
8 sdk: ">=2.12.0 <3.0.0" 7 sdk: ">=2.12.0 <3.0.0"