NativeAdWidget class

A widget that displays a native ad.

Native ads are customizable ads that match the look and feel of your app.

Example:

NativeAdWidget(
  adUnitId: 'ca-app-pub-xxxxx/xxxxx',
  height: 300,
  style: NativeAdStyle(
    mediaStyle: NativeAdMediaStyle(aspectRatio: 16/9),
  ),
  onAdLoaded: () => print('Native ad loaded'),
  onAdFailedToLoad: (error) => print('Native ad failed: $error'),
)
Inheritance

Constructors

NativeAdWidget({Key? key, required String adUnitId, double height = 250.0, AdRequestConfig? requestConfig, VoidCallback? onAdLoaded, dynamic onAdFailedToLoad(String error)?, VoidCallback? onAdClicked, VoidCallback? onAdImpression, Color? backgroundColor, String? templateId, String? preloadedNativeAdId, NativeAdStyle? style, NativeAdTemplate? template, bool isFullScreen = false})
const

Properties

adUnitId String
The ad unit ID for the native ad.
final
backgroundColor Color?
Background color for the ad container.
final
hashCode int
The hash code for this object.
no setterinherited
height double
The height of the native ad container.
final
isFullScreen bool
Whether to show the ad in full screen mode
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
onAdClicked VoidCallback?
Called when the ad is clicked.
final
onAdFailedToLoad → dynamic Function(String error)?
Called when the ad fails to load.
final
onAdImpression VoidCallback?
Called when the ad impression is recorded.
final
onAdLoaded VoidCallback?
Called when the ad loads successfully.
final
preloadedNativeAdId String?
Optional preloaded native ad ID returned by loadNativeAd.
final
requestConfig AdRequestConfig?
Optional request configuration.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
style NativeAdStyle?
Native ad style configuration
final
template NativeAdTemplate?
Native ad template type
final
templateId String?
Custom template ID for native ads (optional).
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<NativeAdWidget>
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