https://github.com/myconsciousness/admob-unit-ids
Admob Unit IDs is a library that provides a common structure for managing AdMob unit IDs licensed under BSD 3-Clause.
https://github.com/myconsciousness/admob-unit-ids
admob dart flutter id library package pubdev unit unit-id
Last synced: 3 months ago
JSON representation
Admob Unit IDs is a library that provides a common structure for managing AdMob unit IDs licensed under BSD 3-Clause.
- Host: GitHub
- URL: https://github.com/myconsciousness/admob-unit-ids
- Owner: myConsciousness
- License: bsd-3-clause
- Created: 2021-08-05T14:15:24.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-12-28T04:44:27.000Z (almost 4 years ago)
- Last Synced: 2024-10-03T07:43:52.096Z (about 1 year ago)
- Topics: admob, dart, flutter, id, library, package, pubdev, unit, unit-id
- Language: Dart
- Homepage: https://pub.dev/packages/admob_unit_ids
- Size: 29.3 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
[](https://github.com/myConsciousness/admob-unit-ids/actions/workflows/dart.yml)
# 1. Admob Unit IDs
## 1.1. What is it?
`Admob Unit IDs` is a library that provides a common structure for managing AdMob unit IDs licensed under BSD 3-Clause.
- [1. Admob Unit IDs](#1-admob-unit-ids)
- [1.1. What is it?](#11-what-is-it)
- [1.2. Motivation](#12-motivation)
- [1.3. How To Use](#13-how-to-use)
- [1.3.1. Get library](#131-get-library)
- [1.3.2. Import and extend abstract class](#132-import-and-extend-abstract-class)
- [1.3.3. Override methods](#133-override-methods)
- [1.3.4. Call methods to get AdMob Unit IDs](#134-call-methods-to-get-admob-unit-ids)
- [1.3.5. Overview](#135-overview)
- [1.4. More Information](#14-more-information)## 1.2. Motivation
1. Provide common functionality regarding unit IDs when implementing AdMob.
2. Reduce redundant settings when deploying AdMob.## 1.3. How To Use
### 1.3.1. Get library
Run this command:
With Flutter:
```terminal
flutter pub add admob_unit_ids
```### 1.3.2. Import and extend abstract class
```dart
import 'package:admob_unit_ids/admob_unit_ids.dart';class DemoAdmobUnitIDs extends AdmobUnitIDs {
}
```### 1.3.3. Override methods
| 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. |```dart
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';
}
```### 1.3.4. Call methods to get AdMob Unit IDs
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. |```dart
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);
}
```### 1.3.5. Overview
```dart
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);
}
```## 1.4. More Information
`AdmobUnitIDs` was designed and implemented by **_Kato Shinya_**.
- [Creator Profile](https://github.com/myConsciousness)
- [License](https://github.com/myConsciousness/admob-unit-ids/blob/main/LICENSE)
- [Release Note](https://github.com/myConsciousness/admob-unit-ids/releases)
- [File a Bug](https://github.com/myConsciousness/admob-unit-ids/issues)