From cd4811ff68f930116dfc16c2e1a1a0a8f411bb83 Mon Sep 17 00:00:00 2001 From: Mounir Bouaiche Date: Mon, 12 Jun 2023 00:52:36 +0100 Subject: [PATCH] Add ensureScreenSizeAndInit + make init sync --- lib/src/screen_util.dart | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/lib/src/screen_util.dart b/lib/src/screen_util.dart index dbc36e7..477d7db 100644 --- a/lib/src/screen_util.dart +++ b/lib/src/screen_util.dart @@ -92,16 +92,13 @@ class ScreenUtil { } } - static Future configure({ + static void configure({ MediaQueryData? data, Size? designSize, bool? splitScreenMode, bool? minTextAdapt, - bool? ensureScreenHasSize, FontSizeResolver? fontSizeResolver, - }) async { - if (ensureScreenHasSize ?? false) await ScreenUtil.ensureScreenSize(); - + }) { try { if (data != null) _instance._data = data; @@ -135,24 +132,40 @@ class ScreenUtil { } /// Initializing the library. - static Future init( + static void init( BuildContext context, { Size designSize = defaultSize, bool splitScreenMode = false, bool minTextAdapt = false, - bool ensureScreenSize = false, FontSizeResolver? fontSizeResolver, }) { return configure( data: MediaQuery.maybeOf(context), designSize: designSize, - minTextAdapt: minTextAdapt, splitScreenMode: splitScreenMode, - ensureScreenHasSize: ensureScreenSize, + minTextAdapt: minTextAdapt, fontSizeResolver: fontSizeResolver, ); } + static Future ensureScreenSizeAndInit( + BuildContext context, { + Size designSize = defaultSize, + bool splitScreenMode = false, + bool minTextAdapt = false, + FontSizeResolver? fontSizeResolver, + }) { + return ScreenUtil.ensureScreenSize().then((_) { + return configure( + data: MediaQuery.maybeOf(context), + designSize: designSize, + minTextAdapt: minTextAdapt, + splitScreenMode: splitScreenMode, + fontSizeResolver: fontSizeResolver, + ); + }); + } + ///获取屏幕方向 ///Get screen orientation Orientation get orientation => _orientation;