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
李卓原
2023-01-30 13:42:36 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
5b48d1d4d7bafbeaf454a830e45b0354a3e5a345
5b48d1d4
1 parent
032b6dbe
FlutterView instead of FlutterWindow
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
30 deletions
lib/src/screen_util.dart
lib/src/screenutil_init.dart
lib/src/screen_util.dart
View file @
5b48d1d
...
...
@@ -4,7 +4,7 @@
*/
import
'dart:math'
show
min
,
max
;
import
'dart:ui'
show
Flutter
Windo
w
;
import
'dart:ui'
show
Flutter
Vie
w
;
import
'dart:async'
show
Completer
;
import
'package:flutter/widgets.dart'
;
...
...
@@ -55,7 +55,7 @@ class ScreenUtil {
/// )
/// ```
static
Future
<
void
>
ensureScreenSize
([
Flutter
Windo
w
?
window
,
Flutter
Vie
w
?
window
,
Duration
duration
=
const
Duration
(
milliseconds:
10
),
])
async
{
final
binding
=
WidgetsFlutterBinding
.
ensureInitialized
();
...
...
lib/src/screenutil_init.dart
View file @
5b48d1d
import
'package:flutter/widgets.dart'
;
import
'screen_util.dart'
;
import
'dart:ui'
show
FlutterWindow
;
typedef
RebuildFactor
=
bool
Function
(
MediaQueryData
old
,
MediaQueryData
data
);
...
...
@@ -32,17 +31,17 @@ class RebuildFactors {
class
ScreenUtilInit
extends
StatefulWidget
{
/// A helper widget that initializes [ScreenUtil]
const
ScreenUtilInit
({
Key
?
key
,
required
this
.
builder
,
this
.
child
,
this
.
rebuildFactor
=
RebuildFactors
.
size
,
this
.
designSize
=
ScreenUtil
.
defaultSize
,
this
.
splitScreenMode
=
false
,
this
.
minTextAdapt
=
false
,
this
.
useInheritedMediaQuery
=
false
,
this
.
scaleByHeight
=
false
})
:
super
(
key:
key
);
const
ScreenUtilInit
(
{
Key
?
key
,
required
this
.
builder
,
this
.
child
,
this
.
rebuildFactor
=
RebuildFactors
.
size
,
this
.
designSize
=
ScreenUtil
.
defaultSize
,
this
.
splitScreenMode
=
false
,
this
.
minTextAdapt
=
false
,
this
.
useInheritedMediaQuery
=
false
,
this
.
scaleByHeight
=
false
})
:
super
(
key:
key
);
final
ScreenUtilInitBuilder
builder
;
final
Widget
?
child
;
...
...
@@ -133,13 +132,11 @@ class _ScreenUtilInitState extends State<ScreenUtilInit>
builder:
(
__context
)
{
final
deviceData
=
MediaQuery
.
maybeOf
(
__context
);
final
deviceSize
=
deviceData
?.
size
??
widget
.
designSize
;
ScreenUtil
.
init
(
__context
,
ScreenUtil
.
init
(
__context
,
designSize:
widget
.
designSize
,
splitScreenMode:
widget
.
splitScreenMode
,
minTextAdapt:
widget
.
minTextAdapt
,
scaleByHeight:
widget
.
scaleByHeight
);
scaleByHeight:
widget
.
scaleByHeight
);
return
Container
(
width:
deviceSize
.
width
,
height:
deviceSize
.
height
,
...
...
@@ -149,25 +146,22 @@ class _ScreenUtilInitState extends State<ScreenUtilInit>
child:
Container
(
width:
widget
.
scaleByHeight
?
(
deviceSize
.
height
*
widget
.
designSize
.
width
)
/
widget
.
designSize
.
height
widget
.
designSize
.
height
:
deviceSize
.
width
,
height:
deviceSize
.
height
,
child:
child
,
),
)
);
));
},
),
);
}
ScreenUtil
.
init
(
_context
,
ScreenUtil
.
init
(
_context
,
designSize:
widget
.
designSize
,
splitScreenMode:
widget
.
splitScreenMode
,
minTextAdapt:
widget
.
minTextAdapt
,
scaleByHeight:
widget
.
scaleByHeight
);
scaleByHeight:
widget
.
scaleByHeight
);
final
deviceData
=
MediaQuery
.
maybeOf
(
_context
);
final
deviceSize
=
deviceData
?.
size
??
widget
.
designSize
;
...
...
@@ -178,13 +172,13 @@ class _ScreenUtilInitState extends State<ScreenUtilInit>
fit:
BoxFit
.
none
,
alignment:
Alignment
.
center
,
child:
Container
(
width:
widget
.
scaleByHeight
?
(
deviceSize
.
height
*
widget
.
designSize
.
width
)
/
widget
.
designSize
.
height
:
deviceSize
.
width
,
width:
widget
.
scaleByHeight
?
(
deviceSize
.
height
*
widget
.
designSize
.
width
)
/
widget
.
designSize
.
height
:
deviceSize
.
width
,
height:
deviceSize
.
height
,
child:
child
,
),
)
);
));
}
}
...
...
Please
register
or
login
to post a comment