李卓原

Merge branch 'v4'

null safety.1
# 5.0.0-nullsafety.1
- merge 4.0.1 ,4.0.2 #183
# 5.0.0-nullsafety.0
- Migrated flutter_screenutil to non-nullable
# 4.0.2
- add r(),adapt according to the smaller of width or height
# 4.0.1
- Modify the initialization unit to dp
- delete screenWidthPx and screenHeightPx(No one use these method,I guess)
# 4.0.0
- Upgrade to 4.0.0
- update to 4.0.0
# 4.0.0-beta3
- Optimize the way of initialization
... ...
... ... @@ -23,7 +23,7 @@ dependencies:
flutter:
sdk: flutter
# add flutter_screenutil
flutter_screenutil: ^5.0.0-nullsafety.0
flutter_screenutil: ^5.0.0-nullsafety.1
```
### Add the following imports to your Dart code:
```dart
... ... @@ -34,7 +34,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
|Property|Type|Default Value|Description|
|:---|:---|:---|:---|
|designSize|Size|Size(1080, 1920)|The size of the device in the design draft, in px|
|designSize|Size|Size(360, 690)|The size of the device in the design draft, in dp|
|allowFontScaling|bool|false|Sets whether the font size is scaled according to the system's "font size" assist option|
### Initialize and set the fit size and font size to scale according to the system's "font size" accessibility option
... ... @@ -59,14 +59,14 @@ class MyApp extends StatelessWidget {
//fill in the screen size of the device in the design
//default value : width : 1080px , height:1920px , allowFontScaling:false
//default value : width : 360dp , height:690dp , allowFontScaling:false
ScreenUtil.init(constraints);
//If the design is based on the size of the iPhone6 ​​(iPhone6 ​​750*1334)
ScreenUtil.init(constraints, designSize: Size(750, 1334));
//The size of the equipment in the design draft(360,690)
ScreenUtil.init(constraints, designSize: Size(360, 690));
//If you want to set the font size is scaled according to the system's "font size" assist option
ScreenUtil.init(constraints, designSize: Size(750, 1334), allowFontScaling: true);
ScreenUtil.init(constraints, designSize: Size(360, 690), allowFontScaling: true);
```
... ... @@ -74,11 +74,12 @@ ScreenUtil.init(constraints, designSize: Size(750, 1334), allowFontScaling: true
### API
#### Pass the px size of the design draft
#### Pass the dp size of the design draft
```dart
ScreenUtil().setWidth(540) (dart sdk>=2.6 : 540.w) //Adapted to screen width
ScreenUtil().setHeight(200) (dart sdk>=2.6 : 200.h) //Adapted to screen height , under normal circumstances, the height still uses x.w
ScreenUtil().radius(200) (dart sdk>=2.6 : 200.r) //Adapt according to the smaller of width or height
ScreenUtil().setSp(24) (dart sdk>=2.6 : 24.sp) //Adapter font
ScreenUtil().setSp(24, allowFontScalingSelf: true) (dart sdk>=2.6 : 24.ssp) //Adapter font(fonts will scale to respect Text Size accessibility settings)
ScreenUtil().setSp(24, allowFontScalingSelf: false) (dart sdk>=2.6 : 24.nsp) //Adapter font(fonts will not scale to respect Text Size accessibility settings)
... ... @@ -87,11 +88,11 @@ ScreenUtil.init(constraints, designSize: Size(750, 1334), allowFontScaling: true
ScreenUtil().screenWidth (dart sdk>=2.6 : 1.sw) //Device width
ScreenUtil().screenHeight (dart sdk>=2.6 : 1.sh) //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().statusBarHeight //Status bar height , Notch will be higher
ScreenUtil().textScaleFactor //System font scaling factor
ScreenUtil().scaleWidth //Ratio of actual width dp to ui design
ScreenUtil().scaleHeight //Ratio of actual height dp to ui design
ScreenUtil().scaleWidth //The ratio of actual width to UI design
ScreenUtil().scaleHeight //The ratio of actual height to UI design
0.2.sw //0.2 times the screen width
0.5.sh //50% of screen height
... ... @@ -99,7 +100,7 @@ ScreenUtil.init(constraints, designSize: Size(750, 1334), allowFontScaling: true
#### Adapt screen size:
Pass the px size of the design draft((The unit is the same as the unit at initialization)):
Pass the dp size of the design draft((The unit is the same as the unit at initialization)):
Adapted to screen width: `ScreenUtil().setWidth(540)`,
... ... @@ -129,22 +130,30 @@ The height can also use setWidth to ensure that it is not deformed(when you want
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.
Generally speaking, 50.w!=50.h.
```dart
//for example:
///If you want to display a square:
///rectangle
///The UI may show a rectangle:
Container(
width: ScreenUtil().setWidth(375),
height: ScreenUtil().setWidth(200),
width: 375.w,
height: 375.h,
),
////If you want to display a square:
Container(
width: ScreenUtil().setWidth(300),
width: 300.w,
height: 300.w,
),
or
Container(
width: 300.r,
height: 300.r,
),
```
... ... @@ -169,13 +178,13 @@ Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'My font size is 24px on the design draft and will not change with the system.',
'My font size is 24dp on the design draft and will not change with the system.',
style: TextStyle(
color: Colors.black,
fontSize: ScreenUtil().setSp(24),
)),
Text(
'My font size is 24px on the design draft and will change with the system.',
'My font size is 24dp on the design draft and will change with the system.',
style: TextStyle(
color: Colors.black,
fontSize: ScreenUtil()
... ...
# flutter_ScreenUtil
# flutter_screenUtil
[![pub package](https://img.shields.io/pub/v/flutter_screenutil.svg)](https://pub.dartlang.org/packages/flutter_screenutil)
... ... @@ -28,7 +28,7 @@ dependencies:
flutter:
sdk: flutter
# 添加依赖
flutter_screenutil: ^5.0.0-nullsafety.0
flutter_screenutil: ^5.0.0-nullsafety.1
```
### 在每个使用的地方导入包:
```dart
... ... @@ -39,7 +39,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
|属性|类型|默认值|描述|
|:---|:---|:---|:---|
|designSize|Size|Size(1080, 1920)|设计稿中设备的尺寸(单位随意,但在使用过程中必须保持一致)|
|designSize|Size|Size(360, 690)|设计稿中设备的尺寸(单位随意,但在使用过程中必须保持一致)|
|allowFontScaling|bool|false|设置字体大小是否根据系统的“字体大小”辅助选项来进行缩放|
### 初始化并设置适配尺寸及字体大小是否根据系统的“字体大小”辅助选项来进行缩放
... ... @@ -65,25 +65,26 @@ class MyApp extends StatelessWidget {
}
}
//默认 width : 1080px , height:1920px , allowFontScaling:false
//默认 width : 360dp , height:690dp , allowFontScaling:false
ScreenUtil.init(constraints);
//假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334)
ScreenUtil.init(constraints, designSize: Size(750, 1334));
//传入设计稿的尺寸(例如(360,690))
ScreenUtil.init(constraints, designSize: Size(360,690));
//设置字体大小根据系统的“字体大小”辅助选项来进行缩放,默认为false
ScreenUtil.init(constraints, designSize: Size(750, 1334), allowFontScaling: true);
ScreenUtil.init(constraints, designSize: Size(360,690), allowFontScaling: true);
```
### 使用
### API
#### 传入设计稿的px尺寸 px px px !
#### 传入设计稿的dp尺寸
```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().setWidth(540) (sdk>=2.6 : 540.w) //根据屏幕宽度适配尺寸
ScreenUtil().setHeight(200) (sdk>=2.6 : 200.h) //根据屏幕高度适配尺寸(一般根据宽度适配即可)
ScreenUtil().radius(200) (sdk>=2.6 : 200.r) //根据宽度或高度中的较小者进行调整
ScreenUtil().setSp(24) (sdk>=2.6 : 24.sp) //适配字体
ScreenUtil().setSp(24, allowFontScalingSelf: true) (sdk>=2.6 : 24.ssp) //适配字体(根据系统的“字体大小”辅助选项来进行缩放)
ScreenUtil().setSp(24, allowFontScalingSelf: false) (sdk>=2.6 : 24.nsp) //适配字体(不会根据系统的“字体大小”辅助选项来进行缩放)
... ... @@ -94,8 +95,8 @@ ScreenUtil.init(constraints, designSize: Size(750, 1334), allowFontScaling: true
ScreenUtil.statusBarHeight //状态栏高度 刘海屏会更高
ScreenUtil.textScaleFactor //系统字体缩放比例
ScreenUtil().scaleWidth // 实际宽度的dp与设计稿宽度的比例
ScreenUtil().scaleHeight // 实际高度的dp与设计稿高度度的比例
ScreenUtil().scaleWidth // 实际宽度设计稿宽度的比例
ScreenUtil().scaleHeight // 实际高度与设计稿高度度的比例
0.2.sw //屏幕宽度的0.2倍
0.5.sh //屏幕高度的50%
... ... @@ -110,6 +111,8 @@ ScreenUtil.init(constraints, designSize: Size(750, 1334), allowFontScaling: true
根据屏幕高度适配 `height: ScreenUtil().setHeight(200)`, 一般来说,控件高度也根据宽度进行适配
一般来说,50.w!=50.h
**注意**
高度也根据setWidth来做适配可以保证不变形(当你想要一个正方形的时候)
... ... @@ -119,16 +122,16 @@ setHeight譁ケ豕穂クサ隕∵弍蝨ィ鬮伜コヲ荳願ソ幄。碁る, 蝨ィ菴諠ウ謗ァ蛻カUI荳贋ク螻冗噪
例如:
```dart
//UI上是长方形:
//UI可能显示长方形:
Container(
width: ScreenUtil().setWidth(375),
height: ScreenUtil().setHeight(375),
width: 375.w,
height: 375.h,
),
//如果你想显示一个正方形:
Container(
width: ScreenUtil().setWidth(300),
height: ScreenUtil().setWidth(300),
width: 300.r,
height: 300.r,
),
```
... ... @@ -169,12 +172,12 @@ ScreenUtil().setSp(24, allowFontScalingSelf: true)
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('我的文字大小在设计稿上是24px,不会随着系统的文字缩放比例变化',
Text('我的文字大小在设计稿上是24dp,不会随着系统的文字缩放比例变化',
style: TextStyle(
color: Colors.black,
fontSize: ScreenUtil().setSp(24),
)),
Text('我的文字大小在设计稿上是24px,会随着系统的文字缩放比例变化',
Text('我的文字大小在设计稿上是24dp,会随着系统的文字缩放比例变化',
style: TextStyle(
color: Colors.black,
fontSize: ScreenUtil()
... ...
... ... @@ -24,7 +24,7 @@ dependencies:
flutter:
sdk: flutter
# add flutter_screenutil
flutter_screenutil: ^5.0.0-nullsafety.0
flutter_screenutil: ^5.0.0-nullsafety.1
```
### Adicione o seguinte import em seu código Dart:
... ... @@ -36,8 +36,8 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
|Propriedade|Tipo|Valor Padrão|Descrição|
|:---|:---|:---|:---|
|width|double|1080px|A largura do dispositivo no protótipo de design, em px|
|height|double|1920px|A altura do dispositivo no protótipo de design, em px|
|width|double|360dp|A largura do dispositivo no protótipo de design, em dp|
|height|double|690dp|A altura do dispositivo no protótipo de design, em dp|
|allowFontScaling|bool|false|Defina caso o tamanho da fonte seja dimensionado de acordo com a opção "tamanho de fonte" na acessibilidade do sistema|
### Inicialize e defina o tamanho de ajuste e tamanho da fonte para dimensionar de acordo com a opção "tamanho de fonte" na acessibilidade do sistema
... ... @@ -61,14 +61,14 @@ class MyApp extends StatelessWidget {
}
}
//Valor padrão: width : 1080px , height:1920px , allowFontScaling:false
//Valor padrão: width : 360dp , height:690dp , allowFontScaling:false
ScreenUtil.init(constraints);
//Se o design é baseado no iPhone6 ​​(iPhone6 ​​750*1334)
ScreenUtil.init(constraints, designSize: Size(750, 1334));
//The size of the equipment in the design draft(360,690)
ScreenUtil.init(constraints, designSize: Size(360,690));
//Se você quer definir que o tamanho da fonte seja ajustado de acordo com a opção "tamanho da fonte" na acessibilidade do sistema
ScreenUtil.init(constraints, designSize: Size(750, 1334), allowFontScaling: true);
ScreenUtil.init(constraints, designSize: Size(360,690), allowFontScaling: true);
```
... ... @@ -79,6 +79,7 @@ ScreenUtil.init(constraints, designSize: Size(750, 1334), allowFontScaling: true
```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().radius(200) (dart sdk>=2.6 : 200.r) //Adapt according to the smaller of width or 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().setSp(24, allowFontScalingSelf: false) (sdk>=2.6 : 24.nsp) //Adapter font(fonts will not scale to respect Text Size accessibility settings)
... ... @@ -87,11 +88,11 @@ ScreenUtil.init(constraints, designSize: Size(750, 1334), allowFontScaling: true
ScreenUtil.screenWidth (sdk>=2.6 : 1.sw) //Device width
ScreenUtil.screenHeight (sdk>=2.6 : 1.sh) //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.statusBarHeight //Status bar height , Notch will be higher
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
ScreenUtil().scaleWidth //The ratio of actual width to UI design
ScreenUtil().scaleHeight //The ratio of actual height to UI design
0.2.sw //0,2 vezes a largura da tela
0.5.sh //50% altura da tela
... ... @@ -129,19 +130,21 @@ Altura também é adaptada de acordo com o setWidth para garantir que não tenha
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.
Generally speaking, 50.w!=50.h.
```dart
//Exemplo:
//Retângulo
Container(
width: ScreenUtil().setWidth(375),
height: ScreenUtil().setHeight(200),
width: 375.w,
height: 200.w,
...
),
////Se quiser exibir um quadrado:
Container(
width: ScreenUtil().setWidth(300),
height: ScreenUtil().setWidth(300),
width: 300.r,
height: 300.r,
),
```
... ...
... ... @@ -8,7 +8,7 @@ class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
//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)
return ScreenUtilInit(
designSize: Size(750, 1334),
designSize: Size(360, 690),
allowFontScaling: false,
child: MaterialApp(
debugShowCheckedModeBanner: false,
... ... @@ -54,65 +54,78 @@ class _HomePageState extends State<HomePage> {
height: 200.h,
color: Colors.red,
child: Text(
'My width:${0.5.sw}dp \n'
'My height:${200.h}dp',
'My actual width: ${0.5.sw}dp \n\n'
'My actual height: ${200.h}dp',
style: TextStyle(
color: Colors.white,
fontSize: 24.sp,
fontSize: 12.sp,
),
),
),
// Without using Extensions
Container(
padding: EdgeInsets.all(ScreenUtil().setWidth(10)),
width: ScreenUtil().screenWidth * 0.5,
width: 180.w,
height: ScreenUtil().setHeight(200),
color: Colors.blue,
child: Text(
'My width:${ScreenUtil().screenWidth * 0.5}dp \n'
'My height:${ScreenUtil().setHeight(200)}dp',
'My design draft width: 180dp\n\n'
'My design draft height: 200dp',
style: TextStyle(
color: Colors.white,
fontSize: ScreenUtil().setSp(24),
fontSize: ScreenUtil().setSp(12),
),
),
),
],
),
Text('Device width:${ScreenUtil().screenWidthPx}px'),
Text('Device height:${ScreenUtil().screenHeightPx}px'),
Container(
padding: EdgeInsets.all(ScreenUtil().setWidth(10)),
width: 100.r,
height: 100.r,
color: Colors.green,
child: Text('I am a square with a side length of 100',
style: TextStyle(
color: Colors.white,
fontSize: ScreenUtil().setSp(12),
),
),
),
Text('Device width:${ScreenUtil().screenWidth}dp'),
Text('Device height:${ScreenUtil().screenHeight}dp'),
Text('Device pixel density:${ScreenUtil().pixelRatio}'),
Text('Bottom safe zone distance:${ScreenUtil().bottomBarHeight}dp'),
Text('Status bar height:${ScreenUtil().statusBarHeight}dp'),
Text(
'Ratio of actual width dp to design draft px:${ScreenUtil().scaleWidth}',
'The ratio of actual width to UI design:${ScreenUtil().scaleWidth}',
textAlign: TextAlign.center,
),
Text(
'Ratio of actual height dp to design draft px:${ScreenUtil().scaleHeight}',
'The ratio of actual height to UI design:${ScreenUtil().scaleHeight}',
textAlign: TextAlign.center,
),
SizedBox(
height: 5.h,
height: 50.h,
),
Text('System font scaling factor:${ScreenUtil().textScaleFactor}'),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'My font size is 24px on the design draft and will not change with the system.',
style: TextStyle(
color: Colors.black,
fontSize: 24.sp,
Container(
height: 32.h,
child: Text(
'My font size is 16sp on the design draft and will not change with the system.',
style: TextStyle(
color: Colors.black,
fontSize: 16.sp,
),
),
),
Text(
'My font size is 24px on the design draft and will change with the system.',
'My font size is 16sp on the design draft and will change with the system.',
style: TextStyle(
color: Colors.black,
fontSize: 24.ssp,
fontSize: 16.ssp,
),
),
],
... ... @@ -129,8 +142,8 @@ class _HomePageState extends State<HomePage> {
print('Device pixel density:${ScreenUtil().pixelRatio}');
print('Bottom safe zone distance dp:${ScreenUtil().bottomBarHeight}dp');
print('Status bar height dp:${ScreenUtil().statusBarHeight}dp');
print('Ratio of actual width dp to UI Design:${ScreenUtil().scaleWidth}');
print('Ratio of actual height dp to UI Design:${ScreenUtil().scaleHeight}');
print('The ratio of actual width to UI design:${ScreenUtil().scaleWidth}');
print('The ratio of actual height to UI design:${ScreenUtil().scaleHeight}');
print('System font scaling:${ScreenUtil().textScaleFactor}');
print('0.5 times the screen width:${0.5.sw}dp');
print('0.5 times the screen height:${0.5.sh}dp');
... ...
... ... @@ -51,57 +51,68 @@ class _HomePageState extends State<HomePage> {
height: ScreenUtil().setHeight(200),
color: Colors.red,
child: Text(
'我的宽度:${0.5.sw}dp \n'
'我的高度:${ScreenUtil().setHeight(200)}dp',
style: TextStyle(color: Colors.white, fontSize: ScreenUtil().setSp(24)),
'我的实际宽度:${0.5.sw}dp \n'
'我的实际高度:${ScreenUtil().setHeight(200)}dp',
style: TextStyle(color: Colors.white, fontSize: ScreenUtil().setSp(12)),
),
),
Container(
padding: EdgeInsets.all(ScreenUtil().setWidth(10)),
width: 375.w,
width: 180.w,
height: 200.h,
color: Colors.blue,
child: Text(
'我的宽度:${375.w}dp \n'
'我的高度:${200.h}dp',
style: TextStyle(color: Colors.white, fontSize: ScreenUtil().setSp(24))),
'我的设计稿宽度: 180dp \n'
'我的设计稿高度: 200dp',
style: TextStyle(color: Colors.white, fontSize: ScreenUtil().setSp(12))),
),
],
),
Text('设备宽度:${ScreenUtil().screenWidthPx}px'),
Text('设备高度:${ScreenUtil().screenHeightPx}px'),
Container(
padding: EdgeInsets.all(ScreenUtil().setWidth(10)),
width: 100.r,
height: 100.r,
color: Colors.green,
child: Text('我是正方形,边长是100',
style: TextStyle(
color: Colors.white,
fontSize: ScreenUtil().setSp(12),
),
),
),
Text('设备宽度:${ScreenUtil().screenWidth}dp'),
Text('设备高度:${ScreenUtil().screenHeight}dp'),
Text('设备的像素密度:${ScreenUtil().pixelRatio}'),
Text('底部安全区距离:${ScreenUtil().bottomBarHeight}dp'),
Text('状态栏高度:${ScreenUtil().statusBarHeight}dp'),
Text(
'实际宽度的dp与设计稿px的比例:${ScreenUtil().scaleWidth}',
'实际宽度与设计稿的比例:${ScreenUtil().scaleWidth}',
textAlign: TextAlign.center,
),
Text(
'实际高度的dp与设计稿px的比例:${ScreenUtil().scaleHeight}',
'实际高度与设计稿的比例:${ScreenUtil().scaleHeight}',
textAlign: TextAlign.center,
),
SizedBox(
height: 100.h,
height: 50.h,
),
Text('系统的字体缩放比例:${ScreenUtil().textScaleFactor}'),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'我的文字大小在设计稿上是24px,不会随着系统的文字缩放比例变化',
'我的文字大小在设计稿上是16dp,不会随着系统的文字缩放比例变化',
style: TextStyle(
color: Colors.black,
fontSize: 24.sp,
fontSize: 16.sp,
),
),
Text(
'我的文字大小在设计稿上是24px,会随着系统的文字缩放比例变化',
'我的文字大小在设计稿上是16dp,会随着系统的文字缩放比例变化',
style: TextStyle(
color: Colors.black,
fontSize: 24.ssp,
fontSize: 16.ssp,
),
),
],
... ...
... ... @@ -5,6 +5,8 @@
import 'dart:ui' as ui;
import 'dart:math';
import 'package:flutter/material.dart';
class ScreenUtil {
... ... @@ -44,11 +46,11 @@ class ScreenUtil {
_screenWidth = constraints.maxWidth;
_screenHeight = constraints.maxHeight;
var mediaQuery = WidgetsBinding.instance?.window ?? ui.window;
_pixelRatio = mediaQuery.devicePixelRatio;
_statusBarHeight = mediaQuery.padding.top;
_bottomBarHeight = mediaQuery.padding.bottom;
_textScaleFactor = mediaQuery.textScaleFactor;
var window = WidgetsBinding.instance?.window ?? ui.window;
_pixelRatio = window.devicePixelRatio;
_statusBarHeight = window.padding.top;
_bottomBarHeight = window.padding.bottom;
_textScaleFactor = window.textScaleFactor;
}
/// 每个逻辑像素的字体像素数,字体的缩放比例
... ... @@ -67,14 +69,6 @@ class ScreenUtil {
///The vertical extent of this size. dp
double get screenHeight => _screenHeight;
/// 当前设备宽度 px
/// The vertical extent of this size. px
double get screenWidthPx => _screenWidth * _pixelRatio;
/// 当前设备高度 px
/// The vertical extent of this size. px
double get screenHeightPx => _screenHeight * _pixelRatio;
/// 状态栏高度 dp 刘海屏会更高
/// The offset from the top, in dp
double get statusBarHeight => _statusBarHeight / _pixelRatio;
... ... @@ -83,13 +77,14 @@ class ScreenUtil {
/// The offset from the bottom, in dp
double get bottomBarHeight => _bottomBarHeight / _pixelRatio;
/// 实际的dp与UI设计px的比例
/// The ratio of the actual dp to the design draft px
/// 实际尺寸与UI设计的比例
/// The ratio of actual width to UI design
double get scaleWidth => _screenWidth / uiSize.width;
/// /// The ratio of actual height to UI design
double get scaleHeight => _screenHeight / uiSize.height;
double get scaleText => scaleWidth;
double get scaleText => min(scaleWidth, scaleHeight);
/// 根据UI设计的设备宽度适配
/// 高度也可以根据这个来做适配可以保证不变形,比如你先要一个正方形的时候.
... ... @@ -108,6 +103,9 @@ class ScreenUtil {
/// does not match the current style effect, or if there is a difference in shape.
double setHeight(num height) => height * scaleHeight;
///Adapt according to the smaller of width or height
double radius(num r) => r * scaleText;
///字体大小适配方法
///- [fontSize] UI设计上字体的大小,单位px.
///Font size adaptation method
... ...
... ... @@ -7,6 +7,9 @@ extension SizeExtension on num {
///[ScreenUtil.setHeight]
double get h => ScreenUtil().setHeight(this);
///[ScreenUtil.radius]
double get r => ScreenUtil().radius(this);
///[ScreenUtil.setSp]
double get sp => ScreenUtil().setSp(this);
... ...
name: flutter_screenutil
description: A flutter plugin for adapting screen and font size.Guaranteed to look good on different models
version: 5.0.0-nullsafety.0
version: 5.0.0-nullsafety.1
homepage: https://github.com/OpenFlutter/flutter_screenutil
environment:
... ...