Placement Events
Media, Banner and Interstitial share one typed event vocabulary. Feed has its own callbacks, because it speaks the bridge protocol rather than a native placement's event stream. Both are covered here.
Media, Banner and Interstitial
The callbacks
| Callback | Signature | Purpose |
|---|---|---|
onReady | void Function() | An ad is loaded and will display |
onFailed | void Function(TeadsAdError) | The request or render failed |
onClicked | void Function(TeadsAdClick) | A paid ad was clicked |
onClickedOrganic | void Function(TeadsAdClick) | Organic content was clicked |
onEvent | void Function(TeadsAdEvent, Map<String, dynamic>?) | Catch-all for every event |
onClosed | void Function() | Interstitial only — dismissed |
Every callback is optional. Implement only what you need.
For MediaPlacement and BannerPlacement these are constructor arguments; for
InterstitialPlacement they are assignable fields, because it is not a widget:
// Widget placements
MediaPlacement(
config: config,
onReady: () => debugPrint('ready'),
onFailed: (error) => debugPrint(error.reason),
);
// Interstitial
final interstitial = await InterstitialPlacement.create(config: config);
interstitial.onReady = () => debugPrint('ready');
interstitial.onClosed = () => debugPrint('dismissed');
TeadsAdError
class TeadsAdError {
final String reason;
}
onFailed: (TeadsAdError error) {
debugPrint('Ad failed: ${error.reason}');
analytics.track('ad_error', {'reason': error.reason});
}
A failure is not exceptional — no-fill is a normal outcome. Leave your layout in a sensible state rather than showing an error to the user.
TeadsAdClick
class TeadsAdClick {
final String? url;
}
url is null for a plain click on platforms and placements that do not report a
click-through URL, so always null-check it.
The SDK opens the click-through. Opening click.url as well makes the browser open
twice. Use these callbacks for analytics only.
The exception is FeedPlacement.onOrganicClick, which exists precisely so you can
handle navigation — see below.
TeadsAdEvent
The catch-all onEvent receives every event, including those with a dedicated callback:
onEvent: (TeadsAdEvent event, Map<String, dynamic>? data) {
switch (event) {
case TeadsAdEvent.viewed:
analytics.track('ad_viewable');
case TeadsAdEvent.complete:
analytics.track('ad_video_complete');
default:
break;
}
}
Full enum:
| Value | Fires when |
|---|---|
ready | An ad is available to display. Feed on Android also emits it when the page reports a fill, with isFillEvent: true in its data |
rendered | The creative has been rendered |
viewed | The ad met the viewability threshold. Feed emits it for the page's viewability event |
failed | The request or render failed |
clicked | A paid ad was clicked |
clickedOrganic | Organic content was clicked |
play | Video playback started or resumed |
pause | Video playback paused |
loaded | The ad finished loading. Feed on iOS emits it when the page reports a fill |
complete | Video playback reached the end |
startPlayAudio | Audio started (the user unmuted) |
stopPlayAudio | Audio stopped |
heightUpdated | The placement's height changed. Payload: height, in logical pixels |
willPresent | Interstitial — about to present |
presented | Interstitial — presented fullscreen |
willDismiss | Interstitial — about to dismiss |
dismissed | Interstitial — dismissed; the ad is spent |
Do not assume the whole enum applies. MediaPlacement never emits loaded or
rendered; the fullscreen events come only from Interstitial. Unknown native event
names are tolerated rather than throwing, so a future native event will not crash your
app — but it will not appear in the enum either.
The widgets resize themselves on heightUpdated, so you do not need to react to it.
Use it when your own layout depends on the placement's height.
Feed
Feed's callbacks differ in shape and purpose:
| Callback | Signature | Purpose |
|---|---|---|
onEvent | void Function(TeadsAdEvent event, Map<String, dynamic>? data) | Lifecycle, telemetry, height changes and clicks, sharing the typed TeadsAdEvent vocabulary |
onUnsupported | void Function(TeadsAdError error) | A bridge feature the plugin does not implement |
onOrganicClick | void Function(Uri organicUrl) | An organic recommendation was tapped |
onFullScreenChange | void Function(bool fullScreen) | The page wants to enter or leave fullscreen |
onOrganicClick
Organic recommendations point at your content, so the SDK hands you the URL instead of opening a browser over your app:
FeedPlacement(
config: feedConfig,
onOrganicClick: (Uri organicUrl) {
Navigator.of(context).push(
MaterialPageRoute(builder: (_) => ArticleScreen(url: organicUrl.toString())),
);
},
)
Leave it null and the article opens in an in-app browser view instead. Either way the click
is registered, and that does not depend on this callback. On Android the report is started
before the callback runs but is not awaited. On iOS the callback runs, and clickedOrganic
is emitted, only after the click's tracking report succeeds. If the report fails, neither
happens and nothing opens.
onFullScreenChange
The placement can only grow its own slot, so your app must fold its chrome away. It scrolls its card to the top of the viewport itself, so do not scroll your list from this callback. See the Feed guide for a complete example.
Collapse siblings with Visibility(maintainState: true) or a zero height. Removing one
re-parents the WebView and it stops painting.
onUnsupported
onUnsupported reports a bridge feature the plugin does not implement. A build that does
not wire it up sees a missing feature as silence. Wire it up in any build you intend
to debug.
Page events that neither native SDK forwards, error messages the page reports about
itself, and the Google ads card messages no longer reach onUnsupported. Both native SDKs
drop them, and the plugin logs them at debug level. Set TeadsLog.level = LogLevel.debug
to see them.
FeedPlacement(
config: feedConfig,
onUnsupported: (TeadsAdError error) {
debugPrint('Feed unsupported: ${error.reason}');
analytics.track('feed_unsupported', {'reason': error.reason});
},
)
onEvent
Shares the typed TeadsAdEvent vocabulary, mapped from the bridge page's events as each native Feed maps them:
| Page event | Android | iOS |
|---|---|---|
fill | ready, with isFillEvent: true in its data | loaded |
ready | ready | ready |
rendered | rendered | rendered |
viewability | viewed | viewed |
no-fill | failed, with reason: 'notFilled' plus the page's own fields | failed, with reason: 'notFilled', errorCode: 3 plus the page's own fields |
error | failed, with the page's message as reason | not emitted |
readyfires twice per ad on Android, once for the fill and once for the page's ownready, as on native Android. UseisFillEventto tell them apart. On iOS it fires once.reasonwas'no-fill'before 1.2.0. Match'notFilled'now.TeadsAdEvent.viewabilityis deprecated. Listen forviewed.viewabilityis still emitted right after eachvieweduntil it is removed.
Feed holds events back until the ad's outcome is known. Nothing but clicks arrives before the page reports a fill or a no-fill, or after a no-fill. The last height the page reported before the fill is delivered right after it.
It also emits, as the native Feed does:
| Event | Payload | Fires when |
|---|---|---|
heightUpdated | height | The feed's height in your layout changed. height is the page's height plus contentBottomPadding, capped at maxHeight. Read it as num |
clicked | url | A sponsored recommendation or a display ad was tapped. The SDK opens it |
clickedOrganic | url | An organic recommendation was tapped. On Android it fires whether or not onOrganicClick is set. On iOS it fires only after the click's tracking report succeeds |
Details that differ by platform or that you may trip over:
heightUpdatedon Android fires for every height the page reports, repeats included, andheightis a whole number there unless your padding or cap is fractional. The slot itself is not held back: it can grow before the fill with noheightUpdated, and the latest height arrives right after the fill. Don't size your layout from this event before the fill. On iOS it fires only when the height changes. ChangingcontentBottomPaddingormaxHeighton a rebuild emits it too, once the page has reported a height. It is not emitted while a card is fullscreen.clickedis emitted when the plugin asks to open the URL, not when the browser finishes loading. Repeated clicks within one second count as one, and on iOS so does a second tap while an organic click is still being reported.
FeedPlacement(
config: feedConfig,
onEvent: (TeadsAdEvent event, Map<String, dynamic>? data) {
switch (event) {
case TeadsAdEvent.heightUpdated:
debugPrint('Feed height: ${data?['height']}');
case TeadsAdEvent.clicked:
analytics.track('feed_paid_click', {'url': data?['url']});
default:
debugPrint('Feed event: ${event.identifier} — $data');
}
},
)
Complete Example
class _ArticleScreenState extends State<ArticleScreen> {
bool _fullScreen = false;
Widget build(BuildContext context) {
return Scaffold(
// Black behind the card: on Android the hidden navigation bar leaves a
// strip the card does not cover.
backgroundColor: _fullScreen ? Colors.black : null,
// Zero height rather than null: removing the AppBar changes the
// Scaffold's layout and risks re-parenting the body.
appBar: PreferredSize(
preferredSize: Size.fromHeight(_fullScreen ? 0 : kToolbarHeight),
child: _fullScreen
? const SizedBox.shrink()
: AppBar(title: const Text('Article')),
),
body: ListView(
physics: _fullScreen ? const NeverScrollableScrollPhysics() : null,
children: [
Visibility(
visible: !_fullScreen,
maintainState: true,
child: Column(
children: [
const Text('Article content…'),
MediaPlacement(
config: MediaPlacementConfig(
pid: 84242,
articleUrl: widget.articleUrl,
),
onReady: () => analytics.track('media_ready'),
onFailed: (error) =>
analytics.track('media_failed', {'reason': error.reason}),
onClicked: (click) =>
analytics.track('media_clicked', {'url': click.url}),
onEvent: (event, data) {
if (event == TeadsAdEvent.viewed) {
analytics.track('media_viewable');
}
},
),
],
),
),
FeedPlacement(
config: FeedPlacementConfig(
widgetId: 'MB_1',
installationKey: 'NANOWDGT01',
articleUrl: widget.articleUrl,
),
onOrganicClick: (url) => Navigator.of(context).push(
MaterialPageRoute(
builder: (_) => ArticleScreen(articleUrl: url.toString()),
),
),
onUnsupported: (error) => debugPrint('Feed: ${error.reason}'),
onFullScreenChange: (fullScreen) =>
setState(() => _fullScreen = fullScreen),
),
],
),
);
}
}
Best Practices
Keep callbacks cheap
They run on the platform-channel response path. Heavy synchronous work there shows up as jank while an ad is loading. Queue it instead.
Guard setState
An event can arrive after the widget is unmounted:
onReady: () {
if (!mounted) return;
setState(() => _adReady = true);
}
Do not re-create callbacks needlessly
Building a new closure on every rebuild is harmless for correctness but makes the placement's config identity churn. Prefer instance methods over inline closures in a frequently-rebuilt widget.
Treat failure as normal
No-fill is an expected outcome, not an error state to surface to users. Collapse the slot gracefully.
Troubleshooting
Events not firing
- Confirm
TeadsSdk.configure()completed without throwing - Confirm the callback is actually passed to the constructor
- Confirm the widget is mounted and on screen
- Raise the log level:
TeadsLog.level = LogLevel.debug
Clicks not working
- Check for an overlay — even a transparent one — over the placement
- Check that no ancestor
IgnorePointerorAbsorbPointeris swallowing the gesture - Test on a real device
Feed fullscreen breaks the layout
You are almost certainly removing widgets from the tree rather than collapsing them.
Next Steps
- Settings & Configuration — every config field
- Formats — complete examples
- Troubleshooting Guide — common issues
Pro tip: wire onFailed and — for Feed — onUnsupported up from the start. They
are the difference between a diagnosable integration and a silent one.