Skip to content

Commit

Permalink
1.1.0 新增对num的扩展函数
Browse files Browse the repository at this point in the history
  • Loading branch information
lizhuoyuan committed Mar 17, 2020
1 parent acfc24a commit 0fb6206
Show file tree
Hide file tree
Showing 13 changed files with 275 additions and 172 deletions.
2 changes: 1 addition & 1 deletion .packages
@@ -1,4 +1,4 @@
# Generated by pub on 2020-01-06 17:46:26.285635.
# Generated by pub on 2020-03-17 15:00:35.134973.
archive:file:///D:/flutter/.pub-cache/hosted/pub.dartlang.org/archive-2.0.11/lib/
args:file:///D:/flutter/.pub-cache/hosted/pub.dartlang.org/args-1.5.2/lib/
async:file:///D:/flutter/.pub-cache/hosted/pub.dartlang.org/async-2.4.0/lib/
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,14 @@
* @LastEditTime: 2020年1月14日 12:11:02
* @Description: Update log
-->

#1.1.0
- support ExtensionMethod Dart-SDK-2.6.0
- you can use 'width: 50.w' instead of 'width: ScreenUtil().setWidth(50)'
'50.h' instead of 'ScreenUtil().setHeight(50)'
'24.sp' instead of 'ScreenUtil().setSp(24)'
'24.ssp' instead of 'ScreenUtil().setSp(24, allowFontScalingSelf: true)'

# 1.0.2
- fix #89
- 优化屏幕旋转效果
Expand Down
50 changes: 36 additions & 14 deletions README.md
Expand Up @@ -60,6 +60,25 @@ ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: true);

### Use:

#### API

```dart
ScreenUtil().setWidth(540) (sdk>=2.6 : 540.w) //Adapted to screen width
ScreenUtil().setHeight(200) (sdk>=2.6 : 200.h) //Adapted to screen height
ScreenUtil().setSp(24) (sdk>=2.6 : 24.sp) //Adapter font
ScreenUtil().setSp(24, allowFontScalingSelf: true) (sdk>=2.6 : 24.ssp) //Adapter font(fonts will scale to respect Text Size accessibility settings)
ScreenUtil.pixelRatio //Device pixel density
ScreenUtil.screenWidth //Device width
ScreenUtil.screenHeight //Device height
ScreenUtil.bottomBarHeight //Bottom safe zone distance, suitable for buttons with full screen
ScreenUtil.statusBarHeight //Status bar height , Notch will be higher Unit px
ScreenUtil.textScaleFactor //System font scaling factor
ScreenUtil().scaleWidth //Ratio of actual width dp to design draft px
ScreenUtil().scaleHeight //Ratio of actual height dp to design draft px
```

#### Adapt screen size:

Pass the px size of the design draft:
Expand All @@ -68,6 +87,23 @@ Adapted to screen width: `ScreenUtil().setWidth(540)`,

Adapted to screen height: `ScreenUtil().setHeight(200)`,

If your dart sdk>=2.6, you can use extension functions:

example:
instead of :
```
Container(
width: ScreenUtil().setWidth(50),
height:ScreenUtil().setHeight(200),
)
```
you can use it like this:
```
Container(
width: 50.w,
height:200.h
)
```
**Note**

