I'm using the plugin: firebase_admob: ^0.9.3+4 And I want to load ads only on a specific page in a PageView. When the user moves to another page I want the ads to be disposed. However, I've encountered a problem where the ad only gets disposed if its already loaded and shown. Otherwise it loads and displays on the new tab.
How can I prevent an ad from loading if it hasn't loaded already?
Here's the code:
MobileAdTargetingInfo targetingInfo = MobileAdTargetingInfo(
keywords: <String>['flutterio', 'beautiful apps'],
contentUrl: 'https://flutter.io',
birthday: DateTime.now(),
childDirected: false,
designedForFamilies: false,
gender: MobileAdGender.male,
testDevices: <String>[],
);
BannerAd myBanner = BannerAd(
adUnitId: BannerAd.testAdUnitId,
size: AdSize.smartBanner,
targetingInfo: targetingInfo,
listener: (MobileAdEvent event) {
print("BannerAd event is $event");
},
);
myBanner
..load()
..show(
anchorOffset: 60.0,
horizontalCenterOffset: 10.0,
anchorType: AnchorType.bottom,
);
And in the dispose method of the page I call the following function:
@override
void dispose() {
disposeAds();
super.dispose();
}
void disposeAds()async{
_banner?.dispose();
_banner=null;
}
What I want to know is how to prevent an ad from loading after the page is disposed? On iOS it automatically seems to do this but not on Android.