Skip to content

Commit cd4811f

Browse files
author
Mounir Bouaiche
committed
Add ensureScreenSizeAndInit + make init sync
1 parent f156608 commit cd4811f

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

lib/src/screen_util.dart

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,13 @@ class ScreenUtil {
9292
}
9393
}
9494

95-
static Future<void> configure({
95+
static void configure({
9696
MediaQueryData? data,
9797
Size? designSize,
9898
bool? splitScreenMode,
9999
bool? minTextAdapt,
100-
bool? ensureScreenHasSize,
101100
FontSizeResolver? fontSizeResolver,
102-
}) async {
103-
if (ensureScreenHasSize ?? false) await ScreenUtil.ensureScreenSize();
104-
101+
}) {
105102
try {
106103
if (data != null)
107104
_instance._data = data;
@@ -135,24 +132,40 @@ class ScreenUtil {
135132
}
136133

137134
/// Initializing the library.
138-
static Future<void> init(
135+
static void init(
139136
BuildContext context, {
140137
Size designSize = defaultSize,
141138
bool splitScreenMode = false,
142139
bool minTextAdapt = false,
143-
bool ensureScreenSize = false,
144140
FontSizeResolver? fontSizeResolver,
145141
}) {
146142
return configure(
147143
data: MediaQuery.maybeOf(context),
148144
designSize: designSize,
149-
minTextAdapt: minTextAdapt,
150145
splitScreenMode: splitScreenMode,
151-
ensureScreenHasSize: ensureScreenSize,
146+
minTextAdapt: minTextAdapt,
152147
fontSizeResolver: fontSizeResolver,
153148
);
154149
}
155150

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+
156169
///获取屏幕方向
157170
///Get screen orientation
158171
Orientation get orientation => _orientation;

0 commit comments

Comments
 (0)