Skip to content

Commit 959f188

Browse files
author
李卓原
committed
4.0.2
close #180
1 parent e4b43ab commit 959f188

File tree

9 files changed

+84
-33
lines changed

9 files changed

+84
-33
lines changed

CHANGELOG.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
<!--
2-
* @Author: [email protected]
3-
* @Date: 2018-10-16 19:43:03
4-
* @LastEditors: [email protected]
5-
* @LastEditTime: 2020年6月20日 11:20:02
6-
* @Description: Update log
7-
-->
1+
# 4.0.2
2+
- add r(),adapt according to the smaller of width or height
83

94
# 4.0.1
105
- Modify the initialization unit to dp

README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ ScreenUtil.init(constraints, designSize: Size(360, 690), allowFontScaling: true)
7979
```dart
8080
ScreenUtil().setWidth(540) (dart sdk>=2.6 : 540.w) //Adapted to screen width
8181
ScreenUtil().setHeight(200) (dart sdk>=2.6 : 200.h) //Adapted to screen height , under normal circumstances, the height still uses x.w
82+
ScreenUtil().radius(200) (dart sdk>=2.6 : 200.r) //Adapt according to the smaller of width or height
8283
ScreenUtil().setSp(24) (dart sdk>=2.6 : 24.sp) //Adapter font
8384
ScreenUtil().setSp(24, allowFontScalingSelf: true) (dart sdk>=2.6 : 24.ssp) //Adapter font(fonts will scale to respect Text Size accessibility settings)
8485
ScreenUtil().setSp(24, allowFontScalingSelf: false) (dart sdk>=2.6 : 24.nsp) //Adapter font(fonts will not scale to respect Text Size accessibility settings)
@@ -129,22 +130,30 @@ The height can also use setWidth to ensure that it is not deformed(when you want
129130

130131
setHeight method is mainly adapted in height, you want to control the height and actuality of a screen on the UIUsed when the same is displayed.
131132

133+
Generally speaking, 50.w!=50.h.
134+
132135
```dart
133136
//for example:
134137
135138
///If you want to display a square:
136-
///rectangle
139+
///The UI may show a rectangle:
137140
Container(
138-
width: ScreenUtil().setWidth(375),
139-
height: ScreenUtil().setWidth(200),
141+
width: 375.w,
142+
height: 375.h,
140143
),
141144
142145
////If you want to display a square:
143146
Container(
144-
width: ScreenUtil().setWidth(300),
147+
width: 300.w,
145148
height: 300.w,
146149
),
147150
151+
or
152+
153+
Container(
154+
width: 300.r,
155+
height: 300.r,
156+
),
148157
```
149158

150159

README_CN.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ ScreenUtil.init(constraints, designSize: Size(360,690), allowFontScaling: true);
8181
### API
8282
#### 传入设计稿的dp尺寸
8383
```dart
84-
ScreenUtil().setWidth(540) (sdk>=2.6 : 540.w) //根据屏幕宽度适配尺寸
85-
ScreenUtil().setHeight(200) (sdk>=2.6 : 200.h) //根据屏幕高度适配尺寸(一般根据宽度适配即可)
86-
ScreenUtil().setSp(24) (sdk>=2.6 : 24.sp) //适配字体
84+
ScreenUtil().setWidth(540) (sdk>=2.6 : 540.w) //根据屏幕宽度适配尺寸
85+
ScreenUtil().setHeight(200) (sdk>=2.6 : 200.h) //根据屏幕高度适配尺寸(一般根据宽度适配即可)
86+
ScreenUtil().radius(200) (sdk>=2.6 : 200.r) //根据宽度或高度中的较小者进行调整
87+
ScreenUtil().setSp(24) (sdk>=2.6 : 24.sp) //适配字体
8788
ScreenUtil().setSp(24, allowFontScalingSelf: true) (sdk>=2.6 : 24.ssp) //适配字体(根据系统的“字体大小”辅助选项来进行缩放)
8889
ScreenUtil().setSp(24, allowFontScalingSelf: false) (sdk>=2.6 : 24.nsp) //适配字体(不会根据系统的“字体大小”辅助选项来进行缩放)
8990
@@ -110,6 +111,8 @@ ScreenUtil.init(constraints, designSize: Size(360,690), allowFontScaling: true);
110111

