@@ -118,13 +118,14 @@ class ResponsiveWrapper extends StatefulWidget {
118118 /// is not resized.
119119 /// Can be used to set a background image, pattern,
120120 /// or solid fill.
121+ /// Overrides [backgroundColor] if a widget is set.
121122 final Widget ? background;
122123
123124 /// First frame initialization default background color.
124125 /// Because layout initialization is delayed by 1 frame,
125126 /// a solid background color is displayed instead.
126- /// By default uses ` background` widget if it is set,
127- /// otherwise uses white color .
127+ /// Is overridden by [ background] if set.
128+ /// Defaults to a white background .
128129 final Color ? backgroundColor;
129130 final MediaQueryData ? mediaQueryData;
130131 final bool shrinkWrap;
@@ -659,39 +660,41 @@ class _ResponsiveWrapperState extends State<ResponsiveWrapper>
659660 // Platform initialization requires context.
660661 setPlatform ();
661662
662- return (screenWidth ==
663- 0 ) // Initialization check. Window measurements not available until postFrameCallback.
664- ? buildBackgroundColorWidget (widget
665- .backgroundColor) // First frame with empty background.
666- : InheritedResponsiveWrapper (
667- data: ResponsiveWrapperData .fromResponsiveWrapper (this ),
668- child: Stack (
669- alignment: widget.alignment,
670- children: [
671- widget.background ?? SizedBox .shrink (),
672- MediaQuery (
673- data: calculateMediaQueryData (),
674- child: SizedBox (
675- width: screenWidth,
676- child: FittedBox (
677- fit: BoxFit .fitWidth,
678- alignment: Alignment .topCenter,
679- child: Container (
680- width: scaledWidth,
681- height: (widget.shrinkWrap == true &&
682- widget.mediaQueryData == null )
683- ? null
684- : scaledHeight,
685- // Shrink wrap height if no MediaQueryData is passed.
686- alignment: Alignment .center,
687- child: widget.child,
688- ),
689- ),
690- ),
663+ // Initialization check. Window measurements not available until postFrameCallback.
664+ // Return first frame with empty background.
665+ if (screenWidth == 0 )
666+ return buildBackground (
667+ background: widget.background, color: widget.backgroundColor);
668+
669+ return InheritedResponsiveWrapper (
670+ data: ResponsiveWrapperData .fromResponsiveWrapper (this ),
671+ child: Stack (
672+ alignment: widget.alignment,
673+ children: [
674+ widget.background ?? SizedBox .shrink (),
675+ MediaQuery (
676+ data: calculateMediaQueryData (),
677+ child: SizedBox (
678+ width: screenWidth,
679+ child: FittedBox (
680+ fit: BoxFit .fitWidth,
681+ alignment: Alignment .topCenter,
682+ child: Container (
683+ width: scaledWidth,
684+ height: (widget.shrinkWrap == true &&
685+ widget.mediaQueryData == null )
686+ ? null
687+ : scaledHeight,
688+ // Shrink wrap height if no MediaQueryData is passed.
689+ alignment: Alignment .center,
690+ child: widget.child,
691691 ),
692- ] ,
692+ ) ,
693693 ),
694- );
694+ ),
695+ ],
696+ ),
697+ );
695698 }
696699
697700 /// Return updated [MediaQueryData] values.
@@ -718,11 +721,13 @@ class _ResponsiveWrapperState extends State<ResponsiveWrapper>
718721 padding: scaledPadding);
719722 }
720723
721- /// Builds a container with [color] .
724+ /// Builds a container with widget [background] or [color] .
722725 /// Defaults to a white background.
723- Widget buildBackgroundColorWidget (Color ? color) {
724- if (color == null ) return widget.background ?? Container (color: Color (0xFFFFFFFF ));
725- return Container (color: color);
726+ Widget buildBackground ({Widget ? background, Color ? color}) {
727+ if (background != null ) return background;
728+ if (color != null ) return Container (color: color);
729+
730+ return Container (color: Colors .white);
726731 }
727732}
728733
0 commit comments