Last updated:
0 purchases
mint admobkit
mint_admobkit #
A set of AdMob integration utils for MintMinter apps
AdBanner: show a banner ad
SimpleAdBanner: show a banner ad simple
AdIdProvider: provide ids for different ad type
AdType: defines ad type
AttView: Show ATT request on iOS
Usage #
Integrate AdMob on Android #
Update AndroidManifest.xml:
Add permissions before <application:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>
copied to clipboard
Add metadata before </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-3940256099942544~3347511713"/>
<!-- Delay app measurement until MobileAds.initialize() is called. See https://developers.google.com/admob/flutter/eu-consent#delay_app_measurement_optional -->
<meta-data
android:name="com.google.android.gms.ads.DELAY_APP_MEASUREMENT_INIT"
android:value="true"/>
copied to clipboard
Add an ad provider:
import 'package:mintminter_mint/ad/ad.dart';
sealed class ExampleAdType extends AdType {
const ExampleAdType({required this.unitId});
final String unitId;
@override
List<Object?> get props => [
unitId,
];
}
class ExampleTopBannerAndroid extends ExampleAdType {
const ExampleTopBannerAndroid({
required super.unitId,
});
@override
List<Object?> get props => [super.unitId];
}
class ExampleAdProvider extends AdIdProvider {
ExampleAdProvider._internal();
static ExampleAdProvider? _instance;
/// Get an ExampleAdProvider instance
factory ExampleAdProvider.getInstance() {
_instance ??= ExampleAdProvider._internal();
return _instance!;
}
/// Dispose ExampleAdProvider instance
static dispose() {
_instance = null;
}
@override
String getAndroidAdUnitId(AdType adType) {
if (adType is ExampleAdType) {
return adType.unitId;
} else {
return '';
}
}
@override
String getIOSAdUnitId(AdType adType) {
return '';
}
}
copied to clipboard
Init the add provider in main
void main() {
WidgetsFlutterBinding.ensureInitialized();
ExampleAdProvider.getInstance().initializeMobileAdsOnMobile();
runApp(const App());
}
copied to clipboard
Use AdBanner:
AdBanner(
padding: const EdgeInsets.symmetric(vertical: 50),
type: const ExampleTopBannerAndroid(unitId: AdIdProvider.mockAdId),
adIdProvider: ExampleAdProvider.getInstance(),
)
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.