Step 1: (Optional) Construct event listener
final AdropPopupListener listener = AdropPopupListener(
onAdReceived: (ad) =>
debugPrint('Adrop Popup Ad loaded with unitId ${ad.unitId}!'),
onAdFailedToReceive: (ad, errorCode) =>
debugPrint('error in ${ad.unitId} while loading: $errorCode'),
onAdFailedToShowFullScreen: (ad, errorCode) =>
debugPrint('error in ${ad.unitId} while showing: $errorCode'),
...
);
class YourComponent extends StatefulWidget {
const YourComponent({super.key});
@override
State<StatefulWidget> createState() => _YourComponentState();
}
class _YourComponentState extends State<YourComponent> {
final AdropPopupAd popupAd = AdropPopupAd(
unitId: 'YOUR_UNIT_ID',
listener: listener,
closeTextColor: your_color // optional Color
hideForTodayTextColor: your_color // optional Color
backgroundColor: your_color // optional Color
);
@override
void initState() {
super.initState();
popupAd.load();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: TextButton(
onPressed: () {
final isLoaded = popupAd.isLoaded ?? false;
if (isLoaded) {
popupAd.show();
} else {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('popup ad is loading...'))
);
}
},
child: const Text('display ad'),
),
),
);
}
}
AdropPopupAd must be disposed of when access to it is no longer needed.
@override
void dispose() {
super.dispose();
popupAd.dispose();
}