Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
__卓原
flutter_screenutil
提交
eb6f7404
F
flutter_screenutil
项目概览
__卓原
/
flutter_screenutil
通知
10
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
3
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
flutter_screenutil
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
3
Issue
3
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
eb6f7404
编写于
9月 29, 2018
作者:
李
李卓原
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修改release无效的bug
上级
7f76f59a
变更
9
展开全部
隐藏空白更改
内联
并排
Showing
9 changed file
with
786 addition
and
623 deletion
+786
-623
.idea/libraries/Dart_Packages.xml
.idea/libraries/Dart_Packages.xml
+10
-107
.idea/workspace.xml
.idea/workspace.xml
+265
-34
.packages
.packages
+55
-55
README.md
README.md
+16
-7
example/lib/main.dart
example/lib/main.dart
+7
-10
example/pubspec.lock
example/pubspec.lock
+8
-1
example/pubspec.yaml
example/pubspec.yaml
+1
-0
lib/flutter_screenutil.dart
lib/flutter_screenutil.dart
+47
-32
pubspec.lock
pubspec.lock
+377
-377
未找到文件。
.idea/libraries/Dart_Packages.xml
浏览文件 @
eb6f7404
此差异已折叠。
点击以展开。
.idea/workspace.xml
浏览文件 @
eb6f7404
此差异已折叠。
点击以展开。
.packages
浏览文件 @
eb6f7404
# Generated by pub on 2018-09-2
1 00:18:30.0756
89.
analyzer:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/analyzer-0.32.4/lib/
args:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/args-1.5.0/lib/
async:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/async-2.0.8/lib/
boolean_selector:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/boolean_selector-1.0.4/lib/
charcode:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/charcode-1.1.2/lib/
collection:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/collection-1.14.11/lib/
convert:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/convert-2.0.2/lib/
crypto:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/crypto-2.0.6/lib/
csslib:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/csslib-0.14.5/lib/
flutter:file:///
d
:/flutter/packages/flutter/lib/
flutter_test:file:///
d
:/flutter/packages/flutter_test/lib/
front_end:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/front_end-0.1.4/lib/
glob:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/glob-1.1.7/lib/
html:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/html-0.13.3+3/lib/
http:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/http-0.11.3+17/lib/
http_multi_server:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/http_multi_server-2.0.5/lib/
http_parser:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/http_parser-3.1.3/lib/
io:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/io-0.3.3/lib/
js:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/js-0.6.1+1/lib/
json_rpc_2:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/json_rpc_2-2.0.9/lib/
kernel:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/kernel-0.3.4/lib/
logging:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/logging-0.11.3+2/lib/
matcher:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/matcher-0.12.3+1/lib/
meta:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/meta-1.1.6/lib/
mime:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/mime-0.9.6+2/lib/
multi_server_socket:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/multi_server_socket-1.0.2/lib/
node_preamble:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/node_preamble-1.4.4/lib/
package_config:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/package_config-1.0.5/lib/
package_resolver:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/package_resolver-1.0.4/lib/
path:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/path-1.6.2/lib/
plugin:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/plugin-0.2.0+3/lib/
pool:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/pool-1.3.6/lib/
pub_semver:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/pub_semver-1.4.2/lib/
quiver:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/quiver-2.0.0+1/lib/
shelf:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/shelf-0.7.3+3/lib/
shelf_packages_handler:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/shelf_packages_handler-1.0.4/lib/
shelf_static:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/shelf_static-0.2.8/lib/
shelf_web_socket:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/shelf_web_socket-0.2.2+4/lib/
sky_engine:file:///
d
:/flutter/bin/cache/pkg/sky_engine/lib/
source_map_stack_trace:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/source_map_stack_trace-1.1.5/lib/
source_maps:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/source_maps-0.10.7/lib/
source_span:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/source_span-1.4.1/lib/
stack_trace:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/stack_trace-1.9.3/lib/
stream_channel:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/stream_channel-1.6.8/lib/
string_scanner:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/string_scanner-1.0.4/lib/
term_glyph:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/term_glyph-1.0.1/lib/
test:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/test-1.3.0/lib/
typed_data:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/typed_data-1.1.6/lib/
utf:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/utf-0.9.0+5/lib/
vector_math:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/vector_math-2.0.8/lib/
vm_service_client:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/vm_service_client-0.2.6/lib/
watcher:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/watcher-0.9.7+10/lib/
web_socket_channel:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/web_socket_channel-1.0.9/lib/
yaml:file:///
d:/flutter/.pub-c
ache/hosted/pub.flutter-io.cn/yaml-2.1.15/lib/
# Generated by pub on 2018-09-2
9 11:16:33.4327
89.
analyzer:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/analyzer-0.32.4/lib/
args:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/args-1.5.0/lib/
async:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/async-2.0.8/lib/
boolean_selector:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/boolean_selector-1.0.4/lib/
charcode:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/charcode-1.1.2/lib/
collection:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/collection-1.14.11/lib/
convert:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/convert-2.0.2/lib/
crypto:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/crypto-2.0.6/lib/
csslib:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/csslib-0.14.5/lib/
flutter:file:///
D
:/flutter/packages/flutter/lib/
flutter_test:file:///
D
:/flutter/packages/flutter_test/lib/
front_end:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/front_end-0.1.4/lib/
glob:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/glob-1.1.7/lib/
html:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/html-0.13.3+3/lib/
http:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/http-0.11.3+17/lib/
http_multi_server:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/http_multi_server-2.0.5/lib/
http_parser:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/http_parser-3.1.3/lib/
io:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/io-0.3.3/lib/
js:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/js-0.6.1+1/lib/
json_rpc_2:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/json_rpc_2-2.0.9/lib/
kernel:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/kernel-0.3.4/lib/
logging:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/logging-0.11.3+2/lib/
matcher:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/matcher-0.12.3+1/lib/
meta:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/meta-1.1.6/lib/
mime:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/mime-0.9.6+2/lib/
multi_server_socket:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/multi_server_socket-1.0.2/lib/
node_preamble:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/node_preamble-1.4.4/lib/
package_config:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/package_config-1.0.5/lib/
package_resolver:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/package_resolver-1.0.4/lib/
path:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/path-1.6.2/lib/
plugin:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/plugin-0.2.0+3/lib/
pool:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/pool-1.3.6/lib/
pub_semver:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/pub_semver-1.4.2/lib/
quiver:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/quiver-2.0.0+1/lib/
shelf:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/shelf-0.7.3+3/lib/
shelf_packages_handler:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/shelf_packages_handler-1.0.4/lib/
shelf_static:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/shelf_static-0.2.8/lib/
shelf_web_socket:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/shelf_web_socket-0.2.2+4/lib/
sky_engine:file:///
D
:/flutter/bin/cache/pkg/sky_engine/lib/
source_map_stack_trace:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/source_map_stack_trace-1.1.5/lib/
source_maps:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/source_maps-0.10.7/lib/
source_span:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/source_span-1.4.1/lib/
stack_trace:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/stack_trace-1.9.3/lib/
stream_channel:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/stream_channel-1.6.8/lib/
string_scanner:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/string_scanner-1.0.4/lib/
term_glyph:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/term_glyph-1.0.1/lib/
test:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/test-1.3.0/lib/
typed_data:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/typed_data-1.1.6/lib/
utf:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/utf-0.9.0+5/lib/
vector_math:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/vector_math-2.0.8/lib/
vm_service_client:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/vm_service_client-0.2.6/lib/
watcher:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/watcher-0.9.7+10/lib/
web_socket_channel:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/web_socket_channel-1.0.9/lib/
yaml:file:///
C:/Users/Frank/AppData/Roaming/Pub/C
ache/hosted/pub.flutter-io.cn/yaml-2.1.15/lib/
flutter_screenutil:lib/
README.md
浏览文件 @
eb6f7404
...
...
@@ -28,10 +28,11 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
### 初始化设置尺寸
在使用之前请设置好设计稿的宽度和高度,传入设计稿的宽度和高度(单位px)
如果不设置则使用默认尺寸,默认为1080
*
1920
推荐在项目入口中
设置,以保证在每次使用之前设置好了适配尺寸:
一定在MaterialApp的home中的页面
设置,以保证在每次使用之前设置好了适配尺寸:
```
ScreenUtil.instance = new ScreenUtil(width: 360, height: 720);
//设置适配尺寸 (填入设计稿中设备的屏幕尺寸) 假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334)
ScreenUtil.instance = ScreenUtil(width: 750, height: 1334)..init(context);
```
### 使用:
...
...
@@ -57,13 +58,23 @@ height: ScreenUtil().setHeight(200),
```
```
import 'package:flutter_app/ScreenUtil.dart'; //导入
//导入
import 'package:flutter_screenutil/flutter_screenutil.dart';
...
@override
@override
Widget build(BuildContext context) {
//设置适配尺寸 (填入设计稿中设备的屏幕尺寸) 假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334)
ScreenUtil.instance = ScreenUtil(width: 750, height: 1334)..init(context);
print('设备宽度:${ScreenUtil.screenWidth}'); //设备宽度
print('设备高度:${ScreenUtil.screenHeight}'); //设备高度
print('设备的像素密度:${ScreenUtil.pixelRatio}'); //设备的像素密度
print('底部安全区距离:${ScreenUtil.bottomBarHeight}'); //底部安全区距离,适用于全面屏下面有按键的
print('状态栏高度:${ScreenUtil.statusBarHeight}px'); //状态栏高度 刘海屏会更高
print('宽度相对于设计稿放大的倍数:${ScreenUtil().scaleWidth}'); //宽度相对于设计稿放大的倍数
print('高度相对于设计稿放大的倍数:${ScreenUtil().scaleHeight}'); //高度相对于设计稿放大的倍数
return new Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
...
...
@@ -96,8 +107,6 @@ import 'package:flutter_app/ScreenUtil.dart'; //导入
Text('设备的像素密度:${ScreenUtil.pixelRatio}'),
Text('底部安全区距离:${ScreenUtil.bottomBarHeight}px'),
Text('状态栏高度:${ScreenUtil.statusBarHeight}px'),
Text('宽度相对于设计稿放大的倍数:${ScreenUtil().scaleWidth}'),
Text('高度相对于设计稿放大的倍数:${ScreenUtil().scaleHeight}'),
],
),
),
...
...
example/lib/main.dart
浏览文件 @
eb6f7404
...
...
@@ -7,9 +7,6 @@ class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget
build
(
BuildContext
context
)
{
//假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334)
ScreenUtil
.
instance
=
new
ScreenUtil
(
width:
750
,
height:
1334
);
return
new
MaterialApp
(
title:
'Flutter Demo'
,
theme:
new
ThemeData
(
...
...
@@ -34,18 +31,20 @@ class _MyHomePageState extends State<MyHomePage> {
void
initState
()
{
// TODO: implement initState
super
.
initState
();
print
(
'设备的像素密度:
${ScreenUtil.pixelRatio}
'
);
//设备的像素密度
}
@override
Widget
build
(
BuildContext
context
)
{
//设置适配尺寸 (填入设计稿中设备的屏幕尺寸) 假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334)
ScreenUtil
.
instance
=
ScreenUtil
(
width:
750
,
height:
1334
)..
init
(
context
);
print
(
'设备宽度:
${ScreenUtil.screenWidth}
'
);
//设备宽度
print
(
'设备高度:
${ScreenUtil.screenHeight}
'
);
//设备高度
print
(
'设备的像素密度:
${ScreenUtil.pixelRatio}
'
);
//设备的像素密度
print
(
'底部安全区距离:
${ScreenUtil.bottomBarHeight}
'
);
//底部安全区距离,适用于全面屏下面有按键的
print
(
'状态栏高度:
${ScreenUtil.statusBarHeight}
px'
);
//状态栏高度 刘海屏会更高
print
(
'宽度相对于设计稿放大的倍数:
${ScreenUtil().scaleWidth}
'
);
//宽度相对于设计稿放大的倍数
print
(
'高度相对于设计稿放大的倍数:
${ScreenUtil().scaleHeight}
'
);
//高度相对于设计稿放大的倍数
}
@override
Widget
build
(
BuildContext
context
)
{
return
new
Scaffold
(
appBar:
new
AppBar
(
title:
new
Text
(
widget
.
title
),
...
...
@@ -78,8 +77,6 @@ class _MyHomePageState extends State<MyHomePage> {
Text
(
'设备的像素密度:
${ScreenUtil.pixelRatio}
'
),
Text
(
'底部安全区距离:
${ScreenUtil.bottomBarHeight}
px'
),
Text
(
'状态栏高度:
${ScreenUtil.statusBarHeight}
px'
),
Text
(
'宽度相对于设计稿放大的倍数:
${ScreenUtil().scaleWidth}
'
),
Text
(
'高度相对于设计稿放大的倍数:
${ScreenUtil().scaleHeight}
'
),
],
),
),
...
...
example/pubspec.lock
浏览文件 @
eb6f7404
...
...
@@ -43,6 +43,13 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.14.11"
common_utils:
dependency: "direct main"
description:
name: common_utils
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.2"
convert:
dependency: transitive
description:
...
...
@@ -81,7 +88,7 @@ packages:
description:
path: "."
ref: HEAD
resolved-ref: "
94af1bacf4c9f89461a592b26fac8eceb1df3343
"
resolved-ref: "
62d8b7d3a3cc4323eca1682166d7aee2890b1468
"
url: "git://github.com/lizhuoyuan/flutter_screenUtil"
source: git
version: "0.1.0"
...
...
example/pubspec.yaml
浏览文件 @
eb6f7404
...
...
@@ -22,6 +22,7 @@ dependencies:
flutter_screenutil
:
git
:
url
:
git://github.com/lizhuoyuan/flutter_screenUtil
common_utils
:
^1.0.2
dev_dependencies
:
flutter_test
:
sdk
:
flutter
...
...
lib/flutter_screenutil.dart
浏览文件 @
eb6f7404
/*
* Created by 李卓原 on 2018/9/2
0
.
* Created by 李卓原 on 2018/9/2
9
.
* email: zhuoyuan93@gmail.com
* 设计稿设备尺寸默认为 1080 * 1920 px
*/
import
'
dart:ui
'
;
import
'
package:flutter/material.dart
'
;
class
ScreenUtil
{
//请修改成你的设计稿的尺寸
static
ScreenUtil
instance
=
new
ScreenUtil
(
width:
1080
,
height:
1920
);
static
ScreenUtil
instance
=
new
ScreenUtil
();
//设计稿的设备尺寸修改
int
designWidth
;
int
designHeight
;
int
_designWidth
;
int
_designHeight
;
static
MediaQueryData
_mediaQueryData
;
static
double
_screenWidth
;
static
double
_screenHeight
;
static
double
_pixelRatio
;
static
double
_statusBarHeight
;
static
double
_bottomBarHeight
;
ScreenUtil
({
int
width
,
int
height
})
{
designWidth
=
width
;
designHeight
=
height
;
_
designWidth
=
width
;
_
designHeight
=
height
;
}
static
ScreenUtil
getInstance
()
{
return
instance
;
}
//设备的像素密度
static
double
pixelRatio
=
window
.
devicePixelRatio
;
void
init
(
BuildContext
context
)
{
MediaQueryData
mediaQuery
=
MediaQuery
.
of
(
context
);
_mediaQueryData
=
mediaQuery
;
_pixelRatio
=
mediaQuery
.
devicePixelRatio
;
_screenWidth
=
mediaQuery
.
size
.
width
;
_screenHeight
=
mediaQuery
.
size
.
height
;
_statusBarHeight
=
mediaQuery
.
padding
.
top
;
_bottomBarHeight
=
_mediaQueryData
.
padding
.
bottom
;
}
static
MediaQueryData
get
mediaQueryData
=>
_mediaQueryData
;
///设备的像素密度
static
double
get
pixelRatio
=>
_pixelRatio
;
//当前设备宽度 px
static
double
screenWidth
=
window
.
physicalSize
.
width
;
//
/
当前设备宽度 px
static
double
get
screenWidth
=>
_screenWidth
*
_pixelRatio
;
//当前设备高度 px
static
double
screenHeight
=
window
.
physicalSize
.
height
;
//
/
当前设备高度 px
static
double
get
screenHeight
=>
_screenHeight
*
_pixelRatio
;
//状态栏高度 刘海屏会更高
static
double
statusBarHeight
=
window
.
padding
.
top
;
//
/
状态栏高度 刘海屏会更高
static
double
get
statusBarHeight
=>
_statusBarHeight
*
_pixelRatio
;
//底部安全区距离
static
double
bottomBarHeight
=
window
.
padding
.
bottom
;
//
/
底部安全区距离
static
double
get
bottomBarHeight
=>
_bottomBarHeight
*
_pixelRatio
;
//相对于设计稿放大的倍数
double
get
scaleWidth
=>
screenWidth
/
instance
.
designWidth
/
pixelRatio
;
//
/
相对于设计稿放大的倍数
get
scaleWidth
=>
_screenWidth
/
instance
.
_designWidth
;
double
get
scaleHeight
=>
screenHeight
/
instance
.
designHeight
/
pixelRatio
;
get
scaleHeight
=>
_screenHeight
/
instance
.
_designHeight
;
/**
* 根据设计稿的设备宽度适配
* 高度也根据这个来做适配可以保证不变形
*/
///根据设计稿的设备宽度适配
///高度也根据这个来做适配可以保证不变形
setWidth
(
int
width
)
=>
width
*
scaleWidth
;
/**
* 根据设计稿的设备高度适配
* 当发现设计稿中的一屏显示的与当前样式效果不符合时,
* 或者形状有差异时,高度适配建议使用此方法
* 高度适配主要针对想根据设计稿的一屏展示一样的效果
*/
/// 根据设计稿的设备高度适配
/// 当发现设计稿中的一屏显示的与当前样式效果不符合时,
/// 或者形状有差异时,高度适配建议使用此方法
/// 高度适配主要针对想根据设计稿的一屏展示一样的效果
setHeight
(
int
height
)
=>
height
*
scaleHeight
;
}
pubspec.lock
浏览文件 @
eb6f7404
# Generated by pub
# See https://www.dartlang.org/tools/pub/glossary#lockfile
packages:
analyzer:
dependency: transitive
description:
name: analyzer
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.32.4"
args:
dependency: transitive
description:
name: args
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.5.0"
async:
dependency: transitive
description:
name: async
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.8"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.4"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.2"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.14.11"
convert:
dependency: transitive
description:
name: convert
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.2"
crypto:
dependency: transitive
description:
name: crypto
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.6"
csslib:
dependency: transitive
description:
name: csslib
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.14.5"
flutter:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
flutter_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
front_end:
dependency: transitive
description:
name: front_end
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.1.4"
glob:
dependency: transitive
description:
name: glob
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.7"
html:
dependency: transitive
description:
name: html
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.13.3+3"
http:
dependency: transitive
description:
name: http
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.11.3+17"
http_multi_server:
dependency: transitive
description:
name: http_multi_server
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.5"
http_parser:
dependency: transitive
description:
name: http_parser
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.1.3"
io:
dependency: transitive
description:
name: io
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.3.3"
js:
dependency: transitive
description:
name: js
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.6.1+1"
json_rpc_2:
dependency: transitive
description:
name: json_rpc_2
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.9"
kernel:
dependency: transitive
description:
name: kernel
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.3.4"
logging:
dependency: transitive
description:
name: logging
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.11.3+2"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.12.3+1"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.6"
mime:
dependency: transitive
description:
name: mime
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.9.6+2"
multi_server_socket:
dependency: transitive
description:
name: multi_server_socket
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.2"
node_preamble:
dependency: transitive
description:
name: node_preamble
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.4.4"
package_config:
dependency: transitive
description:
name: package_config
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.5"
package_resolver:
dependency: transitive
description:
name: package_resolver
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.4"
path:
dependency: transitive
description:
name: path
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.6.2"
plugin:
dependency: transitive
description:
name: plugin
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.2.0+3"
pool:
dependency: transitive
description:
name: pool
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.6"
pub_semver:
dependency: transitive
description:
name: pub_semver
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.4.2"
quiver:
dependency: transitive
description:
name: quiver
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.0+1"
shelf:
dependency: transitive
description:
name: shelf
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.7.3+3"
shelf_packages_handler:
dependency: transitive
description:
name: shelf_packages_handler
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.4"
shelf_static:
dependency: transitive
description:
name: shelf_static
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.2.8"
shelf_web_socket:
dependency: transitive
description:
name: shelf_web_socket
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.2.2+4"
sky_engine:
dependency: transitive
description: flutter
source: sdk
version: "0.0.99"
source_map_stack_trace:
dependency: transitive
description:
name: source_map_stack_trace
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.5"
source_maps:
dependency: transitive
description:
name: source_maps
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.10.7"
source_span:
dependency: transitive
description:
name: source_span
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.4.1"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.9.3"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.6.8"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.4"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.1"
test:
dependency: transitive
description:
name: test
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.0"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.6"
utf:
dependency: transitive
description:
name: utf
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.9.0+5"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.8"
vm_service_client:
dependency: transitive
description:
name: vm_service_client
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.2.6"
watcher:
dependency: transitive
description:
name: watcher
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.9.7+10"
web_socket_channel:
dependency: transitive
description:
name: web_socket_channel
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.9"
yaml:
dependency: transitive
description:
name: yaml
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.15"
sdks:
dart: ">=2.0.0-dev.68.0 <3.0.0"
# Generated by pub
# See https://www.dartlang.org/tools/pub/glossary#lockfile
packages:
analyzer:
dependency: transitive
description:
name: analyzer
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.32.4"
args:
dependency: transitive
description:
name: args
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.5.0"
async:
dependency: transitive
description:
name: async
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.8"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.4"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.2"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.14.11"
convert:
dependency: transitive
description:
name: convert
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.2"
crypto:
dependency: transitive
description:
name: crypto
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.6"
csslib:
dependency: transitive
description:
name: csslib
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.14.5"
flutter:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
flutter_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
front_end:
dependency: transitive
description:
name: front_end
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.1.4"
glob:
dependency: transitive
description:
name: glob
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.7"
html:
dependency: transitive
description:
name: html
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.13.3+3"
http:
dependency: transitive
description:
name: http
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.11.3+17"
http_multi_server:
dependency: transitive
description:
name: http_multi_server
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.5"
http_parser:
dependency: transitive
description:
name: http_parser
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.1.3"
io:
dependency: transitive
description:
name: io
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.3.3"
js:
dependency: transitive
description:
name: js
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.6.1+1"
json_rpc_2:
dependency: transitive
description:
name: json_rpc_2
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.9"
kernel:
dependency: transitive
description:
name: kernel
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.3.4"
logging:
dependency: transitive
description:
name: logging
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.11.3+2"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.12.3+1"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.6"
mime:
dependency: transitive
description:
name: mime
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.9.6+2"
multi_server_socket:
dependency: transitive
description:
name: multi_server_socket
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.2"
node_preamble:
dependency: transitive
description:
name: node_preamble
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.4.4"
package_config:
dependency: transitive
description:
name: package_config
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.5"
package_resolver:
dependency: transitive
description:
name: package_resolver
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.4"
path:
dependency: transitive
description:
name: path
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.6.2"
plugin:
dependency: transitive
description:
name: plugin
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.2.0+3"
pool:
dependency: transitive
description:
name: pool
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.6"
pub_semver:
dependency: transitive
description:
name: pub_semver
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.4.2"
quiver:
dependency: transitive
description:
name: quiver
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.0+1"
shelf:
dependency: transitive
description:
name: shelf
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.7.3+3"
shelf_packages_handler:
dependency: transitive
description:
name: shelf_packages_handler
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.4"
shelf_static:
dependency: transitive
description:
name: shelf_static
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.2.8"
shelf_web_socket:
dependency: transitive
description:
name: shelf_web_socket
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.2.2+4"
sky_engine:
dependency: transitive
description: flutter
source: sdk
version: "0.0.99"
source_map_stack_trace:
dependency: transitive
description:
name: source_map_stack_trace
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.5"
source_maps:
dependency: transitive
description:
name: source_maps
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.10.7"
source_span:
dependency: transitive
description:
name: source_span
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.4.1"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.9.3"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.6.8"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.4"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.1"
test:
dependency: transitive
description:
name: test
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.0"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.6"
utf:
dependency: transitive
description:
name: utf
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.9.0+5"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.8"
vm_service_client:
dependency: transitive
description:
name: vm_service_client
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.2.6"
watcher:
dependency: transitive
description:
name: watcher
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.9.7+10"
web_socket_channel:
dependency: transitive
description:
name: web_socket_channel
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.9"
yaml:
dependency: transitive
description:
name: yaml
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.15"
sdks:
dart: ">=2.0.0-dev.68.0 <3.0.0"
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录