Admob Unit IDs
is a library that provides a common structure for managing AdMob unit IDs licensed under BSD 3-Clause.
- Provide common functionality regarding unit IDs when implementing AdMob.
- Reduce redundant settings when deploying AdMob.
Run this command:
With Flutter:
flutter pub add admob_unit_ids
import 'package:admob_unit_ids/admob_unit_ids.dart';
class DemoAdmobUnitIDs extends AdmobUnitIDs {
}
Method Name | Remarks |
---|---|
releaseAppOpen | Should return unit id of app open for releasing. |
releaseBanner | Should return unit id of banner for releasing. |
releaseInterstitial | Should return unit id of interstitial for releasing. |
releaseInterstitialVideo | Should return unit id of interstitial video for releasing. |
releaseNativeAdvanced | Should return unit id of native advanced for releasing. |
releaseNativeAdvancedVideo | Should return unit id of native advanced video for releasing. |
releaseRewarded | Should return unit id of rewarded for releasing. |
releaseRewardedInterstitial | Should return unit id of rewarded interstitial for releasing. |
import 'package:universal_io/io.dart';
import 'package:admob_unit_ids/admob_unit_ids.dart';
class DemoAdmobUnitIDs extends AdmobUnitIDs {
@override
String get releaseAppOpen => Platform.isAndroid
? 'ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx'
: 'ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx';
@override
String get releaseBanner => Platform.isAndroid
? 'ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx'
: 'ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx';
@override
String get releaseInterstitial => Platform.isAndroid
? 'ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx'
: 'ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx';
@override
String get releaseInterstitialVideo => Platform.isAndroid
? 'ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx'
: 'ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx';
@override
String get releaseNativeAdvanced => Platform.isAndroid
? 'ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx'
: 'ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx';
@override
String get releaseNativeAdvancedVideo => Platform.isAndroid
? 'ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx'
: 'ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx';
@override
String get releaseRewarded => Platform.isAndroid
? 'ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx'
: 'ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx';
@override
String get releaseRewardedInterstitial => Platform.isAndroid
? 'ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx'
: 'ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx';
}
If you override the above abstract methods in a class that extends from this abstract class, basically no need to use the overridden methods directly. But you can use the methods defined in this abstract class to get the unit ID depends on the application startup status.
The following methods check the application startup status, and returns the unit ID for testing when debugging, and returns the release unit ID implemented in concrete class extended this abstract class when releasing.
Method Name | Remarks |
---|---|
appOpen | Returns the unit id of app open for debugging or releasing. |
banner | Returns the unit id of banner for debugging or releasing. |
interstitial | Returns the unit id of interstitial for debugging or releasing. |
interstitialVideo | Returns the unit id of interstitial video for debugging or releasing. |
nativeAdvanced | Returns the unit id of native advanced for debugging or releasing. |
nativeAdvancedVideo | Returns the unit id of native advanced video for debugging or releasing. |
rewarded | Returns the unit id of rewarded for debugging or releasing. |
rewardedInterstitial | Returns the unit id of rewarded interstitial for debugging or releasing. |
void main() {
final AdmobUnitIDs admobUnitIDs = DemoAdmobUnitIDs();
// => Unit id for debugging or unit id for releasing.
print(admobUnitIDs.appOpen);
print(admobUnitIDs.banner);
print(admobUnitIDs.interstitial);
print(admobUnitIDs.interstitialVideo);
print(admobUnitIDs.nativeAdvanced);
print(admobUnitIDs.nativeAdvancedVideo);
print(admobUnitIDs.rewarded);
print(admobUnitIDs.rewardedInterstitial);
}
import 'package:universal_io/io.dart';
import 'package:admob_unit_ids/admob_unit_ids.dart';
class DemoAdmobUnitIDs extends AdmobUnitIDs {
/// The singleton instance of [DemoAdmobUnitIDs].
static final DemoAdmobUnitIDs _singletonInstance = DemoAdmobUnitIDs._internal();
/// The internal default constructor.
DemoAdmobUnitIDs._internal();
/// Returns the singleton instance of [DemoAdmobUnitIDs].
factory DemoAdmobUnitIDs.getInstance() => _singletonInstance;
@override
String get releaseAppOpen => Platform.isAndroid
? 'ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx'
: 'ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx';
@override
String get releaseBanner => Platform.isAndroid
? 'ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx'
: 'ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx';
@override
String get releaseInterstitial => Platform.isAndroid
? 'ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx'
: 'ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx';
@override
String get releaseInterstitialVideo => Platform.isAndroid
? 'ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx'
: 'ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx';
@override
String get releaseNativeAdvanced => Platform.isAndroid
? 'ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx'
: 'ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx';
@override
String get releaseNativeAdvancedVideo => Platform.isAndroid
? 'ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx'
: 'ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx';
@override
String get releaseRewarded => Platform.isAndroid
? 'ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx'
: 'ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx';
@override
String get releaseRewardedInterstitial => Platform.isAndroid
? 'ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx'
: 'ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx';
}
void main() {
final AdmobUnitIDs admobUnitIDs = DemoAdmobUnitIDs.getInstance();
// => Unit id for debugging or unit id for releasing.
print(admobUnitIDs.appOpen);
print(admobUnitIDs.banner);
print(admobUnitIDs.interstitial);
print(admobUnitIDs.interstitialVideo);
print(admobUnitIDs.nativeAdvanced);
print(admobUnitIDs.nativeAdvancedVideo);
print(admobUnitIDs.rewarded);
print(admobUnitIDs.rewardedInterstitial);
}
AdmobUnitIDs
was designed and implemented by Kato Shinya.