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
MT
2022-11-11 11:44:44 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
GitHub
2022-11-11 11:44:44 +0800
Commit
9ddb7a72b36bd2a341926f84e94835f47e440bfb
9ddb7a72
1 parent
9e829b15
scale by height (#437)
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
6 deletions
lib/src/screen_util.dart
lib/src/screenutil_init.dart
lib/src/screen_util.dart
View file @
9ddb7a7
...
...
@@ -94,6 +94,7 @@ class ScreenUtil {
Size
designSize
=
defaultSize
,
bool
splitScreenMode
=
false
,
bool
minTextAdapt
=
false
,
bool
scaleByHeight
=
false
})
async
{
final
navigatorContext
=
Navigator
.
maybeOf
(
context
)?.
context
as
Element
?;
final
mediaQueryContext
=
...
...
@@ -115,12 +116,13 @@ class ScreenUtil {
:
Orientation
.
portrait
);
_instance
..
_context
=
context
..
_context
=
scaleByHeight
?
null
:
context
..
_uiSize
=
designSize
..
_splitScreenMode
=
splitScreenMode
..
_minTextAdapt
=
minTextAdapt
..
_orientation
=
orientation
..
_screenWidth
=
deviceSize
.
width
..
_screenWidth
=
scaleByHeight
?
(
deviceSize
.
height
*
designSize
.
width
)
/
designSize
.
height
:
deviceSize
.
width
..
_screenHeight
=
deviceSize
.
height
;
_instance
.
_elementsToRebuild
?.
forEach
((
el
)
=>
el
.
markNeedsBuild
());
...
...
lib/src/screenutil_init.dart
View file @
9ddb7a7
import
'package:flutter/widgets.dart'
;
import
'screen_util.dart'
;
import
'dart:ui'
show
FlutterWindow
;
typedef
RebuildFactor
=
bool
Function
(
MediaQueryData
old
,
MediaQueryData
data
);
...
...
@@ -40,6 +41,7 @@ class ScreenUtilInit extends StatefulWidget {
this
.
splitScreenMode
=
false
,
this
.
minTextAdapt
=
false
,
this
.
useInheritedMediaQuery
=
false
,
this
.
scaleByHeight
=
false
})
:
super
(
key:
key
);
final
ScreenUtilInitBuilder
builder
;
...
...
@@ -47,6 +49,7 @@ class ScreenUtilInit extends StatefulWidget {
final
bool
splitScreenMode
;
final
bool
minTextAdapt
;
final
bool
useInheritedMediaQuery
;
final
bool
scaleByHeight
;
final
RebuildFactor
rebuildFactor
;
/// The [Size] of the device in the design draft, in dp
...
...
@@ -100,7 +103,7 @@ class _ScreenUtilInitState extends State<ScreenUtilInit>
final
old
=
_mediaQueryData
!;
final
data
=
newData
;
if
(
widget
.
rebuildFactor
(
old
,
data
))
{
if
(
widget
.
scaleByHeight
||
widget
.
rebuildFactor
(
old
,
data
))
{
_mediaQueryData
=
data
;
_updateTree
(
context
as
Element
);
}
...
...
@@ -128,13 +131,31 @@ class _ScreenUtilInitState extends State<ScreenUtilInit>
data:
mediaQueryData
,
child:
Builder
(
builder:
(
__context
)
{
final
deviceData
=
MediaQuery
.
maybeOf
(
__context
);
final
deviceSize
=
deviceData
?.
size
??
widget
.
designSize
;
ScreenUtil
.
init
(
__context
,
designSize:
widget
.
designSize
,
splitScreenMode:
widget
.
splitScreenMode
,
minTextAdapt:
widget
.
minTextAdapt
,
scaleByHeight:
widget
.
scaleByHeight
);
return
Container
(
width:
deviceSize
.
width
,
height:
deviceSize
.
height
,
child:
FittedBox
(
fit:
BoxFit
.
none
,
alignment:
Alignment
.
center
,
child:
Container
(
width:
widget
.
scaleByHeight
?
(
deviceSize
.
height
*
widget
.
designSize
.
width
)
/
widget
.
designSize
.
height
:
deviceSize
.
width
,
height:
deviceSize
.
height
,
child:
child
,
),
)
);
return
child
;
},
),
);
...
...
@@ -145,8 +166,25 @@ class _ScreenUtilInitState extends State<ScreenUtilInit>
designSize:
widget
.
designSize
,
splitScreenMode:
widget
.
splitScreenMode
,
minTextAdapt:
widget
.
minTextAdapt
,
scaleByHeight:
widget
.
scaleByHeight
);
final
deviceData
=
MediaQuery
.
maybeOf
(
_context
);
final
deviceSize
=
deviceData
?.
size
??
widget
.
designSize
;
return
Container
(
width:
deviceSize
.
width
,
height:
deviceSize
.
height
,
child:
FittedBox
(
fit:
BoxFit
.
none
,
alignment:
Alignment
.
center
,
child:
Container
(
width:
widget
.
scaleByHeight
?
(
deviceSize
.
height
*
widget
.
designSize
.
width
)
/
widget
.
designSize
.
height
:
deviceSize
.
width
,
height:
deviceSize
.
height
,
child:
child
,
),
)
);
return
child
;
}
}
...
...
Please
register
or
login
to post a comment