Showing
10 changed files
with
64 additions
and
32 deletions
1 | +# 5.0.3 | ||
2 | + | ||
3 | +- init method add "context" param | ||
4 | +- update ReadMe.md | ||
5 | + | ||
1 | # 5.0.2+1 | 6 | # 5.0.2+1 |
7 | + | ||
2 | - fix splitScreenMode to false | 8 | - fix splitScreenMode to false |
3 | 9 | ||
4 | # 5.0.2 | 10 | # 5.0.2 |
5 | 11 | ||
6 | -- add "minTextAdapt" param , Font adaptation is based on the minimum value of width and height or only based on width(default) | 12 | +- add "minTextAdapt" param , Font adaptation is based on the minimum value of width and height or |
13 | + only based on width(default) | ||
7 | - update readme | 14 | - update readme |
8 | 15 | ||
9 | # 5.0.1+3 | 16 | # 5.0.1+3 |
@@ -70,6 +70,12 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; | @@ -70,6 +70,12 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; | ||
70 | <td>false</td> | 70 | <td>false</td> |
71 | <td>Whether to adapt the text according to the minimum of width and height</td> | 71 | <td>Whether to adapt the text according to the minimum of width and height</td> |
72 | </tr> | 72 | </tr> |
73 | + <tr> | ||
74 | + <td>context</td> | ||
75 | + <td>BuildContext</td> | ||
76 | + <td>null</td> | ||
77 | + <td>If context!=null, screen changes will be more sensitive</td> | ||
78 | + </tr> | ||
73 | </table> | 79 | </table> |
74 | 80 | ||
75 | ### Initialize and set the fit size and font size to scale according to the system's "font size" accessibility option | 81 | ### Initialize and set the fit size and font size to scale according to the system's "font size" accessibility option |
@@ -45,7 +45,8 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; | @@ -45,7 +45,8 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; | ||
45 | |builder|Widget Function()|Container()|一般返回一个MaterialApp类型的Function()| | 45 | |builder|Widget Function()|Container()|一般返回一个MaterialApp类型的Function()| |
46 | |orientation|Orientation|portrait|屏幕方向| | 46 | |orientation|Orientation|portrait|屏幕方向| |
47 | |splitScreenMode|bool|true|支持分屏尺寸| | 47 | |splitScreenMode|bool|true|支持分屏尺寸| |
48 | -|minTextAdapt|bool|false|Whether to adapt the text according to the minimum of width and height| | 48 | +|minTextAdapt|bool|false|是否根据宽度/高度中的最小值适配文字| |
49 | +|context|BuildContext|null|传入context会更灵敏的根据屏幕变化而改变| | ||
49 | 50 | ||
50 | ### 初始化并设置适配尺寸及字体大小是否根据系统的“字体大小”辅助选项来进行缩放 | 51 | ### 初始化并设置适配尺寸及字体大小是否根据系统的“字体大小”辅助选项来进行缩放 |
51 | 在使用之前请设置好设计稿的宽度和高度,传入设计稿的宽度和高度(单位随意,但在使用过程中必须保持一致) | 52 | 在使用之前请设置好设计稿的宽度和高度,传入设计稿的宽度和高度(单位随意,但在使用过程中必须保持一致) |
@@ -42,6 +42,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; | @@ -42,6 +42,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; | ||
42 | |builder|Widget Function()|Container()|Generally returning a Function of MaterialApp type| | 42 | |builder|Widget Function()|Container()|Generally returning a Function of MaterialApp type| |
43 | |orientation|Orientation|portrait|screen orientation| | 43 | |orientation|Orientation|portrait|screen orientation| |
44 | |minTextAdapt|bool|false|Whether to adapt the text according to the minimum of width and height| | 44 | |minTextAdapt|bool|false|Whether to adapt the text according to the minimum of width and height| |
45 | +|context|BuildContext|null|传入context会更灵敏的根据屏幕变化而改变| | ||
45 | 46 | ||
46 | ### 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 | 47 | ### 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 |
47 | Por favor, defina a largura e altura do protótipo de design antes de usar (em pixels). | 48 | Por favor, defina a largura e altura do protótipo de design antes de usar (em pixels). |
1 | #!/bin/sh | 1 | #!/bin/sh |
2 | # This is a generated file; do not edit or check into version control. | 2 | # This is a generated file; do not edit or check into version control. |
3 | -export "FLUTTER_ROOT=C:\flutter" | ||
4 | -export "FLUTTER_APPLICATION_PATH=C:\Users\Avnish\Downloads\flutter_screenutil\example" | 3 | +export "FLUTTER_ROOT=/Users/lizhuoyuan/Development/flutter" |
4 | +export "FLUTTER_APPLICATION_PATH=/Users/lizhuoyuan/Development/Project/flutter_screenutil/example" | ||
5 | export "COCOAPODS_PARALLEL_CODE_SIGN=true" | 5 | export "COCOAPODS_PARALLEL_CODE_SIGN=true" |
6 | -export "FLUTTER_TARGET=lib\main.dart" | 6 | +export "FLUTTER_TARGET=lib/main.dart" |
7 | export "FLUTTER_BUILD_DIR=build" | 7 | export "FLUTTER_BUILD_DIR=build" |
8 | export "FLUTTER_BUILD_NAME=1.0.0" | 8 | export "FLUTTER_BUILD_NAME=1.0.0" |
9 | export "FLUTTER_BUILD_NUMBER=1" | 9 | export "FLUTTER_BUILD_NUMBER=1" |
1 | import 'package:flutter/material.dart'; | 1 | import 'package:flutter/material.dart'; |
2 | import 'package:flutter_screenutil/flutter_screenutil.dart'; | 2 | import 'package:flutter_screenutil/flutter_screenutil.dart'; |
3 | 3 | ||
4 | -void main() => runApp(MyApp()); | 4 | +void main() { |
5 | + WidgetsFlutterBinding.ensureInitialized(); | ||
6 | + runApp(MyApp()); | ||
7 | +} | ||
5 | 8 | ||
6 | class MyApp extends StatelessWidget { | 9 | class MyApp extends StatelessWidget { |
7 | @override | 10 | @override |
@@ -87,7 +90,7 @@ class _HomePageState extends State<HomePage> { | @@ -87,7 +90,7 @@ class _HomePageState extends State<HomePage> { | ||
87 | ], | 90 | ], |
88 | ), | 91 | ), |
89 | Container( | 92 | Container( |
90 | - padding: EdgeInsets.all(ScreenUtil().setWidth(10)), | 93 | + padding: EdgeInsets.all(10.w), |
91 | width: 100.r, | 94 | width: 100.r, |
92 | height: 100.r, | 95 | height: 100.r, |
93 | color: Colors.green, | 96 | color: Colors.green, |
@@ -95,11 +98,10 @@ class _HomePageState extends State<HomePage> { | @@ -95,11 +98,10 @@ class _HomePageState extends State<HomePage> { | ||
95 | 'I am a square with a side length of 100', | 98 | 'I am a square with a side length of 100', |
96 | style: TextStyle( | 99 | style: TextStyle( |
97 | color: Colors.white, | 100 | color: Colors.white, |
98 | - fontSize: ScreenUtil().setSp(12), | 101 | + fontSize: 12.sp, |
99 | ), | 102 | ), |
100 | ), | 103 | ), |
101 | ), | 104 | ), |
102 | - TextField(style: TextStyle(fontSize: 180.sp)), | ||
103 | Text('Device width:${ScreenUtil().screenWidth}dp'), | 105 | Text('Device width:${ScreenUtil().screenWidth}dp'), |
104 | Text('Device height:${ScreenUtil().screenHeight}dp'), | 106 | Text('Device height:${ScreenUtil().screenHeight}dp'), |
105 | Text('Device pixel density:${ScreenUtil().pixelRatio}'), | 107 | Text('Device pixel density:${ScreenUtil().pixelRatio}'), |
@@ -37,6 +37,7 @@ class _HomePageState extends State<HomePage> { | @@ -37,6 +37,7 @@ class _HomePageState extends State<HomePage> { | ||
37 | maxWidth: MediaQuery.of(context).size.width, | 37 | maxWidth: MediaQuery.of(context).size.width, |
38 | maxHeight: MediaQuery.of(context).size.height), | 38 | maxHeight: MediaQuery.of(context).size.height), |
39 | designSize: Size(360, 690), | 39 | designSize: Size(360, 690), |
40 | + context: context, | ||
40 | ); | 41 | ); |
41 | printScreenInformation(); | 42 | printScreenInformation(); |
42 | return Scaffold( | 43 | return Scaffold( |
@@ -31,6 +31,7 @@ class ScreenUtil { | @@ -31,6 +31,7 @@ class ScreenUtil { | ||
31 | 31 | ||
32 | static void init( | 32 | static void init( |
33 | BoxConstraints constraints, { | 33 | BoxConstraints constraints, { |
34 | + BuildContext? context, | ||
34 | Orientation orientation = Orientation.portrait, | 35 | Orientation orientation = Orientation.portrait, |
35 | Size designSize = defaultSize, | 36 | Size designSize = defaultSize, |
36 | bool splitScreenMode = false, | 37 | bool splitScreenMode = false, |
@@ -41,13 +42,20 @@ class ScreenUtil { | @@ -41,13 +42,20 @@ class ScreenUtil { | ||
41 | .._minTextAdapt = minTextAdapt | 42 | .._minTextAdapt = minTextAdapt |
42 | .._orientation = orientation | 43 | .._orientation = orientation |
43 | .._screenWidth = constraints.maxWidth | 44 | .._screenWidth = constraints.maxWidth |
44 | - .._screenHeight = splitScreenMode ? max(constraints.maxHeight, 700) : constraints.maxHeight; | ||
45 | - | ||
46 | - var window = WidgetsBinding.instance?.window ?? ui.window; | ||
47 | - _instance._pixelRatio = window.devicePixelRatio; | ||
48 | - _instance._statusBarHeight = window.padding.top; | ||
49 | - _instance._bottomBarHeight = window.padding.bottom; | ||
50 | - _instance._textScaleFactor = window.textScaleFactor; | 45 | + .._screenHeight = splitScreenMode |
46 | + ? max(constraints.maxHeight, 700) | ||
47 | + : constraints.maxHeight; | ||
48 | + | ||
49 | + var windowData; | ||
50 | + if (context != null) { | ||
51 | + windowData = MediaQuery.of(context); | ||
52 | + } else { | ||
53 | + windowData = WidgetsBinding.instance?.window ?? ui.window; | ||
54 | + } | ||
55 | + _instance._pixelRatio = windowData.devicePixelRatio; | ||
56 | + _instance._statusBarHeight = windowData.padding.top; | ||
57 | + _instance._bottomBarHeight = windowData.padding.bottom; | ||
58 | + _instance._textScaleFactor = windowData.textScaleFactor; | ||
51 | } | 59 | } |
52 | 60 | ||
53 | ///获取屏幕方向 | 61 | ///获取屏幕方向 |
@@ -85,7 +93,8 @@ class ScreenUtil { | @@ -85,7 +93,8 @@ class ScreenUtil { | ||
85 | /// /// The ratio of actual height to UI design | 93 | /// /// The ratio of actual height to UI design |
86 | double get scaleHeight => _screenHeight / uiSize.height; | 94 | double get scaleHeight => _screenHeight / uiSize.height; |
87 | 95 | ||
88 | - double get scaleText => _minTextAdapt ? min(scaleWidth, scaleHeight) : scaleWidth; | 96 | + double get scaleText => |
97 | + _minTextAdapt ? min(scaleWidth, scaleHeight) : scaleWidth; | ||
89 | 98 | ||
90 | /// 根据UI设计的设备宽度适配 | 99 | /// 根据UI设计的设备宽度适配 |
91 | /// 高度也可以根据这个来做适配可以保证不变形,比如你想要一个正方形的时候. | 100 | /// 高度也可以根据这个来做适配可以保证不变形,比如你想要一个正方形的时候. |
@@ -19,19 +19,24 @@ class ScreenUtilInit extends StatelessWidget { | @@ -19,19 +19,24 @@ class ScreenUtilInit extends StatelessWidget { | ||
19 | 19 | ||
20 | @override | 20 | @override |
21 | Widget build(BuildContext context) { | 21 | Widget build(BuildContext context) { |
22 | - return LayoutBuilder(builder: (_, BoxConstraints constraints) { | ||
23 | - if (constraints.maxWidth != 0) { | ||
24 | - final Orientation orientation = constraints.maxWidth > constraints.maxHeight | ||
25 | - ? Orientation.landscape | ||
26 | - : Orientation.portrait; | ||
27 | - ScreenUtil.init(constraints, | ||
28 | - orientation: orientation, | ||
29 | - designSize: designSize, | ||
30 | - splitScreenMode: splitScreenMode, | ||
31 | - minTextAdapt: minTextAdapt); | ||
32 | - return builder(); | ||
33 | - } | ||
34 | - return Container(); | ||
35 | - }); | 22 | + return MediaQuery( |
23 | + data: MediaQueryData(), | ||
24 | + child: LayoutBuilder(builder: (_, BoxConstraints constraints) { | ||
25 | + if (constraints.maxWidth != 0) { | ||
26 | + final Orientation orientation = | ||
27 | + constraints.maxWidth > constraints.maxHeight | ||
28 | + ? Orientation.landscape | ||
29 | + : Orientation.portrait; | ||
30 | + ScreenUtil.init(constraints, | ||
31 | + context: _, | ||
32 | + orientation: orientation, | ||
33 | + designSize: designSize, | ||
34 | + splitScreenMode: splitScreenMode, | ||
35 | + minTextAdapt: minTextAdapt); | ||
36 | + return builder(); | ||
37 | + } | ||
38 | + return Container(); | ||
39 | + }), | ||
40 | + ); | ||
36 | } | 41 | } |
37 | } | 42 | } |
1 | name: flutter_screenutil | 1 | name: flutter_screenutil |
2 | description: A flutter plugin for adapting screen and font size.Guaranteed to look good on different models | 2 | description: A flutter plugin for adapting screen and font size.Guaranteed to look good on different models |
3 | -version: 5.0.2+1 | 3 | +version: 5.0.3 |
4 | homepage: https://github.com/OpenFlutter/flutter_screenutil | 4 | homepage: https://github.com/OpenFlutter/flutter_screenutil |
5 | 5 | ||
6 | environment: | 6 | environment: |
-
Please register or login to post a comment