Mounir Bouaiche
Committed by GitHub

Merge pull request #378 from Mounir-Bouaiche/master

Bug Fix: Reaching context that no longer used. (state: DEFUNCT)
@@ -77,15 +77,19 @@ class ScreenUtil { @@ -77,15 +77,19 @@ class ScreenUtil {
77 static void init( 77 static void init(
78 BuildContext? context, { 78 BuildContext? context, {
79 Orientation? orientation, 79 Orientation? orientation,
  80 + Size? deviceSize,
80 Size designSize = defaultSize, 81 Size designSize = defaultSize,
81 bool splitScreenMode = false, 82 bool splitScreenMode = false,
82 bool minTextAdapt = false, 83 bool minTextAdapt = false,
83 }) { 84 }) {
84 - final deviceData = context != null  
85 - ? MediaQuery.maybeOf(context).nonEmptySizeOrNull() 85 + final mediaQueryContext =
  86 + context?.getElementForInheritedWidgetOfExactType<MediaQuery>();
  87 +
  88 + final deviceData = mediaQueryContext != null
  89 + ? MediaQuery.of(context!).nonEmptySizeOrNull()
86 : null; 90 : null;
87 91
88 - Size deviceSize = deviceData?.size ?? designSize; 92 + deviceSize ??= deviceData?.size ?? designSize;
89 orientation ??= deviceData?.orientation ?? 93 orientation ??= deviceData?.orientation ??
90 (deviceSize.width > deviceSize.height 94 (deviceSize.width > deviceSize.height
91 ? Orientation.landscape 95 ? Orientation.landscape
@@ -98,7 +102,7 @@ class ScreenUtil { @@ -98,7 +102,7 @@ class ScreenUtil {
98 .._orientation = orientation 102 .._orientation = orientation
99 .._screenWidth = deviceSize.width 103 .._screenWidth = deviceSize.width
100 .._screenHeight = deviceSize.height 104 .._screenHeight = deviceSize.height
101 - ..context = context; 105 + ..context = mediaQueryContext;
102 } 106 }
103 107
104 ///获取屏幕方向 108 ///获取屏幕方向