Skip to content

Commit

Permalink
merge 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lizhuoyuan authored Sep 23, 2018
1 parent 5742507 commit 9c471c3
Show file tree
Hide file tree
Showing 9 changed files with 781 additions and 92 deletions.
23 changes: 10 additions & 13 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# See https://www.dartlang.org/guides/libraries/private-files

# Files and directories created by pub
.dart_tool/
.packages
.pub/
build/
# If you're building an application, you may want to check-in your pubspec.lock
pubspec.lock

# Directory created by dartdoc
# If you don't generate documentation locally you can remove this line.
doc/api/
.DS_Store
.dart_tool/

.packages
.pub/

build/
ios/.generated/
ios/Flutter/Generated.xcconfig
ios/Runner/GeneratedPluginRegistrant.*
56 changes: 56 additions & 0 deletions .packages
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Generated by pub on 2018-09-21 00:18:30.075689.
analyzer:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/analyzer-0.32.4/lib/
args:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/args-1.5.0/lib/
async:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/async-2.0.8/lib/
boolean_selector:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/boolean_selector-1.0.4/lib/
charcode:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/charcode-1.1.2/lib/
collection:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/collection-1.14.11/lib/
convert:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/convert-2.0.2/lib/
crypto:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/crypto-2.0.6/lib/
csslib:file:///d:/flutter/.pub-cache/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-cache/hosted/pub.flutter-io.cn/front_end-0.1.4/lib/
glob:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/glob-1.1.7/lib/
html:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/html-0.13.3+3/lib/
http:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/http-0.11.3+17/lib/
http_multi_server:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/http_multi_server-2.0.5/lib/
http_parser:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/http_parser-3.1.3/lib/
io:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/io-0.3.3/lib/
js:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/js-0.6.1+1/lib/
json_rpc_2:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/json_rpc_2-2.0.9/lib/
kernel:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/kernel-0.3.4/lib/
logging:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/logging-0.11.3+2/lib/
matcher:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/matcher-0.12.3+1/lib/
meta:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/meta-1.1.6/lib/
mime:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/mime-0.9.6+2/lib/
multi_server_socket:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/multi_server_socket-1.0.2/lib/
node_preamble:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/node_preamble-1.4.4/lib/
package_config:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/package_config-1.0.5/lib/
package_resolver:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/package_resolver-1.0.4/lib/
path:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/path-1.6.2/lib/
plugin:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/plugin-0.2.0+3/lib/
pool:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/pool-1.3.6/lib/
pub_semver:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/pub_semver-1.4.2/lib/
quiver:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/quiver-2.0.0+1/lib/
shelf:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/shelf-0.7.3+3/lib/
shelf_packages_handler:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/shelf_packages_handler-1.0.4/lib/
shelf_static:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/shelf_static-0.2.8/lib/
shelf_web_socket:file:///d:/flutter/.pub-cache/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-cache/hosted/pub.flutter-io.cn/source_map_stack_trace-1.1.5/lib/
source_maps:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/source_maps-0.10.7/lib/
source_span:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/source_span-1.4.1/lib/
stack_trace:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/stack_trace-1.9.3/lib/
stream_channel:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/stream_channel-1.6.8/lib/
string_scanner:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/string_scanner-1.0.4/lib/
term_glyph:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/term_glyph-1.0.1/lib/
test:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/test-1.3.0/lib/
typed_data:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/typed_data-1.1.6/lib/
utf:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/utf-0.9.0+5/lib/
vector_math:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/vector_math-2.0.8/lib/
vm_service_client:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/vm_service_client-0.2.6/lib/
watcher:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/watcher-0.9.7+10/lib/
web_socket_channel:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/web_socket_channel-1.0.9/lib/
yaml:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/yaml-2.1.15/lib/
flutter_screenutil:lib/
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## [0.0.1] - TODO: Add release date.

* TODO: Describe initial release.
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO: Add your license here.
185 changes: 106 additions & 79 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,79 +1,106 @@
# flutter_ScreenUtil
flutter 屏幕适配方案


csdn博客本工具介绍:https://blog.csdn.net/u011272795/article/details/82795477

更新日志:

2018/9/23 修改一处拼写错误

# 前言:

现在的手机品牌和型号越来越多,导致我们平时写布局的时候会在个不同的移动设备上显示的效果不同,

比如我们的设计稿一个View的大小是300px,如果直接写300px,可能在当前设备显示正常,但到了其他设备可能就会偏小或者偏大,这就需要我们对屏幕进行适配。

安卓原生的话有自己的适配规则,可以根据不同的尺寸建立不同的文件夹,系统会根据当前的设备尺寸取对应的大小的布局。而flutter本身并没有适配规则,而原生的又比较繁琐,这就需要我们自己去对屏幕进行适配。



使用方法:
```
import 'package:flutter_app/ScreenUtil.dart'; //导入
....
//传入设计稿的px尺寸
width: ScreenUtil().setWidth(540),
height: ScreenUtil().setHeight(200),
```

