BannerAdWidget class
A widget that displays a banner ad.
Place this widget in your widget tree to show a banner ad. The widget handles loading, error recovery, and lifecycle management automatically.
Standard banner
BannerAdWidget(
manager: adManager,
onEvent: (event) {
analytics.logAdEvent(event);
},
)
Adaptive banner (recommended)
Automatically adapts to the screen width:
BannerAdWidget.adaptive(
manager: adManager,
)
The widget renders as a SizedBox.shrink while loading or if the ad fails to load, ensuring no layout disruption.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- BannerAdWidget
Constructors
- BannerAdWidget({required AdManager manager, Size? size, void onEvent(AdEvent event)?, Key? key})
-
Creates a banner ad widget with a fixed
size.const - BannerAdWidget.adaptive({required AdManager manager, void onEvent(AdEvent event)?, Key? key})
-
Creates an adaptive banner ad widget.
const
Properties
- adaptive → bool
-
Whether this is an adaptive banner.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- manager → AdManager
-
The ad manager instance providing configuration and lifecycle.
final
- onEvent → void Function(AdEvent event)?
-
Optional callback for ad events (loaded, clicked, etc.).
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- size → Size?
-
The banner size. Ignored when using BannerAdWidget.adaptive.
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< BannerAdWidget> -
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.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent 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, int wrapWidth = 65}) → 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
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited