mopub_flutter 1.1.0 mopub_flutter: ^1.1.0 copied to clipboard
A plugin for Mopub Banner, Interstitial & Rewarded Ads in Android & iOS
MoPub SDK for Flutter #
Note - When running the example repo, please make sure to add your GADIdentifier as well as your AppLovin Key to use MoPub mediation, alternatively you can remove these from your Manifest, not doing so may result in crashes. #
Getting started: #
1. Initialise MoPub #
Call Mopub.init()
in the initState()
of your app
try {
MoPub.init('ad_unit_id', testMode: true).then((_) {
_loadRewardedAd();
_loadInterstitialAd();
});
} on PlatformException {}
2. To load a rewarded ad #
void _loadRewardedAd() {
videoAd = MoPubRewardedVideoAd('ad_unit_id',
(result, args) {
setState(() {
rewardedResult = '${result.toString()}____$args';
});
print('$result');
if (result == RewardedVideoAdResult.GRANT_REWARD) {
print('Grant reward: $args');
}
}, reloadOnClosed: true);
}
3. To load an interstitial ad #
void _loadInterstitialAd() {
interstitialAd = MoPubInterstitialAd(
'ad_unit_id',
(result, args) {
print('Interstitial $result');
},
reloadOnClosed: true,
);
}
4. To call a banner ad #
MoPubBannerAd(
adUnitId: 'ad_unit_id',
bannerSize: BannerSize.STANDARD,
keepAlive: true,
listener: (result, dynamic) {
print('$result');
},
);
IMPORTANT: If you’re Publishing and using Proguard: #
MoPub includes a proguard.cfg file in both the mopub-sdk and mopub-sample directories. The contents of these identical files should be included in your Proguard config when using the MoPub SDK in a Proguarded project.
For the complete implementation, please refer to the example repo.