Ads positioned within scrollable content, dynamically displaying Banner o OutStream formats based on the item’s position within the scroll view.
Show the Ad.
To display an ad in the ListView
widget, or in any other flutter’s scrollable widget with index use R89InfiniteScrollAd
widget, by adding it to the scroll item
Widget _buildItem(context, index) => Card( child: Column( children: [ Padding( padding: const EdgeInsets.all(8.0), child: Text("Item index $index"), ), Center( child: R89InfiniteScrollAd( itemIndex: index, infiniteScrollId: infiniteScrollId), ) ], ), );
R89InfiniteScrollAd
has two required parameters
-
itemIndex
the item position in theListView
-
infiniteScrollId
theR89SDK
generated scroll Id, which is shared between the child items of the sameListView
.
Here is how to generate infiniteScrollId
final int infiniteScrollId = R89SDK.adFactory.createInfiniteScroll( configurationId: ConfigConstants.infiniteScrollTestR89ConfigId);
That all, find the full example at the bottom of this page.
Lifecycle Events
To receive the lifecycle events for a R89InfiniteScrollAd
, provide BannerEventListener
to R89InfiniteScrollAd
via lifecycleCallbacks
parameter. Details about BannerEventListener
can be found in the Reference.
R89InfiniteScrollAd( itemIndex: index, infiniteScrollId: infiniteScrollId, lifecycleCallbacks: BannerEventListener.callbacks( onLoadedCallback: () {}, onImpressionCallback: () {}, onLayoutChangeCallback: (width, height) {}, onClickCallback: () {}, onOpenCallback: () {}, onCloseCallback: () {}, onFailedToLoadCallback: (error) {}, ))
To receive the lifecycle events for overall scroll, provide InfiniteScrollEventListener
to R89SDK.adFactory.createInfiniteScroll
via lifecycleCallbacks
parameter. Details about InfiniteScrollEventListener
can be found in the Reference.
final int infiniteScrollId = R89SDK.adFactory.createInfiniteScroll( configurationId: ConfigConstants.infiniteScrollTestR89ConfigId, lifecycleCallbacks: InfiniteScrollEventListener.callbacks( onRollCallback: (itemIdInData) {}, onRollFailedCallback: (itemIdInData) {}, onAdItemCreatedCallback: (adapterId, probability) {}, onAdItemFailedToCreateCallback: (message) {}, onAdItemLoadedCallback: (itemIdInData) {}, onAdItemFailedToLoadCallback: (itemIdInData, message) {}, onAdItemImpressionCallback: (itemIdInData) {}, onAdItemClickCallback: (itemIdInData) {}, onAdItemOpenCallback: (itemIdInData) {}, onAdItemCloseCallback: (itemIdInData) {}, ));
Full Example.
import 'package:flutter/material.dart'; import 'package:playground/config_constants.dart'; import 'package:refinery89_monetize_app/r89_sdk.dart'; class ScrollPage extends StatefulWidget { const ScrollPage({super.key}); @override State createState() => _ScrollPageState(); } class _ScrollPageState extends State { final int infiniteScrollId = R89SDK.adFactory.createInfiniteScroll( configurationId: ConfigConstants.infiniteScrollTestR89ConfigId); @override Widget build(BuildContext context) => ListView.builder( itemCount: 500, itemBuilder: (context, index) => _buildItem(context, index), ); Widget _buildItem(context, index) => Card( child: Column( children: [ Padding( padding: const EdgeInsets.all(8.0), child: Text("Item index $index"), ), Center( child: R89InfiniteScrollAd( itemIndex: index, infiniteScrollId: infiniteScrollId), ) ], ), ); }