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.

Inheritance

Constructors

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.
const

Properties

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

Methods

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

Operators

operator ==(Object other) bool
The equality operator.
nonVirtual">@nonVirtualinherited

Static Methods

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