李卓原

4.0.2

close #180
<!--
* @Author: zhuoyuan93@gmail.com
* @Date: 2018-10-16 19:43:03
* @LastEditors: zhuoyuan93@gmail.com
* @LastEditTime: 2020年6月20日 11:20:02
* @Description: Update log
-->
# 4.0.2
- add r(),adapt according to the smaller of width or height
# 4.0.1
- Modify the initialization unit to dp
... ...
... ... @@ -79,6 +79,7 @@ ScreenUtil.init(constraints, designSize: Size(360, 690), allowFontScaling: true)
```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)
... ... @@ -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,
),
```
... ...
... ... @@ -83,6 +83,7 @@ ScreenUtil.init(constraints, designSize: Size(360,690), allowFontScaling: true);
```dart
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) //适配字体(不会根据系统的“字体大小”辅助选项来进行缩放)
... ... @@ -110,6 +111,8 @@ ScreenUtil.init(constraints, designSize: Size(360,690), 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,
),
```
... ...
... ... @@ -79,6 +79,7 @@ ScreenUtil.init(constraints, designSize: Size(360,690), 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)
... ... @@ -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,
),
```
... ...
... ... @@ -79,6 +79,18 @@ class _HomePageState extends State<HomePage> {
),
],
),
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}'),
... ... @@ -99,13 +111,16 @@ class _HomePageState extends State<HomePage> {
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
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 16sp on the design draft and will change with the system.',
style: TextStyle(
... ...
... ... @@ -66,8 +66,21 @@ class _HomePageState extends State<HomePage> {
'我的设计稿高度: 200dp',
style: TextStyle(color: Colors.white, fontSize: ScreenUtil().setSp(12))),
),
],
),
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}'),
... ...
... ... @@ -3,6 +3,8 @@
* email: zhuoyuan93@gmail.com
*/
import 'dart:math';
import 'package:flutter/material.dart';
class ScreenUtil {
... ... @@ -84,7 +86,7 @@ class ScreenUtil {
/// /// 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设计的设备宽度适配
/// 高度也可以根据这个来做适配可以保证不变形,比如你先要一个正方形的时候.
... ... @@ -103,14 +105,22 @@ 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
num radius(num r) => r * scaleText;
///字体大小适配方法
///- [fontSize] UI设计上字体的大小,单位px.
///Font size adaptation method
///- [fontSize] The size of the font on the UI design, in px.
///- [allowFontScaling]
double setSp(num fontSize, {bool allowFontScalingSelf}) => allowFontScalingSelf == null
? (allowFontScaling ? (fontSize * scaleText) : (fontSize * scaleText / _textScaleFactor))
: (allowFontScalingSelf ? (fontSize * scaleText) : (fontSize * scaleText / _textScaleFactor));
double setSp(num fontSize, {bool allowFontScalingSelf}) =>
allowFontScalingSelf == null
? (allowFontScaling
? (fontSize * scaleText)
: (fontSize * scaleText / _textScaleFactor))
: (allowFontScalingSelf
? (fontSize * scaleText)
: (fontSize * scaleText / _textScaleFactor));
}
enum UnitType {
... ...
... ... @@ -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: 4.0.1
version: 4.0.2
homepage: https://github.com/OpenFlutter/flutter_screenutil
environment:
... ...