Skip to content

Commit 4aef3ee

Browse files
committed
beta
1 parent 9a06dfb commit 4aef3ee

File tree

4 files changed

+73
-77
lines changed

4 files changed

+73
-77
lines changed

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ height:200.h
123123
```
124124
**Note**
125125

126-
Height is also adapted according to setWidth to ensure no deformation (when you want a square)
126+
The height can also use setWidth to ensure that it is not deformed(when you want a square)
127127

128128
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.
129129

@@ -139,23 +139,28 @@ Container(
139139
////If you want to display a square:
140140
Container(
141141
width: ScreenUtil().setWidth(300),
142-
height: ScreenUtil().setWidth(300),
142+
height: 300.w,
143143
),
144-
144+
145145
```
146146

147147
#### Adapter font:
148148
``` dart
149149
//Incoming font size,the unit is pixel, fonts will not scale to respect Text Size accessibility settings
150150
//(AllowallowFontScaling when initializing ScreenUtil)
151-
ScreenUtil().setSp(28)
151+
ScreenUtil().setSp(28)
152+
28.sp
152153
153154
//Incoming font size,the unit is pixel,fonts will scale to respect Text Size accessibility settings
154-
//(If somewhere does not follow the global allowFontScaling setting)
155+
//(If somewhere follow the global allowFontScaling setting)
155156
ScreenUtil().setSp(24, allowFontScalingSelf: true)
157+
28.ssp
156158
157-
//for example:
159+
//(If somewhere does not follow the global allowFontScaling setting)
160+
ScreenUtil().setSp(24, allowFontScalingSelf: false)
161+
28.nsp
158162
163+
//for example:
159164
Column(
160165
crossAxisAlignment: CrossAxisAlignment.start,
161166
children: <Widget>[

README_CN.md

Lines changed: 50 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,12 @@ Column(
181181
```
182182

