I want to show same banner ad on all the screens of my app.
Currently it only shows on home screen where I am initializing and adding it. And when I navigate to another screen from home screen the banner ads are not showing.
Below is the code of Home_screen where I initialize the BannerAd and add it.
@override
void didChangeDependencies () {
super.didChangeDependencies();
final adState = Provider.of<AdHelper>(context);
adState.initialization.then((status) {
setState(() {
banner = BannerAd(
size: AdSize.banner,
adUnitId: adState.bannerAdUnitId,
listener: adState.bannerAdListener,
request: AdRequest()
)..load();
});
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
...
...
if (banner == null)
SizedBox(
height: 58,
)
else
Container(
height: 58,
child: AdWidget(ad: banner),
)
...
...
On second screen which is navigating for home screen where bannerad is not shown
@override
Widget build(BuildContext context) {
return Scaffold(
...
...
body: Column(
children: [
Expanded(
...
),
SizedBox( // Made space for bannerAd thought that bannerAd will get overlapped on this
height: 58,
)
...
...
I am using google_mobile_ads: ^0.13.2