avory_ad_control 1.0.0
avory_ad_control: ^1.0.0 copied to clipboard
Avory Ad Control is a wrapper around Google Admob which let you integrate ads easily
Avory Ad Control #
Features #
- Google Admob (banner, appOpen, interstitial, rewarded ad, native ad, rewarded interstitial ad)
Installation #
Using Git Repository #
To use this library in your Flutter app directly from the Git repository, add the following to your pubspec.yaml file:
dependencies:
avory_ad_control:
git:
url: https://github.com/AI-App-Studio/avory-ad-control.git
ref: main # or specify a specific branch/tag
Alternatively, you can specify a specific commit or tag:
dependencies:
avory_ad_control:
git:
url: https://github.com/AI-App-Studio/avory-ad-control.git
ref: v1.0.0 # specify a tag
Or use a specific commit hash:
dependencies:
avory_ad_control:
git:
url: https://github.com/AI-App-Studio/avory-ad-control.git
ref: abc1234 # specify a commit hash
After adding the dependency, run:
flutter pub get
Then import the package in your Dart code:
import 'package:avory_ad_control/avory_ad_control.dart';
Admob Mediation #
- This plugin supports admob mediation See Details to see Admob Mediation Guide.
- You just need to add the naative plaatform setting for admob mediation.
GDPR and Privacy Options compliance #
There is a consent manager helper added to support gdpr dialog and privacy dialog ConsentManager.gatherGdprConsent() and ConsentManager.gatherPrivacyConsent()
Platform Specific Setup #
iOS #
Update your Info.plist
- The keys for Google Admob are required in Info.plist.
Update your app's ios/Runner/Info.plist file to add two keys:
<key>GADApplicationIdentifier</key>
<string>YOUR_SDK_KEY</string>
Android #
Update AndroidManifest.xml
<manifest>
<application>
<!-- Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
</application>
</manifest>
Initialize Ad Ids #
import 'dart:io';
import 'package:avory_ad_control/avory_ad_control.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';
class TestAdIdManager extends IAdIdManager {
const TestAdIdManager();
@override
AppAdIds? get admobAdIds => AppAdIds(
appId: Platform.isAndroid
? 'ca-app-pub-3940256099942544~3347511713'
: 'ca-app-pub-3940256099942544~1458002511',
appOpenId: Platform.isAndroid
? 'ca-app-pub-3940256099942544/3419835294'
: 'ca-app-pub-3940256099942544/5662855259',
bannerId: 'ca-app-pub-3940256099942544/6300978111',
interstitialId: 'ca-app-pub-3940256099942544/1033173712',
rewardedId: 'ca-app-pub-3940256099942544/5224354917',
);
}
Initialize the SDK #
Before loading ads, have your app initialize the Mobile Ads SDK by calling AivoryAdControl.instance.initialize() which initializes the SDK and returns a Future that finishes once initialization is complete (or after a 30-second timeout). This needs to be done only once, ideally right before running the app.
import 'package:avory_ad_control/avory_ad_control.dart';
import 'package:flutter/material.dart';
const IAdIdManager adIdManager = TestAdIdManager();
AivoryAdControl.instance.initialize(
adIdManager,
adMobAdRequest: const AdRequest(),
admobConfiguration: RequestConfiguration(testDeviceIds: [
'072D2F3992EF5B4493042ADC632CE39F', // Mi Phone
'00008030-00163022226A802E',
]),
);
Interstitial/Rewarded Ads #
Load an ad #
Ad is automatically loaded after being displayed or first time when you call initialize. But on safe side, you can call this method. This will load both rewarded and interstitial ads. If a particular ad is already loaded, it will not load it again.
AivoryAdControl.instance.loadAd();
Show interstitial or rewarded ad #
AivoryAdControl.instance.showAd(AdUnitType.rewarded);
Show appOpen ad #
AivoryAdControl.instance.showAd(AdUnitType.appOpen)
Show Banner Ads #
This is how you may show banner ad in widget-tree somewhere:
@override
Widget build(BuildContext context) {
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
SomeWidget(),
const Spacer(),
ACBannerAd(
adNetwork: AdNetwork.admob, adSize: AdSize.mediumRectangle),
],
);
}
Listening to the callbacks #
Declare this object in the class
StreamSubscription? _streamSubscription;
We are showing InterstitialAd here and also checking if ad has been shown.
If true, we are canceling the subscribed callbacks, if any.
Then, we are listening to the Stream and accessing the particular event we need
if (AivoryAdControl.instance.showInterstitialAd()) {
// Canceling the last callback subscribed
_streamSubscription?.cancel();
// Listening to the callback from showInterstitialAd()
_streamSubscription =
AivoryAdControl.instance.onEvent.listen((event) {
if (event.adUnitType == AdUnitType.interstitial &&
event.type == AdEventType.adDismissed) {
_streamSubscription?.cancel();
goToNextScreen(countryList[index]);
}
});
}