李卓原

2.3

... ... @@ -6,6 +6,9 @@
* @Description: Update log
-->
# 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.
... ...
... ... @@ -49,16 +49,16 @@ Be sure to set the page in the MaterialApp's home/initialRoute(ie the entry file
//fill in the screen size of the device in the design
//default value : width : 1080px , height:1920px , allowFontScaling:false
ScreenUtil.init(context); //flutter_screenuitl < 1.2
ScreenUtil.init(); //flutter_screenuitl >= 1.2
ScreenUtil.init(context); ~~//flutter_screenuitl < 1.2~~
~~ScreenUtil.init(); //flutter_screenuitl >= 1.2~~
//If the design is based on the size of the iPhone6 ​​(iPhone6 ​​750*1334)
ScreenUtil.init(context, width: 750, height: 1334); //flutter_screenuitl < 1.2
ScreenUtil.init(width: 750, height: 1334); //flutter_screenuitl >= 1.2
ScreenUtil.init(context, width: 750, height: 1334); ~~//flutter_screenuitl < 1.2~~
~~ScreenUtil.init(width: 750, height: 1334); //flutter_screenuitl >= 1.2~~
//If you want to set the font size is scaled according to the system's "font size" assist option
ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: true); //flutter_screenuitl < 1.2
ScreenUtil.init(width: 750, height: 1334, allowFontScaling: true); //flutter_screenuitl >= 1.2
ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: true); ~~//flutter_screenuitl < 1.2~~
~~ScreenUtil.init(width: 750, height: 1334, allowFontScaling: true); //flutter_screenuitl >= 1.2~~
```
... ...
... ... @@ -53,16 +53,16 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
//填入设计稿中设备的屏幕尺寸
//默认 width : 1080px , height:1920px , allowFontScaling:false
ScreenUtil.init(context); //flutter_screenuitl < 1.2
ScreenUtil.init(); //flutter_screenuitl >= 1.2
ScreenUtil.init(context); ~~//flutter_screenuitl < 1.2~~
~~ScreenUtil.init(); //flutter_screenuitl >= 1.2~~
//假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334)
ScreenUtil.init(context, width: 750, height: 1334); //flutter_screenuitl < 1.2
ScreenUtil.init(width: 750, height: 1334); //flutter_screenuitl >= 1.2
ScreenUtil.init(context, width: 750, height: 1334); ~~//flutter_screenuitl < 1.2~~
~~ScreenUtil.init(width: 750, height: 1334); //flutter_screenuitl >= 1.2~~
//设置字体大小根据系统的“字体大小”辅助选项来进行缩放,默认为false
ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: true); //flutter_screenuitl < 1.2
ScreenUtil.init(width: 750, height: 1334, allowFontScaling: true); //flutter_screenuitl >= 1.2
ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: true); ~~//flutter_screenuitl < 1.2~~
~~ScreenUtil.init(width: 750, height: 1334, allowFontScaling: true); //flutter_screenuitl >= 1.2~~
```
... ...
... ... @@ -49,16 +49,16 @@ Certifique-se de definir as dimensões na paginal inicial do MaterialApp (ou sej
//Preencha o tamanho da tela do dispositivo no protótipo de design
//Valor padrão: width : 1080px , height:1920px , allowFontScaling:false
ScreenUtil.init(context); //flutter_screenuitl < 1.2
ScreenUtil.init(); //flutter_screenuitl >= 1.2
ScreenUtil.init(context); ~~//flutter_screenuitl < 1.2~~
~~ScreenUtil.init(); //flutter_screenuitl >= 1.2~~
//Se o design é baseado no iPhone6 ​​(iPhone6 ​​750*1334)
ScreenUtil.init(context, width: 750, height: 1334); //flutter_screenuitl < 1.2
ScreenUtil.init(width: 750, height: 1334); //flutter_screenuitl >= 1.2
ScreenUtil.init(context, width: 750, height: 1334); ~~//flutter_screenuitl < 1.2~~
~~ScreenUtil.init(width: 750, height: 1334); //flutter_screenuitl >= 1.2~~
//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(context, width: 750, height: 1334, allowFontScaling: true); //flutter_screenuitl < 1.2
ScreenUtil.init(width: 750, height: 1334, allowFontScaling: true); //flutter_screenuitl >= 1.2
ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: true); ~~//flutter_screenuitl < 1.2~~
~~ScreenUtil.init(width: 750, height: 1334, allowFontScaling: true); //flutter_screenuitl >= 1.2~~
```
... ...
org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true
\ No newline at end of file
... ...
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=D:\Develop\flutter"
export "FLUTTER_APPLICATION_PATH=D:\Develop\Project\flutter_screenutil\example"
export "FLUTTER_TARGET=lib\main.dart"
export "FLUTTER_ROOT=/Users/lizhuoyuan/Development/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/lizhuoyuan/Development/Project/flutter_screenutil/example"
export "FLUTTER_TARGET=lib/main.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build\ios"
export "OTHER_LDFLAGS=$(inherited) -framework Flutter"
export "FLUTTER_FRAMEWORK_DIR=D:\Develop\flutter\bin\cache\artifacts\engine\ios"
export "SYMROOT=${SOURCE_ROOT}/../build/ios"
export "FLUTTER_FRAMEWORK_DIR=/Users/lizhuoyuan/Development/flutter/bin/cache/artifacts/engine/ios"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
... ...
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
... ... @@ -26,7 +28,7 @@ class _MyHomePageState extends State<MyHomePage> {
@override
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)
ScreenUtil.init(width: 750, height: 1334, allowFontScaling: false);
ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: false);
return ExampleWidget(title: 'FlutterScreenUtil Demo');
}
... ... @@ -44,7 +46,7 @@ class ExampleWidget extends StatefulWidget {
class _ExampleWidgetState extends State<ExampleWidget> {
@override
Widget build(BuildContext context) {
printScreenInformation();
//printScreenInformation();
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
... ... @@ -123,7 +125,8 @@ class _ExampleWidgetState extends State<ExampleWidget> {
floatingActionButton: FloatingActionButton(
child: Icon(Icons.title),
onPressed: () {
ScreenUtil.init(width: 1500, height: 1334, allowFontScaling: false);
ScreenUtil.init(context,
width: 1500, height: 1334, allowFontScaling: false);
setState(() {});
},
),
... ...
... ... @@ -31,7 +31,7 @@ class _MyHomePageState extends State<MyHomePage> {
Widget build(BuildContext context) {
//设置适配尺寸 (填入设计稿中设备的屏幕尺寸) 此处假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334)
ScreenUtil.init(width: 750, height: 1334, allowFontScaling: false);
ScreenUtil.init(context,width: 750, height: 1334, allowFontScaling: false);
return ExampleWidget(title: 'FlutterScreenUtil示例');
}
... ... @@ -126,7 +126,7 @@ class _ExampleWidgetState extends State<ExampleWidget> {
floatingActionButton: FloatingActionButton(
child: Icon(Icons.title),
onPressed: () {
ScreenUtil.init(width: 1500, height: 1334, allowFontScaling: false);
ScreenUtil.init(context,width: 1500, height: 1334, allowFontScaling: false);
setState(() {});
},
),
... ...
... ... @@ -3,7 +3,7 @@
* email: zhuoyuan93@gmail.com
*/
import 'dart:ui';
import 'package:flutter/material.dart';
class ScreenUtil {
static ScreenUtil _instance;
... ... @@ -19,7 +19,7 @@ class ScreenUtil {
/// allowFontScaling Specifies whether fonts should scale to respect Text Size accessibility settings. The default is false.
bool allowFontScaling;
static double _screenWidth;
static double _screenWidth;
static double _screenHeight;
static double _pixelRatio;
static double _statusBarHeight;
... ... @@ -32,22 +32,24 @@ class ScreenUtil {
return _instance;
}
static void init(
static void init(BuildContext context,
{num width = defaultWidth,
num height = defaultHeight,
bool allowFontScaling = false}) {
num height = defaultHeight,
bool allowFontScaling = false}) {
if (_instance == null) {
_instance = ScreenUtil._();
}
_instance.uiWidthPx = width;
_instance.uiHeightPx = height;
_instance.allowFontScaling = allowFontScaling;
_pixelRatio = window.devicePixelRatio;
_screenWidth = window.physicalSize.width;
_screenHeight = window.physicalSize.height;
_statusBarHeight = window.padding.top;
_bottomBarHeight = window.padding.bottom;
_textScaleFactor = window.textScaleFactor;
MediaQueryData mediaQuery = MediaQuery.of(context);
_pixelRatio = mediaQuery.devicePixelRatio;
_screenWidth = mediaQuery.size.width;
_screenHeight = mediaQuery.size.height;
_statusBarHeight = mediaQuery.padding.top;
_bottomBarHeight = mediaQuery.padding.bottom;
_textScaleFactor = mediaQuery.textScaleFactor;
}
/// 每个逻辑像素的字体像素数,字体的缩放比例
... ... @@ -60,27 +62,23 @@ class ScreenUtil {
/// 当前设备宽度 dp
/// The horizontal extent of this size.
static double get screenWidth => _screenWidth / _pixelRatio;
static double get screenWidth => _screenWidth;
///当前设备高度 dp
///The vertical extent of this size. dp
static double get screenHeight => _screenHeight / _pixelRatio;
static double get screenHeight => _screenHeight;
/// 当前设备宽度 px
/// The vertical extent of this size. px
static double get screenWidthPx => _screenWidth;
static double get screenWidthPx => _screenWidth * _pixelRatio;
/// 当前设备高度 px
/// The vertical extent of this size. px
static double get screenHeightPx => _screenHeight;
/// 状态栏高度 dp 刘海屏会更高
/// The offset from the top
static double get statusBarHeight => _statusBarHeight / _pixelRatio;
static double get screenHeightPx => _screenHeight * _pixelRatio;
/// 状态栏高度 dp 刘海屏会更高
/// The offset from the top
static double get statusBarHeightPx => _statusBarHeight;
static double get statusBarHeight => _statusBarHeight;
/// 底部安全区距离 dp
/// The offset from the bottom.
... ... @@ -88,9 +86,9 @@ class ScreenUtil {
/// 实际的dp与UI设计px的比例
/// The ratio of the actual dp to the design draft px
double get scaleWidth => screenWidth / uiWidthPx;
double get scaleWidth => _screenWidth / uiWidthPx;
double get scaleHeight => screenHeight / uiHeightPx;
double get scaleHeight => _screenHeight / uiHeightPx;
double get scaleText => scaleWidth;
... ... @@ -119,9 +117,9 @@ class ScreenUtil {
num setSp(num fontSize, {bool allowFontScalingSelf}) =>
allowFontScalingSelf == null
? (allowFontScaling
? (fontSize * scaleText)
: ((fontSize * scaleText) / _textScaleFactor))
? (fontSize * scaleText)
: ((fontSize * scaleText) / _textScaleFactor))
: (allowFontScalingSelf
? (fontSize * scaleText)
: ((fontSize * scaleText) / _textScaleFactor));
? (fontSize * scaleText)
: ((fontSize * scaleText) / _textScaleFactor));
}
... ...
name: flutter_screenutil
description: A flutter plugin for adapting screen and font size.Guaranteed to look good on different models
version: 2.2.0
version: 2.3.0
homepage: https://github.com/OpenFlutter/flutter_screenutil
environment:
... ...