Step 1: Display banner view
class YourComponentState extends State<YourComponent> {
final unitId = "";
bool isLoaded = false;
AdropBannerView? bannerView;
@override
void initState() {
super.initState();
bannerView = AdropBannerView(
unitId: getUnitId(),
listener: AdropBannerListener(
onAdReceived: (unitId) {
setState(() {
isLoaded = true;
});
},
onAdFailedToReceive: (unitId, error) {
setState(() {
isLoaded = false;
});
},
),
);
bannerView!.load();
}
@override
Widget build(BuildContext context) {
return Column(
children: [
TextButton(
onPressed: () {
bannerManager.load(unitId);
},
child: const Text('Reload Ad!')),
bannerView != null && isLoaded ?
SizedBox(
width: screenWidth,
height: 80,
child: bannerView) : Container(),
],
);
}
}
AdropBannerView must be disposed of when access to it is no longer needed.
@override
void dispose() {
super.dispose();
bannerView?.dispose();
}