@@ -102,12 +102,15 @@ class MaterialBanner extends StatefulWidget {
102102 this .elevation,
103103 this .leading,
104104 this .backgroundColor,
105+ this .surfaceTintColor,
106+ this .shadowColor,
107+ this .dividerColor,
105108 this .padding,
106109 this .leadingPadding,
107110 this .forceActionsBelow = false ,
108111 this .overflowAlignment = OverflowBarAlignment .end,
109112 this .animation,
110- this .onVisible
113+ this .onVisible,
111114 }) : assert (elevation == null || elevation >= 0.0 ),
112115 assert (content != null ),
113116 assert (actions != null ),
@@ -153,6 +156,29 @@ class MaterialBanner extends StatefulWidget {
153156 /// also `null` , [ColorScheme.surface] of [ThemeData.colorScheme] is used.
154157 final Color ? backgroundColor;
155158
159+ /// The color used as an overlay on [backgroundColor] to indicate elevation.
160+ ///
161+ /// If null, [MaterialBannerThemeData.surfaceTintColor] is used. If that
162+ /// is also null, the default value is [ColorScheme.surfaceTint] .
163+ ///
164+ /// See [Material.surfaceTintColor] for more details on how this
165+ /// overlay is applied.
166+ final Color ? surfaceTintColor;
167+
168+ /// The color of the shadow below the [MaterialBanner] .
169+ ///
170+ /// If this property is null, then [MaterialBannerThemeData.shadowColor] of
171+ /// [ThemeData.bannerTheme] is used. If that is also null, the default value
172+ /// is null.
173+ final Color ? shadowColor;
174+
175+ /// The color of the divider.
176+ ///
177+ /// If this property is null, then [MaterialBannerThemeData.dividerColor] of
178+ /// [ThemeData.bannerTheme] is used. If that is also null, the default value
179+ /// is [ColorScheme.surfaceVariant] .
180+ final Color ? dividerColor;
181+
156182 /// The amount of space by which to inset the [content] .
157183 ///
158184 /// If the [actions] are below the [content] , this defaults to
@@ -273,6 +299,7 @@ class _MaterialBannerState extends State<MaterialBanner> {
273299
274300 final ThemeData theme = Theme .of (context);
275301 final MaterialBannerThemeData bannerTheme = MaterialBannerTheme .of (context);
302+ final MaterialBannerThemeData defaults = theme.useMaterial3 ? _BannerDefaultsM3 (context) : _BannerDefaultsM2 (context);
276303
277304 final bool isSingleRow = widget.actions.length == 1 && ! widget.forceActionsBelow;
278305 final EdgeInsetsGeometry padding = widget.padding ?? bannerTheme.padding ?? (isSingleRow
@@ -296,16 +323,26 @@ class _MaterialBannerState extends State<MaterialBanner> {
296323 final double elevation = widget.elevation ?? bannerTheme.elevation ?? 0.0 ;
297324 final Color backgroundColor = widget.backgroundColor
298325 ?? bannerTheme.backgroundColor
299- ?? theme.colorScheme.surface;
326+ ?? defaults.backgroundColor! ;
327+ final Color ? surfaceTintColor = widget.surfaceTintColor
328+ ?? bannerTheme.surfaceTintColor
329+ ?? defaults.surfaceTintColor;
330+ final Color ? shadowColor = widget.shadowColor
331+ ?? bannerTheme.shadowColor;
332+ final Color ? dividerColor = widget.dividerColor
333+ ?? bannerTheme.dividerColor
334+ ?? defaults.dividerColor;
300335 final TextStyle ? textStyle = widget.contentTextStyle
301336 ?? bannerTheme.contentTextStyle
302- ?? theme.textTheme.bodyMedium ;
337+ ?? defaults.contentTextStyle ;
303338
304339 Widget materialBanner = Container (
305340 margin: EdgeInsets .only (bottom: elevation > 0 ? 10.0 : 0.0 ),
306341 child: Material (
307342 elevation: elevation,
308343 color: backgroundColor,
344+ surfaceTintColor: surfaceTintColor,
345+ shadowColor: shadowColor,
309346 child: Column (
310347 mainAxisSize: MainAxisSize .min,
311348 children: < Widget > [
@@ -331,9 +368,8 @@ class _MaterialBannerState extends State<MaterialBanner> {
331368 ),
332369 if (! isSingleRow)
333370 buttonBar,
334-
335371 if (elevation == 0 )
336- const Divider (height: 0 ),
372+ Divider (height: 0 , color : dividerColor ),
337373 ],
338374 ),
339375 ),
@@ -394,3 +430,51 @@ class _MaterialBannerState extends State<MaterialBanner> {
394430 );
395431 }
396432}
433+
434+ class _BannerDefaultsM2 extends MaterialBannerThemeData {
435+ _BannerDefaultsM2 (this .context)
436+ : _theme = Theme .of (context),
437+ super (elevation: 0.0 );
438+
439+ final BuildContext context;
440+ final ThemeData _theme;
441+
442+ @override
443+ Color ? get backgroundColor => _theme.colorScheme.surface;
444+
445+ @override
446+ Color ? get dividerColor => Theme .of (context).colorScheme.surfaceVariant;
447+
448+ @override
449+ TextStyle ? get contentTextStyle => _theme.textTheme.bodyText2;
450+ }
451+
452+ // BEGIN GENERATED TOKEN PROPERTIES - Banner
453+
454+ // Do not edit by hand. The code between the "BEGIN GENERATED" and
455+ // "END GENERATED" comments are generated from data in the Material
456+ // Design token database by the script:
457+ // dev/tools/gen_defaults/bin/gen_defaults.dart.
458+
459+ // Token database version: v0_101
460+
461+ class _BannerDefaultsM3 extends MaterialBannerThemeData {
462+ const _BannerDefaultsM3 (this .context)
463+ : super (elevation: 1.0 );
464+
465+ final BuildContext context;
466+
467+ @override
468+ Color ? get backgroundColor => Theme .of (context).colorScheme.surface;
469+
470+ @override
471+ Color ? get surfaceTintColor => Theme .of (context).colorScheme.surfaceTint;
472+
473+ @override
474+ Color ? get dividerColor => Theme .of (context).colorScheme.surfaceVariant;
475+
476+ @override
477+ TextStyle ? get contentTextStyle => Theme .of (context).textTheme.bodyMedium;
478+ }
479+
480+ // END GENERATED TOKEN PROPERTIES - Banner
0 commit comments