Mounir Bouaiche

Little code solidity

... ... @@ -25,25 +25,7 @@ class ScreenUtil {
ScreenUtil._();
factory ScreenUtil() {
return _instance;
}
factory ScreenUtil.init(
BuildContext context, {
Size designSize = defaultSize,
bool splitScreenMode = false,
bool minTextAdapt = false,
}) {
configure(
data: MediaQuery.maybeOf(context),
designSize: designSize,
minTextAdapt: minTextAdapt,
splitScreenMode: splitScreenMode,
);
return _instance;
}
factory ScreenUtil() => _instance;
/// Manually wait for window size to be initialized
///
... ... @@ -79,7 +61,7 @@ class ScreenUtil {
window = binding.platformDispatcher.implicitView;
}
if (window == null || window!.physicalGeometry.isEmpty == true) {
if (window == null || window!.physicalGeometry.isEmpty) {
return Future.delayed(duration, () => true);
}
... ... @@ -107,19 +89,32 @@ class ScreenUtil {
}
}
/// Initializing the library.
static void configure({
static Future<void> configure({
MediaQueryData? data,
Size? designSize,
bool? splitScreenMode,
bool? minTextAdapt,
}) {
if (data != null) _instance._data = data;
bool? ensureScreenHasSize,
}) async {
if (ensureScreenHasSize ?? false) await ScreenUtil.ensureScreenSize();
final deviceData = _instance._data.nonEmptySizeOrNull();
final deviceSize = deviceData?.size ?? designSize ?? _instance._uiSize;
try {
if (data != null)
_instance._data = data;
else
data = _instance._data;
if (designSize != null) _instance._uiSize = designSize;
if (designSize != null)
_instance._uiSize = designSize;
else
designSize = _instance._uiSize;
} catch (_) {
throw Exception(
'You must either use ScreenUtil.init or ScreenUtilInit first');
}
final MediaQueryData? deviceData = data.nonEmptySizeOrNull();
final Size deviceSize = deviceData?.size ?? designSize;
final orientation = deviceData?.orientation ??
(deviceSize.width > deviceSize.height
... ... @@ -134,6 +129,23 @@ class ScreenUtil {
_instance._elementsToRebuild?.forEach((el) => el.markNeedsBuild());
}
/// Initializing the library.
static Future<void> init(
BuildContext context, {
Size designSize = defaultSize,
bool splitScreenMode = false,
bool minTextAdapt = false,
bool ensureScreenSize = false,
}) {
return configure(
data: MediaQuery.maybeOf(context),
designSize: designSize,
minTextAdapt: minTextAdapt,
splitScreenMode: splitScreenMode,
ensureScreenHasSize: ensureScreenSize,
);
}
///获取屏幕方向
///Get screen orientation
Orientation get orientation => _orientation;
... ... @@ -166,7 +178,7 @@ class ScreenUtil {
/// The ratio of actual width to UI design
double get scaleWidth => screenWidth / _uiSize.width;
/// /// The ratio of actual height to UI design
/// The ratio of actual height to UI design
double get scaleHeight =>
(_splitScreenMode ? max(screenHeight, 700) : screenHeight) /
_uiSize.height;
... ...
... ... @@ -50,6 +50,7 @@ class ScreenUtilInit extends StatefulWidget {
this.splitScreenMode = false,
this.minTextAdapt = false,
this.useInheritedMediaQuery = false,
this.ensureScreenSize,
this.responsiveWidgets,
}) : super(key: key);
... ... @@ -58,6 +59,7 @@ class ScreenUtilInit extends StatefulWidget {
final bool splitScreenMode;
final bool minTextAdapt;
final bool useInheritedMediaQuery;
final bool? ensureScreenSize;
final RebuildFactor rebuildFactor;
/// The [Size] of the device in the design draft, in dp
... ... @@ -143,6 +145,7 @@ class _ScreenUtilInitState extends State<ScreenUtilInit>
designSize: widget.designSize,
splitScreenMode: widget.splitScreenMode,
minTextAdapt: widget.minTextAdapt,
ensureScreenHasSize: widget.ensureScreenSize,
);
return widget.builder?.call(context, widget.child) ?? widget.child!;
... ...