A package to use banner ads in firebase_admob package easily.
The build method of AdmobBannerWidget simply returns a Container, but an ad with the same height is placed exactly on the Container.
This ensures that the ad and the button do not overlap.
The ad itself can be treated as if it were in the widget. You don't have to write an additional process to remove the ad.
When another page is pushed from above, the ad disappears.
If you change the orientation of the device, the ad will be erased first, and then reappear in the new position.
You can dispose this widget continuously.
This package depends on the firebase_admob plugin.
Please read the linked pages carefully and complete the necessary preparations.
Add Firebase to your Flutter app firebase_admob plugin
If you just want to run examples, these preparations is not necessary.
Initialize the firebase_admob plugin before use AdMobBannerWidget.
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await FirebaseAdMob.instance.initialize(
appId: Platform.isAndroid
// AdMob App ID for Firebase Demo Project (Flood-It!)
? 'ca-app-pub-8123415297019784~2664022459'
// test GADApplicationIdentifier. see https://developers.google.com/admob/ios/quick-start?hl=en
: 'ca-app-pub-3940256099942544~1458002511');
runApp(MyApp());
}
Place the AdMobBannerWidget where you want the ad to appear.
class MyApp extends StatelessWidget {
const MyApp();
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(),
body: AdMobBannerWidget(
adUnitId: BannerAd.testAdUnitId,
),
),
);
}
}
The ad size will be the largest one that can be displayed within 1/8th of the height of the SafeArea. AdMobBanner's SmartBanner standard is used as a reference.
They just appear and disappear.
You can't use it as a part of the list to scroll.
It only calculates the position of the widget and puts the ad in front of it. You can't hide ads.