Showing
1 changed file
with
9 additions
and
1 deletions
@@ -8,6 +8,8 @@ import 'dart:ui' as ui show FlutterView; | @@ -8,6 +8,8 @@ import 'dart:ui' as ui show FlutterView; | ||
8 | 8 | ||
9 | import 'package:flutter/widgets.dart'; | 9 | import 'package:flutter/widgets.dart'; |
10 | 10 | ||
11 | +typedef FontSizeResolver = double Function(num fontSize, ScreenUtil instance); | ||
12 | + | ||
11 | class ScreenUtil { | 13 | class ScreenUtil { |
12 | static const Size defaultSize = Size(360, 690); | 14 | static const Size defaultSize = Size(360, 690); |
13 | static ScreenUtil _instance = ScreenUtil._(); | 15 | static ScreenUtil _instance = ScreenUtil._(); |
@@ -22,6 +24,7 @@ class ScreenUtil { | @@ -22,6 +24,7 @@ class ScreenUtil { | ||
22 | late bool _minTextAdapt; | 24 | late bool _minTextAdapt; |
23 | late MediaQueryData _data; | 25 | late MediaQueryData _data; |
24 | late bool _splitScreenMode; | 26 | late bool _splitScreenMode; |
27 | + FontSizeResolver? fontSizeResolver; | ||
25 | 28 | ||
26 | ScreenUtil._(); | 29 | ScreenUtil._(); |
27 | 30 | ||
@@ -95,6 +98,7 @@ class ScreenUtil { | @@ -95,6 +98,7 @@ class ScreenUtil { | ||
95 | bool? splitScreenMode, | 98 | bool? splitScreenMode, |
96 | bool? minTextAdapt, | 99 | bool? minTextAdapt, |
97 | bool? ensureScreenHasSize, | 100 | bool? ensureScreenHasSize, |
101 | + FontSizeResolver? fontSizeResolver, | ||
98 | }) async { | 102 | }) async { |
99 | if (ensureScreenHasSize ?? false) await ScreenUtil.ensureScreenSize(); | 103 | if (ensureScreenHasSize ?? false) await ScreenUtil.ensureScreenSize(); |
100 | 104 | ||
@@ -122,6 +126,7 @@ class ScreenUtil { | @@ -122,6 +126,7 @@ class ScreenUtil { | ||
122 | : Orientation.portrait); | 126 | : Orientation.portrait); |
123 | 127 | ||
124 | _instance | 128 | _instance |
129 | + ..fontSizeResolver = fontSizeResolver ?? _instance.fontSizeResolver | ||
125 | .._minTextAdapt = minTextAdapt ?? _instance._minTextAdapt | 130 | .._minTextAdapt = minTextAdapt ?? _instance._minTextAdapt |
126 | .._splitScreenMode = splitScreenMode ?? _instance._splitScreenMode | 131 | .._splitScreenMode = splitScreenMode ?? _instance._splitScreenMode |
127 | .._orientation = orientation; | 132 | .._orientation = orientation; |
@@ -136,6 +141,7 @@ class ScreenUtil { | @@ -136,6 +141,7 @@ class ScreenUtil { | ||
136 | bool splitScreenMode = false, | 141 | bool splitScreenMode = false, |
137 | bool minTextAdapt = false, | 142 | bool minTextAdapt = false, |
138 | bool ensureScreenSize = false, | 143 | bool ensureScreenSize = false, |
144 | + FontSizeResolver? fontSizeResolver, | ||
139 | }) { | 145 | }) { |
140 | return configure( | 146 | return configure( |
141 | data: MediaQuery.maybeOf(context), | 147 | data: MediaQuery.maybeOf(context), |
@@ -143,6 +149,7 @@ class ScreenUtil { | @@ -143,6 +149,7 @@ class ScreenUtil { | ||
143 | minTextAdapt: minTextAdapt, | 149 | minTextAdapt: minTextAdapt, |
144 | splitScreenMode: splitScreenMode, | 150 | splitScreenMode: splitScreenMode, |
145 | ensureScreenHasSize: ensureScreenSize, | 151 | ensureScreenHasSize: ensureScreenSize, |
152 | + fontSizeResolver: fontSizeResolver, | ||
146 | ); | 153 | ); |
147 | } | 154 | } |
148 | 155 | ||
@@ -217,7 +224,8 @@ class ScreenUtil { | @@ -217,7 +224,8 @@ class ScreenUtil { | ||
217 | ///- [fontSize] UI设计上字体的大小,单位dp. | 224 | ///- [fontSize] UI设计上字体的大小,单位dp. |
218 | ///Font size adaptation method | 225 | ///Font size adaptation method |
219 | ///- [fontSize] The size of the font on the UI design, in dp. | 226 | ///- [fontSize] The size of the font on the UI design, in dp. |
220 | - double setSp(num fontSize) => fontSize * scaleText; | 227 | + double setSp(num fontSize) => |
228 | + fontSizeResolver?.call(fontSize, _instance) ?? fontSize * scaleText; | ||
221 | 229 | ||
222 | Widget setVerticalSpacing(num height) => SizedBox(height: setHeight(height)); | 230 | Widget setVerticalSpacing(num height) => SizedBox(height: setHeight(height)); |
223 | 231 |
-
Please register or login to post a comment