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
顾海波
2025-05-26 12:08:44 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
652135eaed49850b7a36c0f151c81dd6e18f17d9
652135ea
1 parent
6982b124
【需求】跟随设计稿方向
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
6 deletions
lib/src/screen_util.dart
lib/src/screenutil_init.dart
lib/src/screen_util.dart
View file @
652135e
...
...
@@ -18,6 +18,7 @@ class ScreenUtil {
static
bool
Function
()
_enableScaleWH
=
()
=>
true
;
static
bool
Function
()
_enableScaleText
=
()
=>
true
;
static
bool
Function
()
_useDesignOrientation
=
()
=>
false
;
/// UI设计中手机尺寸 , dp
...
...
@@ -27,6 +28,9 @@ class ScreenUtil {
///屏幕方向
late
Orientation
_orientation
;
///设计稿方向
late
Orientation
_designOrientation
;
late
bool
_minTextAdapt
;
late
MediaQueryData
_data
;
late
bool
_splitScreenMode
;
...
...
@@ -41,9 +45,10 @@ class ScreenUtil {
/// if the enableWH return false, the width and the height scale ratio will be 1
/// if the enableText return false, the text scale ratio will be 1
///
static
void
enableScale
({
bool
Function
()?
enableWH
,
bool
Function
()?
enableText
})
{
static
void
enableScale
({
bool
Function
()?
enableWH
,
bool
Function
()?
enableText
,
bool
Function
()?
useDesignOrientation
})
{
_enableScaleWH
=
enableWH
??
()
=>
true
;
_enableScaleText
=
enableText
??
()
=>
true
;
_useDesignOrientation
=
useDesignOrientation
??
()
=>
false
;
}
/// Manually wait for window size to be initialized
...
...
@@ -138,11 +143,16 @@ class ScreenUtil {
?
Orientation
.
landscape
:
Orientation
.
portrait
);
final
designOrientation
=
designSize
.
width
>
designSize
.
height
?
Orientation
.
landscape
:
Orientation
.
portrait
;
_instance
..
fontSizeResolver
=
fontSizeResolver
??
_instance
.
fontSizeResolver
..
_minTextAdapt
=
minTextAdapt
??
_instance
.
_minTextAdapt
..
_splitScreenMode
=
splitScreenMode
??
_instance
.
_splitScreenMode
..
_orientation
=
orientation
;
..
_orientation
=
orientation
..
_designOrientation
=
designOrientation
;
_instance
.
_elementsToRebuild
?.
forEach
((
el
)
=>
el
.
markNeedsBuild
());
}
...
...
@@ -213,12 +223,13 @@ class ScreenUtil {
/// 实际尺寸与UI设计的比例
/// The ratio of actual width to UI design
double
get
scaleWidth
=>
!
_enableScaleWH
()
?
1
:
screenWidth
/
_uiSize
.
width
;
double
get
scaleWidth
=>
!
_enableScaleWH
()
?
1
:
screenWidth
/
((
_useDesignOrientation
()
&&
_designOrientation
!=
_orientation
)?
_uiSize
.
height
:
_uiSize
.
width
);
/// The ratio of actual height to UI design
double
get
scaleHeight
=>
!
_enableScaleWH
()
?
1
:
(
_splitScreenMode
?
max
(
screenHeight
,
700
)
:
screenHeight
)
/
_uiSize
.
height
;
((
_useDesignOrientation
()
&&
_designOrientation
!=
_orientation
)?
_uiSize
.
width
:
_uiSize
.
height
)
;
double
get
scaleText
=>
!
_enableScaleText
()
?
1
:
(
_minTextAdapt
?
min
(
scaleWidth
,
scaleHeight
)
:
scaleWidth
);
...
...
lib/src/screenutil_init.dart
View file @
652135e
...
...
@@ -76,9 +76,10 @@ class ScreenUtilInit extends StatefulWidget {
this
.
ensureScreenSize
=
false
,
this
.
enableScaleWH
,
this
.
enableScaleText
,
this
.
useDesignOrientation
,
this
.
responsiveWidgets
,
this
.
excludeWidgets
,
this
.
fontSizeResolver
=
FontSizeResolvers
.
width
,
this
.
fontSizeResolver
=
FontSizeResolvers
.
width
})
:
super
(
key:
key
);
final
ScreenUtilInitBuilder
?
builder
;
...
...
@@ -89,6 +90,7 @@ class ScreenUtilInit extends StatefulWidget {
final
bool
ensureScreenSize
;
final
bool
Function
()?
enableScaleWH
;
final
bool
Function
()?
enableScaleText
;
final
bool
Function
()?
useDesignOrientation
;
final
RebuildFactor
rebuildFactor
;
final
FontSizeResolver
fontSizeResolver
;
...
...
@@ -114,7 +116,7 @@ class _ScreenUtilInitState extends State<ScreenUtilInit> with WidgetsBindingObse
_canMarkedToBuild
.
addAll
(
widget
.
responsiveWidgets
!);
}
ScreenUtil
.
enableScale
(
enableWH:
widget
.
enableScaleWH
,
enableText:
widget
.
enableScaleText
);
ScreenUtil
.
enableScale
(
enableWH:
widget
.
enableScaleWH
,
enableText:
widget
.
enableScaleText
,
useDesignOrientation:
widget
.
useDesignOrientation
);
_validateSize
().
then
(
_screenSizeCompleter
.
complete
);
...
...
Please
register
or
login
to post a comment