kageeker
... ... @@ -19,5 +19,4 @@ doc
# Include when developing application packages.
.lock
coverage*
*.iml
*.lock
... ...
# 5.1.1
- .w,.h use MediaQuery
# 5.1.0
- Break Change: updated the first initialization method, please refer to README.md
# 5.0.4
- Break Change : add setContext() , the first initialization method requires calling
- fix # 310
- update ReadMe.md
# 5.0.3
- init method add "context" param
- update ReadMe.md
# 5.0.2+1
- fix splitScreenMode to false
# 5.0.2
- add "minTextAdapt" param , Font adaptation is based on the minimum value of width and height or
only based on width(default)
- update readme
# 5.0.1+3
- fix .r
# 5.0.1+2
- Text adaptation no longer considers the height of the screen
# 5.0.1+1
- split default value change to false
# 5.0.1
- support for split screen
- add number.sm (return min(number.sp , number))
# 5.0.0+2
- update readme
# 5.0.0+1
- update readme
# 5.0.0
-Breaking change. Use a new way to set font scaling
-Deprecated ssp and nsp
-Breaking change. Use a new way to set font scaling -Deprecated ssp and nsp
# 5.0.0-nullsafety.11
- revert 5.0.0-nullsafety.10
- fix #230
# 5.0.0-nullsafety.10
- fix #228
# 5.0.0-nullsafety.9
- Supplementary documentation, supports two initialization methods
# 5.0.0-nullsafety.8
- merge v4
- Add a method to get the screen orientation
# 5.0.0-nullsafety.7
- fix #221
# 5.0.0-nullsafety.6
- merge #216 #218
# 5.0.0-nullsafety.5
- Optimize initialization method
# 5.0.0-nullsafety.4
- merge #205
# 5.0.0-nullsafety.3
- merge 4.0.2+3
# 5.0.0-nullsafety.2
- merge 4.0.2+2 #186
# 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
- update to 4.0.0
# 4.0.0-beta3
- Optimize the way of initialization
# 4.0.0-beta2
- fix error:'window is not a type.'
# 4.0.0-beta1
- change readme
# 4.0.0-beta
- Modified the initialization method
- Support font adaptation in themedata
# 3.2.0
- Modify the method name to be more semantic: wp->sw , hp->sh
- Remove the restriction of flutter version
- Modify the return type num to double
# 3.1.1
- change readme
# 3.1.0
- Use the way back to v2 version
- Modify registration method
# 3.0.2+1
- Guide users to use V2 version
# 3.0.2
- Change the unit of'statusBarHeight' and 'bottomBarHeight' to dp
# 3.0.1
- update readme
# 3.0.0
- After a period of experimentation, I think it's time to release the official version
# 3.0.0-beta.2
- readme update
# 3.0.0-beta.1
**BREAKING CHANGES**
- `BuildContext` is no more required while initializing. i.e. ScreenUtil.init(~~context~~)
- Initialize size of design draft using `designSize` instead of width & height.
- All the static methods are now member methods.
# 2.3.1
- add textStyle Example.
# 2.3.0
- We still need context to initialize, sorry.
# 2.2.0
- add 'wp','hp'. Get the height/width of the screen proportionally
- For example: 0.5.wp : Half the width of the screen.
# 2.1.0
- add 'nsp' , you can use 'fontSize: 24.nsp' instead of 'fontSize: ScreenUtil().setSp(24, allowFontScalingSelf: false)'
- add 'nsp' , you can use 'fontSize: 24.nsp' instead of 'fontSize: ScreenUtil().setSp(24,
allowFontScalingSelf: false)'
# 2.0.0
- Use `MediaQueryData.fromWindow(window)` instead of `MediaQuery.of(context)`, no context parameter required
- Use `MediaQueryData.fromWindow(window)` instead of `MediaQuery.of(context)`, no context parameter
required
- API changes, please note
# 1.1.0
- support ExtensionMethod Dart-SDK-2.6.0
- you can use 'width: 50.w' instead of 'width: ScreenUtil().setWidth(50)'
'50.h' instead of 'ScreenUtil().setHeight(50)'
... ... @@ -127,18 +209,20 @@
'24.ssp' instead of 'ScreenUtil().setSp(24, allowFontScalingSelf: true)'
# 1.0.2
- fix #89
- 优化屏幕旋转效果
- 字体适配统一使用宽度
# 1.0.1
- Rebuild code, change API
Delete "getInstance()", please use "ScreenUtil ()" instead of "ScreenUtil.getInstance()"
use "ScreenUtil().setSp(24, allowFontScalingSelf: true)" instead of "ScreenUtil.getInstance().setSp(14, true)"
- Rebuild code, change API Delete "getInstance()", please use "ScreenUtil ()" instead of "
ScreenUtil.getInstance()"
use "ScreenUtil().setSp(24, allowFontScalingSelf: true)" instead of "ScreenUtil.getInstance()
.setSp(14, true)"
- Modify the initialization method
- Fix #68
- Change example code
Example CompileSdkVersion change to 28
- Change example code Example CompileSdkVersion change to 28
**If there is significant impact, please return to 0.7.0**
... ... @@ -170,7 +254,8 @@
- Fix the wrong way of using
- It is recommended to use `ScreenUtil.getInstance()` instead of `ScreenUtil()` , for example: `ScreenUtil.getInstance().setHeight(25)` instead of `ScreenUtil().setHeight(25)`
- It is recommended to use `ScreenUtil.getInstance()` instead of `ScreenUtil()` , for
example: `ScreenUtil.getInstance().setHeight(25)` instead of `ScreenUtil().setHeight(25)`
# 0.4.4
... ... @@ -180,9 +265,9 @@
- Modify the font to change with the system zoom mode. The default value is false.
- setSp(int fontSize, [allowFontScaling = false]) => allowFontScaling
? setWidth(fontSize) \* \_textScaleFactor
: setWidth(fontSize);
- setSp(int fontSize, [allowFontScaling = false]) => allowFontScaling ? setWidth(fontSize) \*
\_textScaleFactor
: setWidth(fontSize);
# 0.4.2
... ... @@ -206,9 +291,10 @@
# 0.3.1
- Perfect documentation
- Width is enlarged relative to the design draft => The ratio of font and width to the size of the design
- Height is enlarged relative to the design draft => The ratio of height width to the size of the design
- Width is enlarged relative to the design draft => The ratio of font and width to the size of the
design
- Height is enlarged relative to the design draft => The ratio of height width to the size of the
design
# 0.3.0
... ...
# flutter_screenutil
[![pub package](https://img.shields.io/pub/v/flutter_screenutil.svg)](https://pub.dev/packages/flutter_screenutil)
[![pub points](https://badges.bar/flutter_screenutil/pub%20points)](https://pub.dev/packages/flutter_screenutil/score)
[![popularity](https://badges.bar/flutter_screenutil/popularity)](https://pub.dev/packages/flutter_screenutil/score)
**A flutter plugin for adapting screen and font size.Let your UI display a reasonable layout on different screen sizes!**
... ... @@ -56,6 +58,24 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
<td>portrait</td>
<td>screen orientation</td>
</tr>
<tr>
<td>splitScreenMode</td>
<td>bool</td>
<td>true</td>
<td>support for split screen</td>
</tr>
<tr>
<td>minTextAdapt</td>
<td>bool</td>
<td>false</td>
<td>Whether to adapt the text according to the minimum of width and height</td>
</tr>
<tr>
<td>context</td>
<td>BuildContext</td>
<td>null</td>
<td>If context!=null, screen changes will be more sensitive</td>
</tr>
</table>
### Initialize and set the fit size and font size to scale according to the system's "font size" accessibility option
... ... @@ -71,10 +91,21 @@ class MyApp extends StatelessWidget {
//Set the fit size (Find your UI design, look at the dimensions of the device screen and fill it in,unit in dp)
return ScreenUtilInit(
designSize: Size(360, 690),
builder: () => MaterialApp(
...
minTextAdapt: true,
splitScreenMode: true,
builder: () =>
MaterialApp(
//... other code
builder: (context, widget) {
//add this line
ScreenUtil.setContext(context);
return MediaQuery(
//Setting font does not change with system font size
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
child: widget!,
);
},
theme: ThemeData(
primarySwatch: Colors.blue,
textTheme: TextTheme(
//To support the following, you need to use the first initialization method
button: TextStyle(fontSize: 45.sp)
... ... @@ -135,6 +166,8 @@ class _HomePageState extends State<HomePage> {
maxWidth: MediaQuery.of(context).size.width,
maxHeight: MediaQuery.of(context).size.height),
designSize: Size(360, 690),
context: context,
minTextAdapt: true,
orientation: Orientation.portrait);
return Scaffold();
}
... ... @@ -152,6 +185,7 @@ class _HomePageState extends State<HomePage> {
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
12.sm //return min(12,12.sp)
ScreenUtil().pixelRatio //Device pixel density
ScreenUtil().screenWidth (dart sdk>=2.6 : 1.sw) //Device width
... ...
# flutter_screenUtil
# flutter_screenutil
[![pub package](https://img.shields.io/pub/v/flutter_screenutil.svg)](https://pub.dartlang.org/packages/flutter_screenutil)
[![pub points](https://badges.bar/flutter_screenutil/pub%20points)](https://pub.dev/packages/flutter_screenutil/score)
[![popularity](https://badges.bar/flutter_screenutil/popularity)](https://pub.dev/packages/flutter_screenutil/score)
**flutter 屏幕适配方案,让你的UI在不同尺寸的屏幕上都能显示合理的布局!**
... ... @@ -42,6 +44,9 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
|designSize|Size|Size(360, 690)|设计稿中设备的尺寸(单位随意,建议dp,但在使用过程中必须保持一致)|
|builder|Widget Function()|Container()|一般返回一个MaterialApp类型的Function()|
|orientation|Orientation|portrait|屏幕方向|
|splitScreenMode|bool|true|支持分屏尺寸|
|minTextAdapt|bool|false|是否根据宽度/高度中的最小值适配文字|
|context|BuildContext|null|传入context会更灵敏的根据屏幕变化而改变|
### 初始化并设置适配尺寸及字体大小是否根据系统的“字体大小”辅助选项来进行缩放
在使用之前请设置好设计稿的宽度和高度,传入设计稿的宽度和高度(单位随意,但在使用过程中必须保持一致)
... ... @@ -57,17 +62,26 @@ class MyApp extends StatelessWidget {
//填入设计稿中设备的屏幕尺寸,单位dp
return ScreenUtilInit(
designSize: Size(360, 690),
builder: () => MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter_ScreenUtil',
minTextAdapt: true,
splitScreenMode: true,
builder: () =>
MaterialApp(
//... other code
builder: (context, widget) {
//add this line
ScreenUtil.setContext(context);
return MediaQuery(
//Setting font does not change with system font size
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
child: widget!,
);
},
theme: ThemeData(
primarySwatch: Colors.blue,
//要支持下面这个需要使用第一种初始化方式
textTheme: TextTheme(
//要支持下面这个需要使用第一种初始化方式
button: TextStyle(fontSize: 45.sp)
),
),
home: HomePage(title: 'FlutterScreenUtil Demo'),
),
);
}
... ... @@ -112,6 +126,8 @@ class _HomePageState extends State<HomePage> {
maxWidth: MediaQuery.of(context).size.width,
maxHeight: MediaQuery.of(context).size.height),
designSize: Size(360, 690),
context: context,
minTextAdapt: true,
orientation: Orientation.portrait);
return Scaffold();
}
... ... @@ -127,6 +143,7 @@ class _HomePageState extends State<HomePage> {
ScreenUtil().setHeight(200) (sdk>=2.6 : 200.h) //根据屏幕高度适配尺寸(一般根据宽度适配即可)
ScreenUtil().radius(200) (sdk>=2.6 : 200.r) //根据宽度或高度中的较小者进行调整
ScreenUtil().setSp(24) (sdk>=2.6 : 24.sp) //适配字体
12.sm // 取12和12.sp中的最小值
ScreenUtil.pixelRatio //设备的像素密度
ScreenUtil.screenWidth (sdk>=2.6 : 1.sw) //设备宽度
... ...
# I don’t speak Portuguese, and other developers have translated the first version. I later modified it based on the translation software. It is recommended to read the English/Chinese version.
# flutter_screenutil
[![pub package](https://img.shields.io/pub/v/flutter_screenutil.svg)](https://pub.dartlang.org/packages/flutter_screenutil)
[![pub points](https://badges.bar/flutter_screenutil/pub%20points)](https://pub.dev/packages/flutter_screenutil/score)
[![popularity](https://badges.bar/flutter_screenutil/popularity)](https://pub.dev/packages/flutter_screenutil/score)
**Um plugin Flutter para adaptação de tamanho de tela e fontes. Deixe sua UI exibir um layout aceitável em diferentes tamanhos de tela!**
... ... @@ -39,6 +41,8 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
|designSize|Size|Size(360, 690)|The size of the device screen in the design draft, in dp|
|builder|Widget Function()|Container()|Generally returning a Function of MaterialApp type|
|orientation|Orientation|portrait|screen orientation|
|minTextAdapt|bool|false|Whether to adapt the text according to the minimum of width and height|
|context|BuildContext|null|传入context会更灵敏的根据屏幕变化而改变|
### 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
Por favor, defina a largura e altura do protótipo de design antes de usar (em pixels).
... ... @@ -54,12 +58,23 @@ class MyApp extends StatelessWidget {
//Set the fit size (Find your UI design, look at the dimensions of the device screen and fill it in,unit in dp)
return ScreenUtilInit(
designSize: Size(360, 690),
builder: () => MaterialApp(
...
minTextAdapt: true,
splitScreenMode: true,
builder: () =>
MaterialApp(
//... other code
builder: (context, widget) {
//add this line
ScreenUtil.setContext(context);
return MediaQuery(
//Setting font does not change with system font size
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
child: widget!,
);
},
theme: ThemeData(
primarySwatch: Colors.blue,
//To support the following, you need to use the first initialization method
textTheme: TextTheme(
//To support the following, you need to use the first initialization method
button: TextStyle(fontSize: 45.sp)
),
),
... ... @@ -103,6 +118,7 @@ class _HomePageState extends State<HomePage> {
maxWidth: MediaQuery.of(context).size.width,
maxHeight: MediaQuery.of(context).size.height),
designSize: Size(360, 690),
context: context,
orientation: Orientation.portrait);
return Scaffold();
}
... ...
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android" name="Android">
<configuration>
<option name="ALLOW_USER_CONFIGURATION" value="false" />
<option name="GEN_FOLDER_RELATIVE_PATH_APT" value="/gen" />
<option name="GEN_FOLDER_RELATIVE_PATH_AIDL" value="/gen" />
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/app/src/main/AndroidManifest.xml" />
<option name="RES_FOLDER_RELATIVE_PATH" value="/app/src/main/res" />
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/app/src/main/assets" />
<option name="LIBS_FOLDER_RELATIVE_PATH" value="/app/src/main/libs" />
<option name="PROGUARD_LOGS_FOLDER_RELATIVE_PATH" value="/app/src/main/proguard_logs" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/app/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/app/src/main/kotlin" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" generated="true" />
</content>
<orderEntry type="jdk" jdkName="Android API 29 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Flutter for Android" level="project" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
</component>
</module>
... ...
... ... @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>8.0</string>
<string>9.0</string>
</dict>
</plist>
... ...
... ... @@ -3,11 +3,16 @@
export "FLUTTER_ROOT=C:\dev\flutter"
export "FLUTTER_APPLICATION_PATH=C:\Users\kagee\Documents\flutter_screenutil\example"
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
<<<<<<< HEAD
export "FLUTTER_TARGET=lib\main.dart"
=======
export "FLUTTER_TARGET=/Users/lizhuoyuan/Development/Project/flutter_screenutil/example/lib/main.dart"
>>>>>>> 30a18a0ab24cfbb7f41bc5abd3b88e91b091d595
export "FLUTTER_BUILD_DIR=build"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
export "DART_DEFINES=Zmx1dHRlci5pbnNwZWN0b3Iuc3RydWN0dXJlZEVycm9ycz10cnVl,RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ=="
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=false"
export "TRACK_WIDGET_CREATION=true"
export "TREE_SHAKE_ICONS=false"
export "PACKAGE_CONFIG=.packages"
export "PACKAGE_CONFIG=/Users/lizhuoyuan/Development/Project/flutter_screenutil/example/.dart_tool/package_config.json"
... ...
... ... @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objectVersion = 50;
objects = {
/* Begin PBXBuildFile section */
... ... @@ -139,7 +139,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0910;
LastUpgradeCheck = 1300;
ORGANIZATIONNAME = "The Chromium Authors";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
... ... @@ -292,7 +292,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
... ... @@ -339,7 +339,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
... ...
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0910"
LastUpgradeVersion = "1300"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
... ...
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
void main() => runApp(MyApp());
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
... ... @@ -9,6 +11,8 @@ class MyApp extends StatelessWidget {
//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(360, 690),
minTextAdapt: true,
splitScreenMode: true,
builder: () => MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter_ScreenUtil',
... ... @@ -17,6 +21,7 @@ class MyApp extends StatelessWidget {
textTheme: TextTheme(button: TextStyle(fontSize: 45.sp)),
),
builder: (context, widget) {
ScreenUtil.setContext(context);
return MediaQuery(
//Setting font does not change with system font size
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
... ... @@ -85,7 +90,7 @@ class _HomePageState extends State<HomePage> {
],
),
Container(
padding: EdgeInsets.all(ScreenUtil().setWidth(10)),
padding: EdgeInsets.all(10.w),
width: 100.r,
height: 100.r,
color: Colors.green,
... ... @@ -93,7 +98,7 @@ class _HomePageState extends State<HomePage> {
'I am a square with a side length of 100',
style: TextStyle(
color: Colors.white,
fontSize: ScreenUtil().setSp(12),
fontSize: 12.sp,
),
),
),
... ...
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
... ... @@ -35,6 +37,7 @@ class _HomePageState extends State<HomePage> {
maxWidth: MediaQuery.of(context).size.width,
maxHeight: MediaQuery.of(context).size.height),
designSize: Size(360, 690),
context: context,
);
printScreenInformation();
return Scaffold(
... ...
... ... @@ -2,6 +2,8 @@
// Generated file. Do not edit.
//
// clang-format off
#include "generated_plugin_registrant.h"
... ...
... ... @@ -2,6 +2,8 @@
// Generated file. Do not edit.
//
// clang-format off
#ifndef GENERATED_PLUGIN_REGISTRANT_
#define GENERATED_PLUGIN_REGISTRANT_
... ...
... ... @@ -7,6 +7,7 @@ library flutter_screenutil;
import 'dart:math';
import 'dart:ui' as ui;
import 'dart:ui';
import 'package:flutter/material.dart';
... ...
... ... @@ -15,12 +15,10 @@ class ScreenUtil {
///屏幕方向
late Orientation _orientation;
late double _pixelRatio;
late double _textScaleFactor;
late double _screenWidth;
late double _screenHeight;
late double _statusBarHeight;
late double _bottomBarHeight;
late bool _minTextAdapt;
late BuildContext? context;
ScreenUtil._();
... ... @@ -28,22 +26,27 @@ class ScreenUtil {
return _instance;
}
static void setContext(BuildContext context) {
_instance.context = context;
}
static void init(
BoxConstraints constraints, {
BuildContext? context,
Orientation orientation = Orientation.portrait,
Size designSize = defaultSize,
bool splitScreenMode = false,
bool minTextAdapt = false,
}) {
_instance = ScreenUtil._()
..uiSize = designSize
.._minTextAdapt = minTextAdapt
.._orientation = orientation
.._screenWidth = constraints.maxWidth
.._screenHeight = constraints.maxHeight;
var window = WidgetsBinding.instance?.window ?? ui.window;
_instance._pixelRatio = window.devicePixelRatio;
_instance._statusBarHeight = window.padding.top;
_instance._bottomBarHeight = window.padding.bottom;
_instance._textScaleFactor = window.textScaleFactor;
.._screenHeight = splitScreenMode
? max(constraints.maxHeight, 700)
: constraints.maxHeight;
if (context != null) setContext(context);
}
///获取屏幕方向
... ... @@ -52,36 +55,39 @@ class ScreenUtil {
/// 每个逻辑像素的字体像素数,字体的缩放比例
/// The number of font pixels for each logical pixel.
double get textScaleFactor => _textScaleFactor;
double get textScaleFactor => MediaQuery.of(context!).textScaleFactor;
/// 设备的像素密度
/// The size of the media in logical pixels (e.g, the size of the screen).
double get pixelRatio => _pixelRatio;
double? get pixelRatio => MediaQuery.of(context!).devicePixelRatio;
/// 当前设备宽度 dp
/// The horizontal extent of this size.
double get screenWidth => _screenWidth;
double get screenWidth =>
context == null ? _screenWidth : MediaQuery.of(context!).size.width;
///当前设备高度 dp
///The vertical extent of this size. dp
double get screenHeight => _screenHeight;
double get screenHeight =>
context == null ? _screenHeight : MediaQuery.of(context!).size.height;
/// 状态栏高度 dp 刘海屏会更高
/// The offset from the top, in dp
double get statusBarHeight => _statusBarHeight / _pixelRatio;
double get statusBarHeight => MediaQuery.of(context!).padding.top;
/// 底部安全区距离 dp
/// The offset from the bottom, in dp
double get bottomBarHeight => _bottomBarHeight / _pixelRatio;
double get bottomBarHeight => MediaQuery.of(context!).padding.bottom;
/// 实际尺寸与UI设计的比例
/// The ratio of actual width to UI design
double get scaleWidth => _screenWidth / uiSize.width;
double get scaleWidth => screenWidth / uiSize.width;
/// /// The ratio of actual height to UI design
double get scaleHeight => _screenHeight / uiSize.height;
double get scaleHeight => screenHeight / uiSize.height;
double get scaleText => min(scaleWidth, scaleHeight);
double get scaleText =>
_minTextAdapt ? min(scaleWidth, scaleHeight) : scaleWidth;
/// 根据UI设计的设备宽度适配
/// 高度也可以根据这个来做适配可以保证不变形,比如你想要一个正方形的时候.
... ... @@ -102,7 +108,7 @@ class ScreenUtil {
///根据宽度或高度中的较小值进行适配
///Adapt according to the smaller of width or height
double radius(num r) => r * scaleText;
double radius(num r) => r * min(scaleWidth, scaleHeight);
///字体大小适配方法
///- [fontSize] UI设计上字体的大小,单位dp.
... ...
... ... @@ -5,10 +5,14 @@ class ScreenUtilInit extends StatelessWidget {
ScreenUtilInit({
required this.builder,
this.designSize = ScreenUtil.defaultSize,
this.splitScreenMode = false,
this.minTextAdapt = false,
Key? key,
}) : super(key: key);
final Widget Function() builder;
final bool splitScreenMode;
final bool minTextAdapt;
/// The [Size] of the device in the design draft, in dp
final Size designSize;
... ... @@ -17,14 +21,16 @@ class ScreenUtilInit extends StatelessWidget {
Widget build(BuildContext context) {
return LayoutBuilder(builder: (_, BoxConstraints constraints) {
if (constraints.maxWidth != 0) {
final Orientation orientation = constraints.maxWidth > constraints.maxHeight
final Orientation orientation =
constraints.maxWidth > constraints.maxHeight
? Orientation.landscape
: Orientation.portrait;
ScreenUtil.init(
constraints,
ScreenUtil.init(constraints,
context: _,
orientation: orientation,
designSize: designSize,
);
splitScreenMode: splitScreenMode,
minTextAdapt: minTextAdapt);
return builder();
}
return Container();
... ...
... ... @@ -13,14 +13,10 @@ extension SizeExtension on num {
///[ScreenUtil.setSp]
double get sp => ScreenUtil().setSp(this);
///[ScreenUtil.setSp]
@Deprecated('please use [sp]')
double get ssp => ScreenUtil().setSp(this);
///[ScreenUtil.setSp]
@Deprecated(
'please use [sp] , and set textScaleFactor: 1.0 , for example: Text("text", textScaleFactor: 1.0)')
double get nsp => ScreenUtil().setSp(this);
///smart size : it check your value - if it is bigger than your value it will set your value
///for example, you have set 16.sm() , if for your screen 16.sp() is bigger than 16 , then it will set 16 not 16.sp()
///I think that it is good for save size balance on big sizes of screen
double get sm => min(toDouble(), sp);
///屏幕宽度的倍数
///Multiple of screen width
... ...
name: flutter_screenutil
description: A flutter plugin for adapting screen and font size.Guaranteed to look good on different models
version: 5.0.0+2
version: 5.1.1
homepage: https://github.com/OpenFlutter/flutter_screenutil
publish_to: https://pub.dev
environment:
sdk: ">=2.12.0 <3.0.0"
... ...