Height is also adapted according to setWidth to ensure no deformation (when you want a square)
Expand Down Expand Up @@ -122,20 +158,6 @@ Column(
)
```

#### Other related apis:
```dart
ScreenUtil.pixelRatio //Device pixel density
ScreenUtil.screenWidth //Device width
ScreenUtil.screenHeight //Device height
ScreenUtil.bottomBarHeight //Bottom safe zone distance, suitable for buttons with full screen
ScreenUtil.statusBarHeight //Status bar height , Notch will be higher Unit px
ScreenUtil.textScaleFactor //System font scaling factor
ScreenUtil().scaleWidth //Ratio of actual width dp to design draft px
ScreenUtil().scaleHeight //Ratio of actual height dp to design draft px
```

```dart
//import
import 'package:flutter/material.dart';
Expand Down
64 changes: 46 additions & 18 deletions README_CN.md
Expand Up @@ -62,9 +62,29 @@ ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: true);
```

### 使用
### 使用

#### 适配尺寸:
#### API

```dart
ScreenUtil().setWidth(540) (sdk>=2.6 : 540.w) //根据屏幕宽度适配尺寸
ScreenUtil().setHeight(200) (sdk>=2.6 : 200.h) //根据屏幕高度适配尺寸
ScreenUtil().setSp(24) (sdk>=2.6 : 24.sp) //适配字体
ScreenUtil().setSp(24, allowFontScalingSelf: true) (sdk>=2.6 : 24.ssp) //适配字体(根据系统的“字体大小”辅助选项来进行缩放)
ScreenUtil.pixelRatio //设备的像素密度
ScreenUtil.screenWidth //设备宽度
ScreenUtil.screenHeight //设备高度
ScreenUtil.bottomBarHeight //底部安全区距离,适用于全面屏下面有按键的
ScreenUtil.statusBarHeight //状态栏高度 刘海屏会更高 单位px
ScreenUtil.textScaleFactor //系统字体缩放比例
ScreenUtil().scaleWidth // 实际宽度的dp与设计稿px的比例
ScreenUtil().scaleHeight // 实际高度的dp与设计稿px的比例
```


#### 适配尺寸

传入设计稿的px尺寸:

Expand Down Expand Up @@ -94,15 +114,37 @@ Container(
),
```

如果你的dart sdk>=2.6,可以使用扩展函数:
example:
不用这个:
```
Container(
width: ScreenUtil().setWidth(50),
height:ScreenUtil().setHeight(200),
)
```
而是用这个:
```
Container(
width: 50.w,
height:200.h
)
```

#### 适配字体:
传入设计稿的px尺寸:

```
//传入字体大小,默认不根据系统的“字体大小”辅助选项来进行缩放(可在初始化ScreenUtil时设置allowFontScaling)
ScreenUtil().setSp(28)
ScreenUtil().setSp(28)
28.sp (dart sdk>=2.6)
//传入字体大小,根据系统的“字体大小”辅助选项来进行缩放(如果某个地方不遵循全局的allowFontScaling设置)
ScreenUtil().setSp(24, allowFontScalingSelf: true)
ScreenUtil().setSp(24, allowFontScalingSelf: true)
24.ssp (dart sdk>=2.6)
//for example:
Expand All @@ -123,20 +165,6 @@ Column(
)
```

#### 其他相关api:
```
ScreenUtil.pixelRatio //设备的像素密度
ScreenUtil.screenWidth //设备宽度
ScreenUtil.screenHeight //设备高度
ScreenUtil.bottomBarHeight //底部安全区距离,适用于全面屏下面有按键的
ScreenUtil.statusBarHeight //状态栏高度 刘海屏会更高 单位px
ScreenUtil.textScaleFactor //系统字体缩放比例
ScreenUtil().scaleWidth // 实际宽度的dp与设计稿px的比例
ScreenUtil().scaleHeight // 实际高度的dp与设计稿px的比例
```

