Showing
1 changed file
with
4 additions
and
2 deletions
@@ -55,11 +55,13 @@ class ScreenUtil { | @@ -55,11 +55,13 @@ class ScreenUtil { | ||
55 | 55 | ||
56 | /// 每个逻辑像素的字体像素数,字体的缩放比例 | 56 | /// 每个逻辑像素的字体像素数,字体的缩放比例 |
57 | /// The number of font pixels for each logical pixel. | 57 | /// The number of font pixels for each logical pixel. |
58 | - double get textScaleFactor => MediaQuery.of(context!).textScaleFactor; | 58 | + double get textScaleFactor => |
59 | + context != null ? MediaQuery.of(context!).textScaleFactor : 1; | ||
59 | 60 | ||
60 | /// 设备的像素密度 | 61 | /// 设备的像素密度 |
61 | /// The size of the media in logical pixels (e.g, the size of the screen). | 62 | /// The size of the media in logical pixels (e.g, the size of the screen). |
62 | - double? get pixelRatio => MediaQuery.of(context!).devicePixelRatio; | 63 | + double? get pixelRatio => |
64 | + context != null ? MediaQuery.of(context!).devicePixelRatio : 1; | ||
63 | 65 | ||
64 | /// 当前设备宽度 dp | 66 | /// 当前设备宽度 dp |
65 | /// The horizontal extent of this size. | 67 | /// The horizontal extent of this size. |
-
Please register or login to post a comment