Skip to content

Commit 4b3f685

Browse files
committed
Merge branch 'beta'
# Conflicts: # README_CN.md # README_PT.md
2 parents a4595b0 + be34035 commit 4b3f685

29 files changed

+651
-780
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66
* @Description: Update log
77
-->
88

9+
# 3.0.0-beta.2
10+
- readme update
11+
12+
# 3.0.0-beta.1
13+
**BREAKING CHANGES**
14+
- `BuildContext` is no more required while initializing. i.e. ScreenUtil.init(~~context~~)
15+
- Initialize size of design draft using `designSize` instead of width & height.
16+
- All the static methods are now member methods.
17+
918
# 2.3.1
1019
- add textStyle Example.
1120

README.md

Lines changed: 33 additions & 181 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# flutter_screenutil
32
[![pub package](https://img.shields.io/pub/v/flutter_screenutil.svg)](https://pub.dev/packages/flutter_screenutil)
43

@@ -29,9 +28,8 @@ dependencies:
2928
flutter:
3029
sdk: flutter
3130
# add flutter_screenutil
32-
flutter_screenutil: ^2.3.0
31+
flutter_screenutil: ^3.0.0-beta.1
3332
```
34-
3533
### Add the following imports to your Dart code:
3634
```
3735
import 'package:flutter_screenutil/flutter_screenutil.dart';
@@ -41,26 +39,31 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
4139

4240
|Property|Type|Default Value|Description|
4341
|:---|:---|:---|:---|
44-
|width|double|1080px|The width of the device in the design draft, in px|
45-
|height|double|1920px|The height of the device in the design draft, in px|
42+
|designSize|Size|Size(1080, 1920)|The size of the device in the design draft, in px|
4643
|allowFontScaling|bool|false|Sets whether the font size is scaled according to the system's "font size" assist option|
4744

4845
### Initialize and set the fit size and font size to scale according to the system's "font size" accessibility option
49-
Please set the width and height of the design draft before use, the width and height of the design draft (unit px).
50-
Be sure to set the page in the MaterialApp's home/initialRoute(ie the entry file, just set it once) to ensure that the fit size is set before each use:
46+
Please set the size of the design draft before use, the width and height of the design draft (unit px).
5147

52-
```dart
48+
```
49+
50+
void main() {
51+
WidgetsFlutterBinding.ensureInitialized();
52+
//Set the fit size (fill in the screen size of the device in the design) If the design is based on the size of the iPhone6 ​​(iPhone6 ​​750*1334)
53+
ScreenUtil.init(designSize: Size(750, 1334), allowFontScaling: false);
54+
runApp(MyApp());
55+
}
5356
5457
//fill in the screen size of the device in the design
5558
5659
//default value : width : 1080px , height:1920px , allowFontScaling:false
57-
ScreenUtil.init(context);
60+
ScreenUtil.init();
5861
5962
//If the design is based on the size of the iPhone6 ​​(iPhone6 ​​750*1334)
60-
ScreenUtil.init(context, width: 750, height: 1334);
63+
ScreenUtil.init(designSize: Size(750, 1334));
6164
6265
//If you want to set the font size is scaled according to the system's "font size" assist option
63-
ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: true);
66+
ScreenUtil.init(designSize: Size(750, 1334), allowFontScaling: true);
6467
6568
```
6669

@@ -77,12 +80,12 @@ ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: true);
7780
ScreenUtil().setSp(24, allowFontScalingSelf: true) (sdk>=2.6 : 24.ssp) //Adapter font(fonts will scale to respect Text Size accessibility settings)
7881
ScreenUtil().setSp(24, allowFontScalingSelf: false) (sdk>=2.6 : 24.nsp) //Adapter font(fonts will not scale to respect Text Size accessibility settings)
7982
80-
ScreenUtil.pixelRatio //Device pixel density
81-
ScreenUtil.screenWidth (sdk>=2.6 : 1.wp) //Device width
82-
ScreenUtil.screenHeight (sdk>=2.6 : 1.hp) //Device height
83-
ScreenUtil.bottomBarHeight //Bottom safe zone distance, suitable for buttons with full screen
84-
ScreenUtil.statusBarHeight //Status bar height , Notch will be higher Unit px
85-
ScreenUtil.textScaleFactor //System font scaling factor
83+
ScreenUtil().pixelRatio //Device pixel density
84+
ScreenUtil().screenWidth (sdk>=2.6 : 1.wp) //Device width
85+
ScreenUtil().screenHeight (sdk>=2.6 : 1.hp) //Device height
86+
ScreenUtil().bottomBarHeight //Bottom safe zone distance, suitable for buttons with full screen
87+
ScreenUtil().statusBarHeight //Status bar height , Notch will be higher Unit px
88+
ScreenUtil().textScaleFactor //System font scaling factor
8689
8790
ScreenUtil().scaleWidth //Ratio of actual width dp to design draft px
8891
ScreenUtil().scaleHeight //Ratio of actual height dp to design draft px
@@ -119,7 +122,7 @@ height:200.h
119122
```
120123
**Note**
121124

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

124127
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.
125128

@@ -135,23 +138,28 @@ Container(
135138
////If you want to display a square:
136139
Container(
137140
width: ScreenUtil().setWidth(300),
138-
height: ScreenUtil().setWidth(300),
141+
height: 300.w,
139142
),
140-
143+
141144
```
142145

143146
#### Adapter font:
144147
``` dart
145148
//Incoming font size,the unit is pixel, fonts will not scale to respect Text Size accessibility settings
146149
//(AllowallowFontScaling when initializing ScreenUtil)
147-
ScreenUtil().setSp(28)
150+
ScreenUtil().setSp(28)
151+
28.sp
148152
149153
//Incoming font size,the unit is pixel,fonts will scale to respect Text Size accessibility settings
150-
//(If somewhere does not follow the global allowFontScaling setting)
154+
//(If somewhere follow the global allowFontScaling setting)
151155
ScreenUtil().setSp(24, allowFontScalingSelf: true)
156+
28.ssp
152157
153-
//for example:
158+
//(If somewhere does not follow the global allowFontScaling setting)
159+
ScreenUtil().setSp(24, allowFontScalingSelf: false)
160+
28.nsp
154161
162+
//for example:
155163
Column(
156164
crossAxisAlignment: CrossAxisAlignment.start,
157165
children: <Widget>[
@@ -171,167 +179,11 @@ Column(
171179
)
172180
```
173181

174-
```dart
175-
//import
176-
import 'package:flutter/material.dart';
177-
import 'package:flutter_screenutil/flutter_screenutil.dart';
178-
179-
void main() => runApp(MyApp());
180-
181-
class MyApp extends StatelessWidget {
182-
@override
183-
Widget build(BuildContext context) {
184-
return MaterialApp(
185-
debugShowCheckedModeBanner: false,
186-
title: 'Flutter_ScreenUtil',
187-
theme: ThemeData(
188-
primarySwatch: Colors.blue,
189-
),
190-
home: MyHomePage(),
191-
);
192-
}
193-
}
194-
195-
class MyHomePage extends StatefulWidget {
196-
@override
197-
_MyHomePageState createState() => _MyHomePageState();
198-
}
199-
200-
class _MyHomePageState extends State<MyHomePage> {
201-
@override
202-
Widget build(BuildContext context) {
203-
//Set the fit size (fill in the screen size of the device in the design) If the design is based on the size of the iPhone6 ​​(iPhone6 ​​750*1334)
204-
ScreenUtil.init(width: 750, height: 1334, allowFontScaling: false);
205-
206-
return ExampleWidget(title: 'FlutterScreenUtil Demo');
207-
}
208-
}
209-
210-
class ExampleWidget extends StatefulWidget {
211-
const ExampleWidget({Key key, this.title}) : super(key: key);
212-
213-
final String title;
214-
215-
@override
216-
_ExampleWidgetState createState() => _ExampleWidgetState();
217-
}
218-
219-
class _ExampleWidgetState extends State<ExampleWidget> {
220-
@override
221-
Widget build(BuildContext context) {
222-
printScreenInformation();
223-
return Scaffold(
224-
appBar: AppBar(
225-
title: Text(widget.title),
226-
),
227-
body: SingleChildScrollView(
228-
child: Column(
229-
crossAxisAlignment: CrossAxisAlignment.center,
230-
children: <Widget>[
231-
Row(
232-
children: <Widget>[
233-
Container(
234-
padding: EdgeInsets.all(ScreenUtil().setWidth(10)),
235-
width: ScreenUtil().setWidth(375),
236-
height: ScreenUtil().setHeight(200),
237-
color: Colors.red,
238-
child: Text(
239-
'My width:${ScreenUtil().setWidth(375)}dp \n'
240-
'My height:${ScreenUtil().setHeight(200)}dp',
241-
style: TextStyle(
242-
color: Colors.white, fontSize: ScreenUtil().setSp(24)),
243-
),
244-
),
245-
Container(
246-
padding: EdgeInsets.all(ScreenUtil().setWidth(10)),
247-
width: ScreenUtil().setWidth(375),
248-
height: ScreenUtil().setHeight(200),
249-
color: Colors.blue,
250-
child: Text(
251-
'My width:${ScreenUtil().setWidth(375)}dp \n'
252-
'My height:${ScreenUtil().setHeight(200)}dp',
253-
style: TextStyle(
254-
color: Colors.white,
255-
fontSize: ScreenUtil().setSp(24))),
256-
),
257-
],
258-
),
259-
Text('Device width:${ScreenUtil.screenWidth}dp'),
260-
Text('Device height:${ScreenUtil.screenHeight}dp'),
261-
Text('Device width:${ScreenUtil.screenWidthPx}px'),
262-
Text('Device height:${ScreenUtil.screenHeightPx}px'),
263-
Text('Device pixel density:${ScreenUtil.pixelRatio}'),
264-
Text('Bottom safe zone distance:${ScreenUtil.bottomBarHeight}dp'),
265-
Text('Status bar height:${ScreenUtil.statusBarHeight}dp'),
266-
Text(
267-
'Ratio of actual width dp to design draft px:${ScreenUtil().scaleWidth}',
268-
textAlign: TextAlign.center,
269-
),
270-
Text(
271-
'Ratio of actual height dp to design draft px:${ScreenUtil().scaleHeight}',
272-
textAlign: TextAlign.center,
273-
),
274-
SizedBox(
275-
height: ScreenUtil().setHeight(100),
276-
),
277-
Text('System font scaling factor:${ScreenUtil.textScaleFactor}'),
278-
Column(
279-
crossAxisAlignment: CrossAxisAlignment.start,
280-
children: <Widget>[
281-
Text(
282-
'My font size is 24px on the design draft and will not change with the system.',
283-
style: TextStyle(
284-
color: Colors.black,
285-
fontSize: ScreenUtil().setSp(24),
286-
)),
287-
Text(
288-
'My font size is 24px on the design draft and will change with the system.',
289-
style: TextStyle(
290-
color: Colors.black,
291-
fontSize: ScreenUtil()
292-
.setSp(24, allowFontScalingSelf: true))),
293-
],
294-
)
295-
],
296-
),
297-
),
298-
floatingActionButton: FloatingActionButton(
299-
child: Icon(Icons.title),
300-
onPressed: () {
301-
ScreenUtil.init(width: 1500, height: 1334, allowFontScaling: false);
302-
setState(() {});
303-
},
304-
),
305-
);
306-
}
307-
308-
void printScreenInformation() {
309-
print('Device width dp:${ScreenUtil.screenWidth}'); //Device width
310-
print('Device height dp:${ScreenUtil.screenHeight}'); //Device height
311-
print(
312-
'Device pixel density:${ScreenUtil.pixelRatio}'); //Device pixel density
313-
print(
314-
'Bottom safe zone distance dp:${ScreenUtil.bottomBarHeight}'); //Bottom safe zone distance,suitable for buttons with full screen
315-
print(
316-
'Status bar height dp:${ScreenUtil.statusBarHeight}dp'); //Status bar height , Notch will be higher Unit dp
317-
print(
318-
'Ratio of actual width dp to design draft px:${ScreenUtil().scaleWidth}');
319-
print(
320-
'Ratio of actual height dp to design draft px:${ScreenUtil().scaleHeight}');
321-
print(
322-
'The ratio of font and width to the size of the design:${ScreenUtil().scaleWidth * ScreenUtil.pixelRatio}');
323-
print(
324-
'The ratio of height width to the size of the design:${ScreenUtil().scaleHeight * ScreenUtil.pixelRatio}');
325-
}
326-
}
327-
328-
```
329-
330-
### example:
182+
### Example:
331183

332184
[example demo](/example/lib/main.dart)
333185

334-
effect:
186+
### Effect:
335187

336188
![effect](demo_en.png)
337189
![tablet effect](demo_tablet_en.png)

0 commit comments

Comments
 (0)