Showing
1 changed file
with
3 additions
and
1 deletions
@@ -3,6 +3,8 @@ | @@ -3,6 +3,8 @@ | ||
3 | * email: zhuoyuan93@gmail.com | 3 | * email: zhuoyuan93@gmail.com |
4 | */ | 4 | */ |
5 | 5 | ||
6 | +import 'dart:ui' as ui; | ||
7 | + | ||
6 | import 'package:flutter/material.dart'; | 8 | import 'package:flutter/material.dart'; |
7 | 9 | ||
8 | class ScreenUtil { | 10 | class ScreenUtil { |
@@ -42,7 +44,7 @@ class ScreenUtil { | @@ -42,7 +44,7 @@ class ScreenUtil { | ||
42 | _screenWidth = constraints.maxWidth; | 44 | _screenWidth = constraints.maxWidth; |
43 | _screenHeight = constraints.maxHeight; | 45 | _screenHeight = constraints.maxHeight; |
44 | 46 | ||
45 | - var mediaQuery = WidgetsBinding.instance.window; | 47 | + var mediaQuery = WidgetsBinding.instance?.window ?? ui.window; |
46 | _pixelRatio = mediaQuery.devicePixelRatio; | 48 | _pixelRatio = mediaQuery.devicePixelRatio; |
47 | _statusBarHeight = mediaQuery.padding.top; | 49 | _statusBarHeight = mediaQuery.padding.top; |
48 | _bottomBarHeight = mediaQuery.padding.bottom; | 50 | _bottomBarHeight = mediaQuery.padding.bottom; |
-
Please register or login to post a comment