111112
根据屏幕高度适配 `height: ScreenUtil().setHeight(200)`, 一般来说,控件高度也根据宽度进行适配
112113

114+
一般来说,50.w!=50.h
115+
113116
**注意**
114117

115118
高度也根据setWidth来做适配可以保证不变形(当你想要一个正方形的时候)
@@ -119,16 +122,16 @@ setHeight方法主要是在高度上进行适配, 在你想控制UI上一屏的
119122
例如:
120123

121124
```dart
122-
//UI上是长方形:
125+
//UI可能显示长方形:
123126
Container(
124-
width: ScreenUtil().setWidth(375),
125-
height: ScreenUtil().setHeight(375),
127+
width: 375.w,
128+
height: 375.h,
126129
),
127130
128131
//如果你想显示一个正方形:
129132
Container(
130-
width: ScreenUtil().setWidth(300),
131-
height: ScreenUtil().setWidth(300),
133+
width: 300.r,
134+
height: 300.r,
132135
),
133136
```
134137

README_PT.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ ScreenUtil.init(constraints, designSize: Size(360,690), allowFontScaling: true);
7979
```dart
8080
ScreenUtil().setWidth(540) (sdk>=2.6 : 540.w) //Adapted to screen width
8181
ScreenUtil().setHeight(200) (sdk>=2.6 : 200.h) //Adapted to screen height
82+
ScreenUtil().radius(200) (dart sdk>=2.6 : 200.r) //Adapt according to the smaller of width or height
8283
ScreenUtil().setSp(24) (sdk>=2.6 : 24.sp) //Adapter font
8384
ScreenUtil().setSp(24, allowFontScalingSelf: true) (sdk>=2.6 : 24.ssp) //Adapter font(fonts will scale to respect Text Size accessibility settings)
8485
ScreenUtil().setSp(24, allowFontScalingSelf: false) (sdk>=2.6 : 24.nsp) //Adapter font(fonts will not scale to respect Text Size accessibility settings)
@@ -129,19 +130,21 @@ Altura também é adaptada de acordo com o setWidth para garantir que não tenha
129130

130131
O método setHeight é a principal forma de adaptar a altura, se quiser controlar a altura e a realidade de uma tela na UiUsed quando a mesma for exibida.
131132

133+
Generally speaking, 50.w!=50.h.
134+
132135
```dart
133136
//Exemplo:
134137
//Retângulo
135138
Container(
136-
width: ScreenUtil().setWidth(375),
137-
height: ScreenUtil().setHeight(200),
139+
width: 375.w,
140+
height: 200.w,
138141
...
139142
),
140143
141144
////Se quiser exibir um quadrado:
142145
Container(
143-
width: ScreenUtil().setWidth(300),
144-
height: ScreenUtil().setWidth(300),
146+
width: 300.r,
147+
height: 300.r,
145148
),
146149
147150
```

example/lib/main.dart

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@ class _HomePageState extends State<HomePage> {
7979
),
8080
],
8181
),
82+
Container(
83+
padding: EdgeInsets.all(ScreenUtil().setWidth(10)),
84+
width: 100.r,
85+
height: 100.r,
86+
color: Colors.green,
87+
child: Text('I am a square with a side length of 100',
88+
style: TextStyle(
89+
color: Colors.white,
90+
fontSize: ScreenUtil().setSp(12),
91+
),
92+
),
93+
),
8294
Text('Device width:${ScreenUtil().screenWidth}dp'),
8395
Text('Device height:${ScreenUtil().screenHeight}dp'),
8496
Text('Device pixel density:${ScreenUtil().pixelRatio}'),
@@ -99,11 +111,14 @@ class _HomePageState extends State<HomePage> {
99111
Column(
100112
crossAxisAlignment: CrossAxisAlignment.start,
101113
children: <Widget>[
102-
Text(
103-
'My font size is 16sp on the design draft and will not change with the system.',
104-
style: TextStyle(
105-
color: Colors.black,
106-
fontSize: 16.sp,
114+
Container(
115+
height: 32.h,
116+
child: Text(
117+
'My font size is 16sp on the design draft and will not change with the system.',
118+
style: TextStyle(
119+
color: Colors.black,
120+
fontSize: 16.sp,
121+
),
107122
),
108123
),
109124
Text(

example/lib/main_zh.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,21 @@ class _HomePageState extends State<HomePage> {
6666
'我的设计稿高度: 200dp',
6767
style: TextStyle(color: Colors.white, fontSize: ScreenUtil().setSp(12))),
6868
),
69+
6970
],
7071
),
72+
Container(
73+
padding: EdgeInsets.all(ScreenUtil().setWidth(10)),
74+
width: 100.r,
75+
height: 100.r,
76+
color: Colors.green,
77+
child: Text('我是正方形,边长是100',
78+
style: TextStyle(
79+
color: Colors.white,
80+
fontSize: ScreenUtil().setSp(12),
81+
),
82+
),
83+
),
7184
Text('设备宽度:${ScreenUtil().screenWidth}dp'),
7285
Text('设备高度:${ScreenUtil().screenHeight}dp'),
7386
Text('设备的像素密度:${ScreenUtil().pixelRatio}'),

lib/screenutil.dart

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
44
*/
55

6+
import 'dart:math';
7+
68
import 'package:flutter/material.dart';
79

810
class ScreenUtil {
@@ -84,7 +86,7 @@ class ScreenUtil {
8486
/// /// The ratio of actual height to UI design
8587
double get scaleHeight => _screenHeight / uiSize.height;
8688

87-
double get scaleText => scaleWidth;
89+
double get scaleText => min(scaleWidth, scaleHeight);
8890

8991
/// 根据UI设计的设备宽度适配
9092
/// 高度也可以根据这个来做适配可以保证不变形,比如你先要一个正方形的时候.
@@ -103,14 +105,22 @@ class ScreenUtil {
103105
/// does not match the current style effect, or if there is a difference in shape.
104106
double setHeight(num height) => height * scaleHeight;
105107

108+
///Adapt according to the smaller of width or height
109+
num radius(num r) => r * scaleText;
110+
106111
///字体大小适配方法
107112
///- [fontSize] UI设计上字体的大小,单位px.
108113
///Font size adaptation method
109114
///- [fontSize] The size of the font on the UI design, in px.
110115
///- [allowFontScaling]
111-
double setSp(num fontSize, {bool allowFontScalingSelf}) => allowFontScalingSelf == null
112-
? (allowFontScaling ? (fontSize * scaleText) : (fontSize * scaleText / _textScaleFactor))
113-
: (allowFontScalingSelf ? (fontSize * scaleText) : (fontSize * scaleText / _textScaleFactor));
116+
double setSp(num fontSize, {bool allowFontScalingSelf}) =>
117+
allowFontScalingSelf == null
118+
? (allowFontScaling
119+
? (fontSize * scaleText)
120+
: (fontSize * scaleText / _textScaleFactor))
121+
: (allowFontScalingSelf
122+
? (fontSize * scaleText)
123+
: (fontSize * scaleText / _textScaleFactor));
114124
}
115125

116126
enum UnitType {

lib/size_extension.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ extension SizeExtension on num {
77
///[ScreenUtil.setHeight]
88
double get h => ScreenUtil().setHeight(this);
99

10+
///[ScreenUtil.radius]
11+
double get r => ScreenUtil().radius(this);
12+
1013
///[ScreenUtil.setSp]
1114
double get sp => ScreenUtil().setSp(this);
1215

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_screenutil
22
description: A flutter plugin for adapting screen and font size.Guaranteed to look good on different models
3-
version: 4.0.1
3+
version: 4.0.2
44
homepage: https://github.com/OpenFlutter/flutter_screenutil
55

66
environment:

0 commit comments

Comments
 (0)