Skip to content

Commit

Permalink
2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
李卓原 committed Jul 16, 2020
1 parent caed30e commit 108ef8d
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 56 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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~~
```

Expand Down
12 changes: 6 additions & 6 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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~~
```

Expand Down
12 changes: 6 additions & 6 deletions README_PT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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~~
```

Expand Down
2 changes: 2 additions & 0 deletions example/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true
Empty file modified example/android/gradlew
100644 → 100755
Empty file.
11 changes: 5 additions & 6 deletions example/ios/Flutter/flutter_export_environment.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#!/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"
9 changes: 6 additions & 3 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

Expand Down Expand Up @@ -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');
}
Expand All @@ -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),
Expand Down Expand Up @@ -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(() {});
},
),
Expand Down
4 changes: 2 additions & 2 deletions example/lib/main_zh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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示例');
}
Expand Down Expand Up @@ -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(() {});
},
),
Expand Down
50 changes: 24 additions & 26 deletions lib/screenutil.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* email: zhuoyuan93@gmail.com
*/

import 'dart:ui';
import 'package:flutter/material.dart';

class ScreenUtil {
static ScreenUtil _instance;
Expand All @@ -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;
Expand All @@ -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;
}

/// 每个逻辑像素的字体像素数,字体的缩放比例
Expand All @@ -60,37 +62,33 @@ 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.
static double get bottomBarHeight => _bottomBarHeight;

/// 实际的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;

Expand Down Expand Up @@ -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));
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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:
Expand Down

0 comments on commit 108ef8d

Please sign in to comment.