Mounir Bouaiche

Add ensureScreenSizeAndInit + make init sync

@@ -92,16 +92,13 @@ class ScreenUtil { @@ -92,16 +92,13 @@ class ScreenUtil {
92 } 92 }
93 } 93 }
94 94
95 - static Future<void> configure({ 95 + static void configure({
96 MediaQueryData? data, 96 MediaQueryData? data,
97 Size? designSize, 97 Size? designSize,
98 bool? splitScreenMode, 98 bool? splitScreenMode,
99 bool? minTextAdapt, 99 bool? minTextAdapt,
100 - bool? ensureScreenHasSize,  
101 FontSizeResolver? fontSizeResolver, 100 FontSizeResolver? fontSizeResolver,
102 - }) async {  
103 - if (ensureScreenHasSize ?? false) await ScreenUtil.ensureScreenSize();  
104 - 101 + }) {
105 try { 102 try {
106 if (data != null) 103 if (data != null)
107 _instance._data = data; 104 _instance._data = data;
@@ -135,24 +132,40 @@ class ScreenUtil { @@ -135,24 +132,40 @@ class ScreenUtil {
135 } 132 }
136 133
137 /// Initializing the library. 134 /// Initializing the library.
138 - static Future<void> init( 135 + static void init(
139 BuildContext context, { 136 BuildContext context, {
140 Size designSize = defaultSize, 137 Size designSize = defaultSize,
141 bool splitScreenMode = false, 138 bool splitScreenMode = false,
142 bool minTextAdapt = false, 139 bool minTextAdapt = false,
143 - bool ensureScreenSize = false,  
144 FontSizeResolver? fontSizeResolver, 140 FontSizeResolver? fontSizeResolver,
145 }) { 141 }) {
146 return configure( 142 return configure(
147 data: MediaQuery.maybeOf(context), 143 data: MediaQuery.maybeOf(context),
148 designSize: designSize, 144 designSize: designSize,
149 - minTextAdapt: minTextAdapt,  
150 splitScreenMode: splitScreenMode, 145 splitScreenMode: splitScreenMode,
151 - ensureScreenHasSize: ensureScreenSize, 146 + minTextAdapt: minTextAdapt,
152 fontSizeResolver: fontSizeResolver, 147 fontSizeResolver: fontSizeResolver,
153 ); 148 );
154 } 149 }
155 150
  151 + static Future<void> ensureScreenSizeAndInit(
  152 + BuildContext context, {
  153 + Size designSize = defaultSize,
  154 + bool splitScreenMode = false,
  155 + bool minTextAdapt = false,
  156 + FontSizeResolver? fontSizeResolver,
  157 + }) {
  158 + return ScreenUtil.ensureScreenSize().then((_) {
  159 + return configure(
  160 + data: MediaQuery.maybeOf(context),
  161 + designSize: designSize,
  162 + minTextAdapt: minTextAdapt,
  163 + splitScreenMode: splitScreenMode,
  164 + fontSizeResolver: fontSizeResolver,
  165 + );
  166 + });
  167 + }
  168 +
156 ///获取屏幕方向 169 ///获取屏幕方向
157 ///Get screen orientation 170 ///Get screen orientation
158 Orientation get orientation => _orientation; 171 Orientation get orientation => _orientation;