Showing
4 changed files
with
33 additions
and
15 deletions
@@ -27,14 +27,29 @@ dependencies: | @@ -27,14 +27,29 @@ dependencies: | ||
27 | import 'package:flutter_screenutil/flutter_screenutil.dart'; | 27 | import 'package:flutter_screenutil/flutter_screenutil.dart'; |
28 | ``` | 28 | ``` |
29 | 29 | ||
30 | -### Initialize the setup size | 30 | +### 属性 |
31 | + | ||
32 | +|Property|Type|Default Value|Description| | ||
33 | +|:---|:---|:---|:---| | ||
34 | +|width|int|1080px|The width of the device in the design draft, in px| | ||
35 | +|height|int|1920px|The height of the device in the design draft, in px| | ||
36 | +|allowFontScaling|bool|false|Sets whether the font size is scaled according to the system's "font size" assist option| | ||
37 | + | ||
38 | +### Initialize and set the fit size and font size to scale according to the system's "font size" accessibility option | ||
31 | Please set the width and height of the design draft before use, the width and height of the design draft (unit px). | 39 | Please set the width and height of the design draft before use, the width and height of the design draft (unit px). |
32 | Be sure to set the page in the MaterialApp's home(ie the entry file, just set it once) to ensure that the fit size is set before each use: | 40 | Be sure to set the page in the MaterialApp's home(ie the entry file, just set it once) to ensure that the fit size is set before each use: |
33 | 41 | ||
34 | ``` | 42 | ``` |
35 | -//Set the fit size (fill in the screen size of the device in the design) | 43 | +//default value : width : 1080px , height:1920px , allowFontScaling:false |
44 | +ScreenUtil.instance = ScreenUtil()..init(context); | ||
45 | + | ||
46 | +//fill in the screen size of the device in the design | ||
36 | //If the design is based on the size of the iPhone6 (iPhone6 750*1334) | 47 | //If the design is based on the size of the iPhone6 (iPhone6 750*1334) |
37 | ScreenUtil.instance = ScreenUtil(width: 750, height: 1334)..init(context); | 48 | ScreenUtil.instance = ScreenUtil(width: 750, height: 1334)..init(context); |
49 | + | ||
50 | +//If you wang to set the font size is scaled according to the system's "font size" assist option | ||
51 | +ScreenUtil.instance = ScreenUtil(width: 750, height: 1334, allowFontScaling: true)..init(context); | ||
52 | + | ||
38 | ``` | 53 | ``` |
39 | 54 | ||
40 | ### Use: | 55 | ### Use: |
@@ -32,12 +32,7 @@ dependencies: | @@ -32,12 +32,7 @@ dependencies: | ||
32 | import 'package:flutter_screenutil/flutter_screenutil.dart'; | 32 | import 'package:flutter_screenutil/flutter_screenutil.dart'; |
33 | ``` | 33 | ``` |
34 | 34 | ||
35 | -### 初始化设置尺寸 | ||
36 | -在使用之前请设置好设计稿的宽度和高度,传入设计稿的宽度和高度(单位px) | ||
37 | - | ||
38 | -一定在MaterialApp的home中的页面设置(即入口文件,只需设置一次),以保证在每次使用之前设置好了适配尺寸: | ||
39 | - | ||
40 | -#### 属性 | 35 | +### 属性 |
41 | 36 | ||
42 | |属性|类型|默认值|描述| | 37 | |属性|类型|默认值|描述| |
43 | |:---|:---|:---|:---| | 38 | |:---|:---|:---|:---| |
@@ -45,12 +40,19 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; | @@ -45,12 +40,19 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; | ||
45 | |height|int|1920px|设计稿中设备的高度,单位px| | 40 | |height|int|1920px|设计稿中设备的高度,单位px| |
46 | |allowFontScaling|bool|false|设置字体大小是否根据系统的“字体大小”辅助选项来进行缩放| | 41 | |allowFontScaling|bool|false|设置字体大小是否根据系统的“字体大小”辅助选项来进行缩放| |
47 | 42 | ||
43 | +### 初始化并设置适配尺寸及字体大小是否根据系统的“字体大小”辅助选项来进行缩放 | ||
44 | +在使用之前请设置好设计稿的宽度和高度,传入设计稿的宽度和高度(单位px) | ||
45 | +一定在MaterialApp的home中的页面设置(即入口文件,只需设置一次),以保证在每次使用之前设置好了适配尺寸: | ||
46 | + | ||
48 | ``` | 47 | ``` |
49 | -//设置适配尺寸 (填入设计稿中设备的屏幕尺寸) 假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334) | ||
50 | -//设置字体大小是否根据系统的“字体大小”辅助选项来进行缩放 , 默认为 false , 字体不随着系统的“字体大小”辅助选项来进行缩放 | ||
51 | - ScreenUtil.instance = ScreenUtil()..init(context); | ||
52 | - ScreenUtil.instance = ScreenUtil(width: 750, height: 1334)..init(context); | ||
53 | - ScreenUtil.instance = ScreenUtil(width: 750, height: 1334, allowFontScaling: false)..init(context); | 48 | +//默认 width : 1080px , height:1920px , allowFontScaling:false |
49 | +ScreenUtil.instance = ScreenUtil()..init(context); | ||
50 | + | ||
51 | +//填入设计稿中设备的屏幕尺寸 , 假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334) | ||
52 | +ScreenUtil.instance = ScreenUtil(width: 750, height: 1334)..init(context); | ||
53 | + | ||
54 | +//设置字体大小根据系统的“字体大小”辅助选项来进行缩放,默认为false : 字体不随着系统的“字体大小”辅助选项来进行缩放 | ||
55 | +ScreenUtil.instance = ScreenUtil(width: 750, height: 1334, allowFontScaling: true)..init(context); | ||
54 | 56 | ||
55 | ``` | 57 | ``` |
56 | 58 |
@@ -32,6 +32,7 @@ class _MyHomePageState extends State<MyHomePage> { | @@ -32,6 +32,7 @@ class _MyHomePageState extends State<MyHomePage> { | ||
32 | Widget build(BuildContext context) { | 32 | Widget build(BuildContext context) { |
33 | ///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) | 33 | ///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) |
34 | ScreenUtil.instance = ScreenUtil(width: 750, height: 1334)..init(context); | 34 | ScreenUtil.instance = ScreenUtil(width: 750, height: 1334)..init(context); |
35 | + | ||
35 | print('Device width:${ScreenUtil.screenWidth}'); //Device width | 36 | print('Device width:${ScreenUtil.screenWidth}'); //Device width |
36 | print('Device height:${ScreenUtil.screenHeight}'); //Device height | 37 | print('Device height:${ScreenUtil.screenHeight}'); //Device height |
37 | print( | 38 | print( |
@@ -24,8 +24,8 @@ class ScreenUtil { | @@ -24,8 +24,8 @@ class ScreenUtil { | ||
24 | static double _textScaleFactor; | 24 | static double _textScaleFactor; |
25 | 25 | ||
26 | ScreenUtil({ | 26 | ScreenUtil({ |
27 | - this.width, | ||
28 | - this.height, | 27 | + this.width = 1080, |
28 | + this.height = 1920, | ||
29 | this.allowFontScaling = false, | 29 | this.allowFontScaling = false, |
30 | }); | 30 | }); |
31 | 31 |
-
Please register or login to post a comment