```
import 'package:flutter_app/ScreenUtil.dart'; //导入
@override
Widget build(BuildContext context) {
print(ScreenUtil.screenWidth); //设备宽度
print(ScreenUtil.screenHeight); //设备高度
print(ScreenUtil.pixelRatio); //设备的像素密度
print(ScreenUtil.StatusBarHeight); //状态栏高度 刘海屏会更高
print(ScreenUtil.BottomBarHeight); //底部安全区距离
return new Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
),
body: Column(
children: <Widget>[
Row(
children: <Widget>[
Container(
width: ScreenUtil().setWidth(540),
height: ScreenUtil().setHeight(200),
color: Colors.red,
child: Text(ScreenUtil().setWidth(540).toString()),
),
Container(
width: ScreenUtil().setWidth(540),
height: ScreenUtil().setHeight(200),
color: Colors.blue,
child: Text(ScreenUtil().setWidth(540).toString()),
),
],
),
Text(ScreenUtil.screenWidth.toString()),
Text(ScreenUtil.screenHeight.toString()),
],
),
);
}
```
效果:
上面的205.xxx 是dp的单位,
下面的单位是px

![效果](微信图片_20180921000611.png)


# flutter_ScreenUtil
flutter 屏幕适配方案

github: https://github.com/lizhuoyuan/flutter_ScreenUtil
csdn博客本工具介绍:https://blog.csdn.net/u011272795/article/details/82795477

# 前言:

现在的手机品牌和型号越来越多,导致我们平时写布局的时候会在个不同的移动设备上显示的效果不同,

比如我们的设计稿一个View的大小是300px,如果直接写300px,可能在当前设备显示正常,但到了其他设备可能就会偏小或者偏大,这就需要我们对屏幕进行适配。

安卓原生的话有自己的适配规则,可以根据不同的尺寸建立不同的文件夹,系统会根据当前的设备尺寸取对应的大小的布局。而flutter本身并没有适配规则,而原生的又比较繁琐,这就需要我们自己去对屏幕进行适配。



使用方法:

```
导入包:
import 'package:flutter_app/ScreenUtil.dart'; //导入
在使用之前请设置好设计稿的宽度和高度,如果不设置则使用默认尺寸
传入设计稿的宽度和高度(单位px),默认为1080*1920
推荐在main.dart中设置,以保证在使用之前设置好了适配尺寸:
ScreenUtil.instance = new ScreenUtil(width: 360, height: 720);
使用:
....
//传入设计稿的px尺寸:
适配尺寸:
width: ScreenUtil().setWidth(540),
height: ScreenUtil().setHeight(200),
其他相关api:
print(ScreenUtil.pixelRatio); //设备的像素密度
print(ScreenUtil.screenWidth); //设备宽度
print(ScreenUtil.screenHeight); //设备高度
print(ScreenUtil.bottomBarHeight); //底部安全区距离,适用于全面屏下面有按键的
print(ScreenUtil.statusBarHeight); //状态栏高度 刘海屏会更高
print(ScreenUtil().scaleWidth); //宽度相对于设计稿放大的倍数
print(ScreenUtil().scaleHeight); //高度相对于设计稿放大的倍数
```

```
import 'package:flutter_app/ScreenUtil.dart'; //导入
@override
Widget build(BuildContext context) {
print(ScreenUtil().setWidth(180));
print(ScreenUtil().setWidth(540));
print(ScreenUtil.screenWidth / ScreenUtil.pixelRatio);
print(ScreenUtil.pixelRatio); //设备的像素密度
print(ScreenUtil.screenWidth); //设备宽度
print(ScreenUtil.screenHeight); //设备高度
print(ScreenUtil.bottomBarHeight); //底部安全区距离,适用于全面屏下面有按键的
print(ScreenUtil.statusBarHeight); //状态栏高度 刘海屏会更高
print(ScreenUtil().scaleWidth); //宽度相对于设计稿放大的倍数
print(ScreenUtil().scaleHeight); //高度相对于设计稿放大的倍数
return new Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
),
body: Column(
children: <Widget>[
Row(
children: <Widget>[
Container(
width: ScreenUtil().setWidth(540),
height: ScreenUtil().setHeight(200),
color: Colors.red,
child: Text(ScreenUtil().setWidth(540).toString()),
),
Container(
width: ScreenUtil().setWidth(540),
height: ScreenUtil().setHeight(200),
color: Colors.blue,
child: Text(ScreenUtil().setWidth(540).toString()),
),
],
),
Text(ScreenUtil.screenWidth.toString()),
Text(ScreenUtil.screenHeight.toString()),
],
),
);
}
```
效果:
上面的205.xxx 是dp的单位,
下面的单位是px

![效果](微信图片_20180921000611.png)

19 changes: 19 additions & 0 deletions flutter_screenutil.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/lib" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/.idea" />
<excludeFolder url="file://$MODULE_DIR$/.pub" />
<excludeFolder url="file://$MODULE_DIR$/build" />
</content>
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart Packages" level="project" />
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Flutter Plugins" level="project" />
</component>
</module>
Loading

0 comments on commit 9c471c3

Please sign in to comment.