183183
```dart
184-
import 'package:flutter/material.dart';
185-
import 'package:flutter_screenutil/flutter_screenutil.dart';
186-
187-
void main() => runApp( MyApp());
184+
void main() {
185+
WidgetsFlutterBinding.ensureInitialized();
186+
//设置适配尺寸 (填入设计稿中设备的屏幕尺寸) 此处假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334)
187+
ScreenUtil.init(designSize: Size(750, 1334), allowFontScaling: false);
188+
runApp(MyApp());
189+
}
188190
189191
class MyApp extends StatelessWidget {
190192
@override
@@ -195,32 +197,11 @@ class MyApp extends StatelessWidget {
195197
theme: ThemeData(
196198
primarySwatch: Colors.blue,
197199
),
198-
home: MyHomePage(),
200+
home: ExampleWidget(title: 'FlutterScreenUtil示例'),
199201
);
200202
}
201203
}
202204
203-
class MyHomePage extends StatefulWidget {
204-
MyHomePage({Key key, this.title}) : super(key: key);
205-
206-
final String title;
207-
208-
@override
209-
_MyHomePageState createState() => _MyHomePageState();
210-
}
211-
212-
class _MyHomePageState extends State<MyHomePage> {
213-
@override
214-
Widget build(BuildContext context) {
215-
//设置适配尺寸 (填入设计稿中设备的屏幕尺寸) 此处假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334)
216-
ScreenUtil.init(width: 750, height: 1334, allowFontScaling: false);
217-
ScreenUtil.init();
218-
ScreenUtil.init(width: 750, height: 1334, allowFontScaling: false);
219-
220-
return ExampleWidget(title: 'FlutterScreenUtil示例');
221-
}
222-
}
223-
224205
class ExampleWidget extends StatefulWidget {
225206
const ExampleWidget({Key key, this.title}) : super(key: key);
226207
@@ -250,33 +231,33 @@ class _ExampleWidgetState extends State<ExampleWidget> {
250231
height: ScreenUtil().setHeight(200),
251232
color: Colors.red,
252233
child: Text(
253-
'我的宽度:${ScreenUtil().setWidth(375)}dp \n'
234+
'我的宽度:${0.5.wp}dp \n'
254235
'我的高度:${ScreenUtil().setHeight(200)}dp',
255236
style: TextStyle(
256237
color: Colors.white, fontSize: ScreenUtil().setSp(24)),
257238
),
258239
),
259240
Container(
260241
padding: EdgeInsets.all(ScreenUtil().setWidth(10)),
261-
width: ScreenUtil().setWidth(375),
262-
height: ScreenUtil().setHeight(200),
242+
width: 375.w,
243+
height: 200.h,
263244
color: Colors.blue,
264245
child: Text(
265-
'我的宽度:${ScreenUtil().setWidth(375)}dp \n'
266-
'我的高度:${ScreenUtil().setHeight(200)}dp',
246+
'我的宽度:${375.w}dp \n'
247+
'我的高度:${200.h}dp',
267248
style: TextStyle(
268249
color: Colors.white,
269250
fontSize: ScreenUtil().setSp(24))),
270251
),
271252
],
272253
),
273-
Text('设备宽度:${ScreenUtil.screenWidth}dp'),
274-
Text('设备高度:${ScreenUtil.screenHeight}dp'),
275-
Text('设备宽度:${ScreenUtil.screenWidthPx}px'),
276-
Text('设备高度:${ScreenUtil.screenHeightPx}px'),
277-
Text('设备的像素密度:${ScreenUtil.pixelRatio}'),
278-
Text('底部安全区距离:${ScreenUtil.bottomBarHeight}dp'),
279-
Text('状态栏高度:${ScreenUtil.statusBarHeight}dp'),
254+
Text('设备宽度:${ScreenUtil().screenWidthPx}px'),
255+
Text('设备高度:${ScreenUtil().screenHeightPx}px'),
256+
Text('设备宽度:${ScreenUtil().screenWidth}dp'),
257+
Text('设备高度:${ScreenUtil().screenHeight}dp'),
258+
Text('设备的像素密度:${ScreenUtil().pixelRatio}'),
259+
Text('底部安全区距离:${ScreenUtil().bottomBarHeight}dp'),
260+
Text('状态栏高度:${ScreenUtil().statusBarHeight}dp'),
280261
Text(
281262
'实际宽度的dp与设计稿px的比例:${ScreenUtil().scaleWidth}',
282263
textAlign: TextAlign.center,
@@ -286,22 +267,20 @@ class _ExampleWidgetState extends State<ExampleWidget> {
286267
textAlign: TextAlign.center,
287268
),
288269
SizedBox(
289-
height: ScreenUtil().setHeight(100),
270+
height: 100.h,
290271
),
291-
Text('系统的字体缩放比例:${ScreenUtil.textScaleFactor}'),
272+
Text('系统的字体缩放比例:${ScreenUtil().textScaleFactor}'),
292273
Column(
293274
crossAxisAlignment: CrossAxisAlignment.start,
294275
children: <Widget>[
295-
Text('我的文字大小在设计稿上是24px,不会随着系统的文字缩放比例变化',
296-
style: TextStyle(
297-
color: Colors.black,
298-
fontSize: ScreenUtil().setSp(24),
299-
)),
300-
Text('我的文字大小在设计稿上是24px,会随着系统的文字缩放比例变化',
301-
style: TextStyle(
302-
color: Colors.black,
303-
fontSize: ScreenUtil()
304-
.setSp(24, allowFontScalingSelf: true))),
276+
Text(
277+
'我的文字大小在设计稿上是24px,不会随着系统的文字缩放比例变化',
278+
style: ts.t2,
279+
),
280+
Text(
281+
'我的文字大小在设计稿上是24px,会随着系统的文字缩放比例变化',
282+
style: ts.t1,
283+
),
305284
],
306285
)
307286
],
@@ -310,28 +289,40 @@ class _ExampleWidgetState extends State<ExampleWidget> {
310289
floatingActionButton: FloatingActionButton(
311290
child: Icon(Icons.title),
312291
onPressed: () {
313-
ScreenUtil.init(width: 1500, height: 1334, allowFontScaling: false);
292+
ScreenUtil.init(
293+
designSize: Size(1500, 1334),
294+
allowFontScaling: false,
295+
);
314296
setState(() {});
315297
},
316298
),
317299
);
318300
}
319301
320302
void printScreenInformation() {
321-
print('设备宽度:${ScreenUtil.screenWidth}'); //Device width
322-
print('设备高度:${ScreenUtil.screenHeight}'); //Device height
323-
print('设备的像素密度:${ScreenUtil.pixelRatio}'); //Device pixel density
303+
print('设备宽度:${ScreenUtil().screenWidth}'); //Device width
304+
print('设备高度:${ScreenUtil().screenHeight}'); //Device height
305+
print('设备的像素密度:${ScreenUtil().pixelRatio}'); //Device pixel density
324306
print(
325-
'底部安全区距离:${ScreenUtil.bottomBarHeight}dp'); //Bottom safe zone distance,suitable for buttons with full screen
307+
'底部安全区距离:${ScreenUtil().bottomBarHeight}dp',
308+
); //Bottom safe zone distance,suitable for buttons with full screen
326309
print(
327-
'状态栏高度:${ScreenUtil.statusBarHeight}dp'); //状态栏高度 , 刘海屏会更高,单位dp
310+
'状态栏高度:${ScreenUtil().statusBarHeight}dp',
311+
); //Status bar height , Notch will be higher Unit px
328312
329313
print('实际宽度的dp与设计稿px的比例:${ScreenUtil().scaleWidth}');
330314
print('实际高度的dp与设计稿px的比例:${ScreenUtil().scaleHeight}');
315+
331316
print(
332-
'宽度和字体相对于设计稿放大的比例:${ScreenUtil().scaleWidth * ScreenUtil.pixelRatio}');
333-
print('高度相对于设计稿放大的比例:${ScreenUtil().scaleHeight * ScreenUtil.pixelRatio}');
334-
print('系统的字体缩放比例:${ScreenUtil.textScaleFactor}');
317+
'宽度和字体相对于设计稿放大的比例:${ScreenUtil().scaleWidth * ScreenUtil().pixelRatio}',
318+
);
319+
print(
320+
'高度相对于设计稿放大的比例:${ScreenUtil().scaleHeight * ScreenUtil().pixelRatio}',
321+
);
322+
print('系统的字体缩放比例:${ScreenUtil().textScaleFactor}');
323+
324+
print('屏幕宽度的0.5:${0.5.wp}');
325+
print('屏幕高度的0.5:${0.5.hp}');
335326
}
336327
}
337328

README_PT.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,16 +193,16 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
193193
@override
194194
Widget build(BuildContext context) {
195195
///Define o tamanho de ajuste (preenche o tamanho da tela do dispositivo no design). Se o design é baseado no tamanho do iPhone6 (iPhone6 ​​750*1334)
196-
ScreenUtil.init(width: 750, height: 1334, allowFontScaling: false);
196+
ScreenUtil.init(designSize: Size(750, 1334), allowFontScaling: false);
197197
198-
print('Largura do dispositivo:${ScreenUtil.screenWidth}'); //Largura do dispositivo
199-
print('Altura do dispositivo:${ScreenUtil.screenHeight}'); //Altura do dispositivo
198+
print('Largura do dispositivo:${ScreenUtil().screenWidth}'); //Largura do dispositivo
199+
print('Altura do dispositivo:${ScreenUtil().screenHeight}'); //Altura do dispositivo
200200
print(
201-
'Densidade de pixels do dispositivo:${ScreenUtil.pixelRatio}'); //Densidade de pixels do dispositivo
201+
'Densidade de pixels do dispositivo:${ScreenUtil().pixelRatio}'); //Densidade de pixels do dispositivo
202202
print(
203-
'Distância segura do rodapé:${ScreenUtil.bottomBarHeight}'); //Distância segura do rodapé, adequada para botões em tela cheia
203+
'Distância segura do rodapé:${ScreenUtil().bottomBarHeight}'); //Distância segura do rodapé, adequada para botões em tela cheia
204204
print(
205-
'Altura da status bar:${ScreenUtil.statusBarHeight}px'); //Altura da status bar em pixels, Notch será maior
205+
'Altura da status bar:${ScreenUtil().statusBarHeight}px'); //Altura da status bar em pixels, Notch será maior
206206
print(
207207
'Razão entre a largura atual e a largura do protótipo de design em pixels:${ScreenUtil().scaleWidth}');
208208
print(
@@ -246,11 +246,11 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
246246
),
247247
],
248248
),
249-
Text('Largura do dispositivo:${ScreenUtil.screenWidth}dp'),
250-
Text('Altura do dispositivo:${ScreenUtil.screenHeight}dp'),
251-
Text('Densidade de pixels do dispositivo:${ScreenUtil.pixelRatio}'),
252-
Text('Distância segura do rodapé:${ScreenUtil.bottomBarHeight}dp'),
253-
Text('Altura da status bar:${ScreenUtil.statusBarHeight}dp'),
249+
Text('Largura do dispositivo:${ScreenUtil().screenWidth}dp'),
250+
Text('Altura do dispositivo:${ScreenUtil().screenHeight}dp'),
251+
Text('Densidade de pixels do dispositivo:${ScreenUtil().pixelRatio}'),
252+
Text('Distância segura do rodapé:${ScreenUtil().bottomBarHeight}dp'),
253+
Text('Altura da status bar:${ScreenUtil().statusBarHeight}dp'),
254254
Text(
255255
'Razão entre a largura atual e a largura do protótipo de design em pixels:${ScreenUtil().scaleWidth}',
256256
textAlign: TextAlign.center,

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: 3.0.0-beta.1
3+
version: 3.0.0-beta.2
44
homepage: https://github.com/OpenFlutter/flutter_screenutil/tree/beta
55

66
environment:

0 commit comments

Comments
 (0)