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
李卓原
2019-05-15 16:57:35 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
3ec74132d5ca78b30deecd93b483da89dcf3cbe5
3ec74132
1 parent
a16e14eb
优化部分示例
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
57 additions
and
56 deletions
.packages
example/lib/main.dart
example/lib/main_zh.dart
example/pubspec.lock
pubspec.lock
.packages
View file @
3ec7413
# Generated by pub on 2019-02-21 16:04:26.823126.
async:file:///D:/flutter/.pub-cache/hosted/pub.dartlang.org/async-2.0.8/lib/
# Generated by pub on 2019-05-15 14:31:19.119581.
async:file:///D:/flutter/.pub-cache/hosted/pub.dartlang.org/async-2.1.0/lib/
boolean_selector:file:///D:/flutter/.pub-cache/hosted/pub.dartlang.org/boolean_selector-1.0.4/lib/
charcode:file:///D:/flutter/.pub-cache/hosted/pub.dartlang.org/charcode-1.1.2/lib/
collection:file:///D:/flutter/.pub-cache/hosted/pub.dartlang.org/collection-1.14.11/lib/
flutter:file:///D:/flutter/packages/flutter/lib/
flutter_test:file:///D:/flutter/packages/flutter_test/lib/
matcher:file:///D:/flutter/.pub-cache/hosted/pub.dartlang.org/matcher-0.12.
3+1
/lib/
matcher:file:///D:/flutter/.pub-cache/hosted/pub.dartlang.org/matcher-0.12.
5
/lib/
meta:file:///D:/flutter/.pub-cache/hosted/pub.dartlang.org/meta-1.1.6/lib/
path:file:///D:/flutter/.pub-cache/hosted/pub.dartlang.org/path-1.6.2/lib/
quiver:file:///D:/flutter/.pub-cache/hosted/pub.dartlang.org/quiver-2.0.1/lib/
pedantic:file:///D:/flutter/.pub-cache/hosted/pub.dartlang.org/pedantic-1.5.0/lib/
quiver:file:///D:/flutter/.pub-cache/hosted/pub.dartlang.org/quiver-2.0.2/lib/
sky_engine:file:///D:/flutter/bin/cache/pkg/sky_engine/lib/
source_span:file:///D:/flutter/.pub-cache/hosted/pub.dartlang.org/source_span-1.
4.1
/lib/
source_span:file:///D:/flutter/.pub-cache/hosted/pub.dartlang.org/source_span-1.
5.5
/lib/
stack_trace:file:///D:/flutter/.pub-cache/hosted/pub.dartlang.org/stack_trace-1.9.3/lib/
stream_channel:file:///D:/flutter/.pub-cache/hosted/pub.dartlang.org/stream_channel-
1.6.8
/lib/
stream_channel:file:///D:/flutter/.pub-cache/hosted/pub.dartlang.org/stream_channel-
2.0.0
/lib/
string_scanner:file:///D:/flutter/.pub-cache/hosted/pub.dartlang.org/string_scanner-1.0.4/lib/
term_glyph:file:///D:/flutter/.pub-cache/hosted/pub.dartlang.org/term_glyph-1.0.1/lib/
test_api:file:///D:/flutter/.pub-cache/hosted/pub.dartlang.org/test_api-0.2.1/lib/
term_glyph:file:///D:/flutter/.pub-cache/hosted/pub.dartlang.org/term_glyph-1.1.0/lib/
test_api:file:///D:/flutter/.pub-cache/hosted/pub.dartlang.org/test_api-0.2.4/lib/
typed_data:file:///D:/flutter/.pub-cache/hosted/pub.dartlang.org/typed_data-1.1.6/lib/
vector_math:file:///D:/flutter/.pub-cache/hosted/pub.dartlang.org/vector_math-2.0.8/lib/
flutter_screenutil:lib/
...
...
example/lib/main.dart
View file @
3ec7413
...
...
@@ -33,14 +33,14 @@ class _MyHomePageState extends State<MyHomePage> {
///Set the fit size (fill in the screen size of the device in the design) If the design is based on the size of the iPhone6 (iPhone6 750*1334)
ScreenUtil
.
instance
=
ScreenUtil
(
width:
750
,
height:
1334
)..
init
(
context
);
print
(
'Device width:
${ScreenUtil.screenWidth}
'
);
//Device width
print
(
'Device height:
${ScreenUtil.screenHeight}
'
);
//Device height
print
(
'Device width px:
${ScreenUtil.screenWidth}
'
);
//Device width
print
(
'Device height px:
${ScreenUtil.screenHeight}
'
);
//Device height
print
(
'Device pixel density:
${ScreenUtil.pixelRatio}
'
);
//Device pixel density
print
(
'Bottom safe zone distance:
${ScreenUtil.bottomBarHeight}
'
);
//Bottom safe zone distance,suitable for buttons with full screen
'Bottom safe zone distance
px
:
${ScreenUtil.bottomBarHeight}
'
);
//Bottom safe zone distance,suitable for buttons with full screen
print
(
'Status bar height:
${ScreenUtil.statusBarHeight}
px'
);
//Status bar height , Notch will be higher Unit px
'Status bar height
px
:
${ScreenUtil.statusBarHeight}
px'
);
//Status bar height , Notch will be higher Unit px
print
(
'Ratio of actual width dp to design draft px:
${ScreenUtil.getInstance().scaleWidth}
'
);
print
(
...
...
@@ -49,6 +49,7 @@ class _MyHomePageState extends State<MyHomePage> {
'The ratio of font and width to the size of the design:
${ScreenUtil.getInstance().scaleWidth * ScreenUtil.pixelRatio}
'
);
print
(
'The ratio of height width to the size of the design:
${ScreenUtil.getInstance().scaleHeight * ScreenUtil.pixelRatio}
'
);
return
new
Scaffold
(
appBar:
new
AppBar
(
title:
new
Text
(
widget
.
title
),
...
...
@@ -84,6 +85,8 @@ class _MyHomePageState extends State<MyHomePage> {
),
Text
(
'Device width:
${ScreenUtil.screenWidth}
px'
),
Text
(
'Device height:
${ScreenUtil.screenHeight}
px'
),
Text
(
'Device width:
${ScreenUtil.screenWidthDp}
dp'
),
Text
(
'Device height:
${ScreenUtil.screenHeightDp}
dp'
),
Text
(
'Device pixel density:
${ScreenUtil.pixelRatio}
'
),
Text
(
'Bottom safe zone distance:
${ScreenUtil.bottomBarHeight}
px'
),
Text
(
'Status bar height:
${ScreenUtil.statusBarHeight}
px'
),
...
...
@@ -95,14 +98,6 @@ class _MyHomePageState extends State<MyHomePage> {
'Ratio of actual height dp to design draft px:
${ScreenUtil.getInstance().scaleHeight}
'
,
textAlign:
TextAlign
.
center
,
),
Text
(
'The ratio of font and width to the size of the design:
${ScreenUtil.getInstance().scaleWidth * ScreenUtil.pixelRatio}
'
,
textAlign:
TextAlign
.
center
,
),
Text
(
'The ratio of height width to the size of the design:
${ScreenUtil.getInstance().scaleHeight * ScreenUtil.pixelRatio}
'
,
textAlign:
TextAlign
.
center
,
),
SizedBox
(
height:
ScreenUtil
.
getInstance
().
setHeight
(
100
),
),
...
...
example/lib/main_zh.dart
View file @
3ec7413
...
...
@@ -45,12 +45,13 @@ class _MyHomePageState extends State<MyHomePage> {
print
(
'宽度和字体相对于设计稿放大的比例:
${ScreenUtil.getInstance().scaleWidth * ScreenUtil.pixelRatio}
'
);
print
(
'高度相对于设计稿放大的比例:
${ScreenUtil.getInstance().scaleHeight * ScreenUtil.pixelRatio}
'
);
print
(
'高度相对于设计稿放大的比例:
${ScreenUtil.getInstance().scaleHeight * ScreenUtil.pixelRatio}
'
);
print
(
'系统的字体缩放比例:
${ScreenUtil.textScaleFactory}
'
);
return
new
Scaffold
(
appBar:
new
AppBar
(
title:
new
Text
(
widget
.
title
),
return
Scaffold
(
appBar:
AppBar
(
title:
Text
(
widget
.
title
),
),
floatingActionButton:
FloatingActionButton
(
onPressed:
()
{
...
...
@@ -82,35 +83,31 @@ class _MyHomePageState extends State<MyHomePage> {
width:
ScreenUtil
.
getInstance
().
setWidth
(
375
),
height:
ScreenUtil
.
getInstance
().
setHeight
(
200
),
color:
Colors
.
blue
,
child:
Text
(
'我的宽度:
${ScreenUtil.getInstance().setWidth(375)}
dp'
,
style:
TextStyle
(
color:
Colors
.
white
,
fontSize:
ScreenUtil
.
getInstance
().
setSp
(
24
),
)),
child:
Text
(
'我的宽度:
${ScreenUtil.getInstance().setWidth(375)}
dp'
,
style:
TextStyle
(
color:
Colors
.
white
,
fontSize:
ScreenUtil
.
getInstance
().
setSp
(
24
),
)),
),
],
),
Text
(
'设备宽度:
${ScreenUtil.screenWidth}
px'
),
Text
(
'设备高度:
${ScreenUtil.screenHeight}
px'
),
Text
(
'设备宽度:
${ScreenUtil.screenWidthDp}
dp'
),
Text
(
'设备高度:
${ScreenUtil.screenHeightDp}
dp'
),
Text
(
'设计稿宽度:
${ScreenUtil.getInstance().width}
'
),
Text
(
'设备的像素密度:
${ScreenUtil.pixelRatio}
'
),
Text
(
'底部安全区距离:
${ScreenUtil.bottomBarHeight}
px'
),
Text
(
'状态栏高度:
${ScreenUtil.statusBarHeight}
px'
),
Text
(
'实际
高度的dp与设计稿px的比例:
${ScreenUtil.getInstance().scaleHeight
}
'
,
'实际
宽度的dp与设计稿px的比例:
${ScreenUtil.getInstance().scaleWidth
}
'
,
textAlign:
TextAlign
.
center
,
),
Text
(
'实际高度的dp与设计稿px的比例:
${ScreenUtil.getInstance().scaleHeight}
'
,
textAlign:
TextAlign
.
center
,
),
Text
(
'宽度和字体相对于设计稿放大的比例:
${ScreenUtil.getInstance().scaleWidth * ScreenUtil.pixelRatio}
'
,
textAlign:
TextAlign
.
center
,
),
Text
(
'高度相对于设计稿放大的比例:
${ScreenUtil.getInstance().scaleHeight * ScreenUtil.pixelRatio}
'
,
textAlign:
TextAlign
.
center
,
),
SizedBox
(
height:
ScreenUtil
.
getInstance
().
setHeight
(
100
),
),
...
...
@@ -118,10 +115,11 @@ class _MyHomePageState extends State<MyHomePage> {
Column
(
crossAxisAlignment:
CrossAxisAlignment
.
start
,
children:
<
Widget
>[
Text
(
'我的文字大小在设计稿上是2
5
px,不会随着系统的文字缩放比例变化'
,
Text
(
'我的文字大小在设计稿上是2
4
px,不会随着系统的文字缩放比例变化'
,
style:
TextStyle
(
color:
Colors
.
black
,
fontSize:
ScreenUtil
.
getInstance
().
setSp
(
24
))),
Text
(
'我的文字大小在设计稿上是25px,会随着系统的文字缩放比例变化'
,
color:
Colors
.
black
,
fontSize:
ScreenUtil
.
getInstance
().
setSp
(
24
))),
Text
(
'我的文字大小在设计稿上是24px,会随着系统的文字缩放比例变化'
,
style:
TextStyle
(
color:
Colors
.
black
,
fontSize:
...
...
example/pubspec.lock
View file @
3ec7413
...
...
@@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.
0.8
"
version: "2.
1.0
"
boolean_selector:
dependency: transitive
description:
...
...
@@ -47,7 +47,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.5.
1
"
version: "0.5.
2
"
flutter_test:
dependency: "direct dev"
description: flutter
...
...
@@ -59,7 +59,7 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.
3+1
"
version: "0.12.
5
"
meta:
dependency: transitive
description:
...
...
@@ -87,7 +87,7 @@ packages:
name: quiver
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.
1
"
version: "2.0.
2
"
sky_engine:
dependency: transitive
description: flutter
...
...
@@ -113,7 +113,7 @@ packages:
name: stream_channel
url: "https://pub.dartlang.org"
source: hosted
version: "
1.6.8
"
version: "
2.0.0
"
string_scanner:
dependency: transitive
description:
...
...
@@ -134,7 +134,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.
2
"
version: "0.2.
4
"
typed_data:
dependency: transitive
description:
...
...
@@ -150,4 +150,4 @@ packages:
source: hosted
version: "2.0.8"
sdks:
dart: ">=2.
1.1-dev.0
.0 <3.0.0"
dart: ">=2.
2
.0 <3.0.0"
...
...
pubspec.lock
View file @
3ec7413
...
...
@@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.
0.8
"
version: "2.
1.0
"
boolean_selector:
dependency: transitive
description:
...
...
@@ -45,7 +45,7 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.
3+1
"
version: "0.12.
5
"
meta:
dependency: transitive
description:
...
...
@@ -60,13 +60,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.2"
pedantic:
dependency: transitive
description:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.5.0"
quiver:
dependency: transitive
description:
name: quiver
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.
1
"
version: "2.0.
2
"
sky_engine:
dependency: transitive
description: flutter
...
...
@@ -78,7 +85,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.
4.1
"
version: "1.
5.5
"
stack_trace:
dependency: transitive
description:
...
...
@@ -92,7 +99,7 @@ packages:
name: stream_channel
url: "https://pub.dartlang.org"
source: hosted
version: "
1.6.8
"
version: "
2.0.0
"
string_scanner:
dependency: transitive
description:
...
...
@@ -106,14 +113,14 @@ packages:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.
0.1
"
version: "1.
1.0
"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.
1
"
version: "0.2.
4
"
typed_data:
dependency: transitive
description:
...
...
@@ -129,4 +136,4 @@ packages:
source: hosted
version: "2.0.8"
sdks:
dart: ">=2.
0
.0 <3.0.0"
dart: ">=2.
2
.0 <3.0.0"
...
...
Please
register
or
login
to post a comment