@@ -165,7 +165,21 @@ class _ResponsiveWrapperState extends State<ResponsiveWrapper>
165165
166166 /// Get screen height calculations.
167167 double screenHeight = 1 ;
168- double getScreenHeight () => windowHeight;
168+ double getScreenHeight () {
169+ // Check if screenWidth exceeds maxWidth.
170+ if (widget.maxWidth != null ) if (windowWidth > widget.maxWidth) {
171+ // Check if there is an active breakpoint with scale set to true.
172+ if (activeBreakpoint != null &&
173+ activeBreakpoint.breakpoint > widget.maxWidth &&
174+ activeBreakpoint.scale) {
175+ // Scale screen height by the amount the width was scaled.
176+ return windowHeight / (screenWidth / widget.maxWidth);
177+ }
178+ }
179+
180+ // Return default window height as height.
181+ return windowHeight;
182+ }
169183
170184 ResponsiveBreakpoint activeBreakpoint;
171185
@@ -198,6 +212,10 @@ class _ResponsiveWrapperState extends State<ResponsiveWrapper>
198212 if (activeBreakpoint.scale == false )
199213 return screenWidth / activeBreakpoint.scaleFactor;
200214
215+ // Screen is larger than max width. Scale from max width.
216+ if (widget.maxWidth != null ) if (activeBreakpoint.breakpoint >
217+ widget.maxWidth) return widget.maxWidth / activeBreakpoint.scaleFactor;
218+
201219 // Return width from breakpoint with scale factor applied.
202220 return activeBreakpoint.breakpoint / activeBreakpoint.scaleFactor;
203221 }
@@ -241,6 +259,13 @@ class _ResponsiveWrapperState extends State<ResponsiveWrapper>
241259 if (activeBreakpoint.scale == false )
242260 return screenHeight / activeBreakpoint.scaleFactor;
243261
262+ // Screen is larger than max width. Calculate height
263+ // from max width.
264+ if (widget.maxWidth != null ) if (activeBreakpoint.breakpoint >
265+ widget.maxWidth) {
266+ return screenHeight / activeBreakpoint.scaleFactor;
267+ }
268+
244269 // Find width adjustment scale to proportionally scale height.
245270 // If screenWidth is scaled 1.5x larger than the breakpoint,
246271 // decrease screenHeight by 33.33% to proportionally scale content.
@@ -260,6 +285,7 @@ class _ResponsiveWrapperState extends State<ResponsiveWrapper>
260285 /// Default fullscreen enabled.
261286 get fullscreen => widget.maxWidth == null ;
262287
288+ /// Calculate updated dimensions.
263289 void setDimensions () {
264290 devicePixelRatio = getDevicePixelRatio ();
265291 windowWidth = getWindowWidth ();
@@ -299,15 +325,13 @@ class _ResponsiveWrapperState extends State<ResponsiveWrapper>
299325
300326 @override
301327 void didChangeMetrics () {
302- setDimensions ();
303- setState (() {});
304- }
305-
306- @override
307- void didUpdateWidget (ResponsiveWrapper oldWidget) {
308- super .didUpdateWidget (oldWidget);
309- setDimensions ();
310- setState (() {});
328+ super .didChangeMetrics ();
329+ // Required MediaQueryData is only updated
330+ // on the next frame.
331+ WidgetsBinding .instance.addPostFrameCallback ((_) {
332+ setDimensions ();
333+ setState (() {});
334+ });
311335 }
312336
313337 @override
@@ -483,5 +507,6 @@ class ResponsiveBreakpoint {
483507 {@required this .breakpoint,
484508 this .scale = false ,
485509 this .scaleFactor = 1 ,
486- this .name});
510+ this .name})
511+ : assert (breakpoint != null );
487512}
0 commit comments