MaterialBanner class Null safety

A Material Design banner.

A banner displays an important, succinct message, and provides actions for users to address (or dismiss the banner). A user action is required for it to be dismissed.

Banners should be displayed at the top of the screen, below a top app bar. They are persistent and non-modal, allowing the user to either ignore them or interact with them at any time.

Banners placed directly into the widget tree are static.
To create a local project with this code sample, run:
flutter create --sample=material.MaterialBanner.1 mysample

MaterialBanner's can also be presented through a ScaffoldMessenger. Here is an example where ScaffoldMessengerState.showMaterialBanner() is used to show the MaterialBanner.
To create a local project with this code sample, run:
flutter create --sample=material.MaterialBanner.2 mysample

The actions will be placed beside the content if there is only one. Otherwise, the actions will be placed below the content. Use forceActionsBelow to override this behavior.

If the actions placed below the content, they will be laid out in a row. If there isn't sufficient room to display everything, they are laid out in a column instead.

The actions and content must be provided. An optional leading widget (typically an Image) can also be provided. The contentTextStyle and backgroundColor can be provided to customize the banner.

This widget is unrelated to the widgets library Banner widget.



MaterialBanner({Key? key, required Widget content, TextStyle? contentTextStyle, required List<Widget> actions, double? elevation, Widget? leading, Color? backgroundColor, EdgeInsetsGeometry? padding, EdgeInsetsGeometry? leadingPadding, bool forceActionsBelow = false, OverflowBarAlignment overflowAlignment = OverflowBarAlignment.end, Animation<double>? animation, VoidCallback? onVisible})
Creates a MaterialBanner.


actions List<Widget>
The set of actions that are displayed at the bottom or trailing side of the MaterialBanner.
animation Animation<double>?
The animation driving the entrance and exit of the material banner when presented by the ScaffoldMessenger.
backgroundColor Color?
The color of the surface of this MaterialBanner.
content Widget
The content of the MaterialBanner.
contentTextStyle TextStyle?
Style for the text in the content of the MaterialBanner.
elevation double?
The z-coordinate at which to place the material banner.
forceActionsBelow bool
An override to force the actions to be below the content regardless of how many there are.
hashCode int
The hash code for this object.
@nonVirtual, read-only, inherited
key Key?
Controls how one widget replaces another widget in the tree.
final, inherited
leading Widget?
The (optional) leading widget of the MaterialBanner.
leadingPadding EdgeInsetsGeometry?
The amount of space by which to inset the leading widget.
onVisible VoidCallback?
Called the first time that the material banner is visible within a Scaffold when presented by the ScaffoldMessenger.
overflowAlignment OverflowBarAlignment
The horizontal alignment of the actions when the actions laid out in a column.
padding EdgeInsetsGeometry?
The amount of space by which to inset the content.
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited


createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
createState() State<MaterialBanner>
Creates the mutable state for this widget at a given location in the tree.
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
@protected, inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
toString({DiagnosticLevel minLevel =}) String
A string representation of this object.
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants.
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
toStringShort() String
A short, textual description of this widget.
withAnimation(Animation<double> newAnimation, {Key? fallbackKey}) MaterialBanner
Creates a copy of this material banner but with the animation replaced with the given animation.


operator ==(Object other) bool
The equality operator.
@nonVirtual, inherited

Static Methods

createAnimationController({required TickerProvider vsync}) AnimationController
Creates an animation controller useful for driving a MaterialBanner's entrance and exit animation.