```dart
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
Expand Down
37 changes: 37 additions & 0 deletions README_PT.md
Expand Up @@ -60,6 +60,25 @@ ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: true);

### Uso:

#### API

```dart
ScreenUtil().setWidth(540) (sdk>=2.6 : 540.w) //Adapted to screen width
ScreenUtil().setHeight(200) (sdk>=2.6 : 200.h) //Adapted to screen height
ScreenUtil().setSp(24) (sdk>=2.6 : 24.sp) //Adapter font
ScreenUtil().setSp(24, allowFontScalingSelf: true) (sdk>=2.6 : 24.ssp) //Adapter font(fonts will scale to respect Text Size accessibility settings)
ScreenUtil.pixelRatio //Device pixel density
ScreenUtil.screenWidth //Device width
ScreenUtil.screenHeight //Device height
ScreenUtil.bottomBarHeight //Bottom safe zone distance, suitable for buttons with full screen
ScreenUtil.statusBarHeight //Status bar height , Notch will be higher Unit px
ScreenUtil.textScaleFactor //System font scaling factor
ScreenUtil().scaleWidth //Ratio of actual width dp to design draft px
ScreenUtil().scaleHeight //Ratio of actual height dp to design draft px
```

#### Adaptar o tamanho da tela:

Informe o tamanho em pixels do protótipo de design:
Expand All @@ -68,6 +87,24 @@ Adaptado à largura da tela: `ScreenUtil().setWidth(540)`,

Adaptado à altura da tela: `ScreenUtil().setHeight(200)`,

If your dart sdk>=2.6, you can use extension functions:

example:
instead of :
```
Container(
width: ScreenUtil().setWidth(50),
height:ScreenUtil().setHeight(200),
)
```
you can use it like this:
```
Container(
width: 50.w,
height:200.h
)
```

**Nota**

Altura também é adaptada de acordo com o setWidth para garantir que não tenha deformação (quando quiser um quadrado)
Expand Down
11 changes: 5 additions & 6 deletions example/lib/main.dart
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

void main() => runApp(MyApp());
Expand Down Expand Up @@ -58,12 +57,12 @@ class _ExampleWidgetState extends State<ExampleWidget> {
children: <Widget>[
Container(
padding: EdgeInsets.all(ScreenUtil().setWidth(10)),
width: ScreenUtil().setWidth(375),
height: ScreenUtil().setHeight(200),
width: 375.w,
height: 200.h,
color: Colors.red,
child: Text(
'My width:${ScreenUtil().setWidth(375)}dp \n'
'My height:${ScreenUtil().setHeight(200)}dp',
'My width:${375.w}dp \n'
'My height:${200.h}dp',
style: TextStyle(
color: Colors.white, fontSize: ScreenUtil().setSp(24)),
),
Expand Down Expand Up @@ -108,7 +107,7 @@ class _ExampleWidgetState extends State<ExampleWidget> {
'My font size is 24px on the design draft and will not change with the system.',
style: TextStyle(
color: Colors.black,
fontSize: ScreenUtil().setSp(24),
fontSize: 24.sp,
)),
Text(
'My font size is 24px on the design draft and will change with the system.',
Expand Down
12 changes: 6 additions & 6 deletions example/lib/main_zh.dart
Expand Up @@ -74,12 +74,12 @@ class _ExampleWidgetState extends State<ExampleWidget> {
),
Container(
padding: EdgeInsets.all(ScreenUtil().setWidth(10)),
width: ScreenUtil().setWidth(375),
height: ScreenUtil().setHeight(200),
width: 375.w,
height: 200.h,
color: Colors.blue,
child: Text(
'我的宽度:${ScreenUtil().setWidth(375)}dp \n'
'我的高度:${ScreenUtil().setHeight(200)}dp',
'我的宽度:${375.w}dp \n'
'我的高度:${200.h}dp',
style: TextStyle(
color: Colors.white,
fontSize: ScreenUtil().setSp(24))),
Expand All @@ -102,7 +102,7 @@ class _ExampleWidgetState extends State<ExampleWidget> {
textAlign: TextAlign.center,
),
SizedBox(
height: ScreenUtil().setHeight(100),
height: 100.h,
),
Text('系统的字体缩放比例:${ScreenUtil.textScaleFactor}'),
Column(
Expand All @@ -111,7 +111,7 @@ class _ExampleWidgetState extends State<ExampleWidget> {
Text('我的文字大小在设计稿上是24px,不会随着系统的文字缩放比例变化',
style: TextStyle(
color: Colors.black,
fontSize: ScreenUtil().setSp(24),
fontSize: 24.sp,
)),
Text('我的文字大小在设计稿上是24px,会随着系统的文字缩放比例变化',
style: TextStyle(
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Expand Up @@ -75,7 +75,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.0.2"
version: "1.1.0"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down

0 comments on commit 0fb6206

Please sign in to comment.