Skip to content

Commit 3888802

Browse files
committed
Create Initialization Background Color
*The first frame initialization color can now be customized.
1 parent 67e9056 commit 3888802

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

lib/responsive_wrapper.dart

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,20 @@ class ResponsiveWrapper extends StatefulWidget {
5252
final String defaultName;
5353
final bool defaultScale;
5454
final double defaultScaleFactor;
55+
56+
/// An optional background widget to insert behind
57+
/// the responsive content. The background widget
58+
/// expands to fill the entire space of the wrapper and
59+
/// is not resized.
60+
/// Can be used to set a background image, pattern,
61+
/// or solid fill.
5562
final Widget background;
63+
64+
/// First frame initialization default background color.
65+
/// Because layout initialization is delayed by 1 frame,
66+
/// a solid background color is displayed instead.
67+
/// Default white.
68+
final Color backgroundColor;
5669
final MediaQueryData mediaQueryData;
5770
final bool shrinkWrap;
5871
final bool debugLog;
@@ -68,6 +81,7 @@ class ResponsiveWrapper extends StatefulWidget {
6881
this.defaultScale = false,
6982
this.defaultScaleFactor = 1,
7083
this.background,
84+
this.backgroundColor,
7185
this.mediaQueryData,
7286
this.shrinkWrap = true,
7387
this.debugLog = false,
@@ -88,6 +102,7 @@ class ResponsiveWrapper extends StatefulWidget {
88102
bool defaultScale = false,
89103
double defaultScaleFactor = 1,
90104
Widget background,
105+
Color backgroundColor,
91106
MediaQueryData mediaQueryData,
92107
bool debugLog = false,
93108
}) {
@@ -100,6 +115,7 @@ class ResponsiveWrapper extends StatefulWidget {
100115
defaultScale: defaultScale,
101116
defaultScaleFactor: defaultScaleFactor,
102117
background: background,
118+
backgroundColor: backgroundColor,
103119
mediaQueryData: mediaQueryData,
104120
shrinkWrap: false,
105121
debugLog: debugLog,
@@ -349,7 +365,10 @@ class _ResponsiveWrapperState extends State<ResponsiveWrapper>
349365
Widget build(BuildContext context) {
350366
return (screenWidth ==
351367
0) // Initialization check. Window measurements not available until postFrameCallback.
352-
? Container(color: Color(0x00FFFFFF))
368+
? (widget.backgroundColor ??
369+
Container(
370+
color: Color(
371+
0xFFFFFFFF))) // First frame empty background color or default white.
353372
: InheritedResponsiveWrapper(
354373
data: ResponsiveWrapperData.fromResponsiveWrapper(this),
355374
child: Stack(

0 commit comments

Comments
 (0)