Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
flutter_screenutil
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Mounir Bouaiche
2023-06-11 19:51:52 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
53651007f9ae7455208049787defe38464041d9c
53651007
1 parent
6fed40a8
Little code solidity
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
28 deletions
lib/src/screen_util.dart
lib/src/screenutil_init.dart
lib/src/screen_util.dart
View file @
5365100
...
...
@@ -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
;
...
...
lib/src/screenutil_init.dart
View file @
5365100
...
...
@@ -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
!;
...
...
Please
register
or
login
to post a comment