monetization_kit 0.0.3
monetization_kit: ^0.0.3 copied to clipboard
A complete Flutter monetization toolkit with AdMob ads, Firebase integration, native ads, custom ad widgets, analytics, remote config, and reusable utilities for building production-ready apps.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:monetization_kit/monetization_kit.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await MonetizationKit.initialize(
config: const MonetizationConfig(
iosStoreId: 'YOUR_IOS_APP_STORE_ID',
adUnitIds: AdUnitIds(
androidBanner: 'YOUR_ANDROID_BANNER_ID',
iosBanner: 'YOUR_IOS_BANNER_ID',
androidInterstitial: 'YOUR_ANDROID_INTERSTITIAL_ID',
iosInterstitial: 'YOUR_IOS_INTERSTITIAL_ID',
androidRewarded: 'YOUR_ANDROID_REWARDED_ID',
iosRewarded: 'YOUR_IOS_REWARDED_ID',
androidAppOpen: 'YOUR_ANDROID_APP_OPEN_ID',
iosAppOpen: 'YOUR_IOS_APP_OPEN_ID',
androidNativeSmall: 'YOUR_ANDROID_NATIVE_ID',
iosNativeSmall: 'YOUR_IOS_NATIVE_ID',
androidNativeMedium: 'YOUR_ANDROID_NATIVE_ID',
iosNativeMedium: 'YOUR_IOS_NATIVE_ID',
androidNativeFull: 'YOUR_ANDROID_NATIVE_ID',
iosNativeFull: 'YOUR_IOS_NATIVE_ID',
),
),
);
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
navigatorObservers: [
AnalyticsService.observer,
],
home: const HomePage(),
);
}
}
class HomePage extends StatelessWidget {
const HomePage({super.key});
Future<void> _showInterstitial(BuildContext context) async {
await InterstitialAdService.show(
context: context,
);
}
Future<void> _showRewarded() async {
await RewardedAdService.show(
onRewardEarned: (reward) {
debugPrint('Reward earned: ${reward.amount} ${reward.type}');
},
);
}
Future<void> _showNativePopup(BuildContext context) async {
await NativePopupAd.show(
context,
type: NativeAdType.full,
);
}
Future<void> _tapAd(BuildContext context) async {
final shouldShow = AdFrequencyManager.shouldShow(
placement: 'home_button',
showEvery: RemoteConfigService.interstitialClickCount,
cooldown: const Duration(seconds: 30),
);
if (shouldShow) {
await InterstitialAdService.show(
context: context,
);
AdFrequencyManager.markShown(
placement: 'home_button',
);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
bottomNavigationBar: const BannerAdWidget(
collapsible: false,
),
appBar: AppBar(
title: const Text('Monetization Kit Example'),
),
body: ListView(
padding: const EdgeInsets.all(16),
children: [
ElevatedButton(
onPressed: () => _showInterstitial(context),
child: const Text('Show Interstitial'),
),
ElevatedButton(
onPressed: _showRewarded,
child: const Text('Show Rewarded'),
),
ElevatedButton(
onPressed: () => _showNativePopup(context),
child: const Text('Show Native Popup'),
),
ElevatedButton(
onPressed: () => _tapAd(context),
child: const Text('Tap Counter Ad'),
),
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => const FeedbackScreen(
webhookUrl: 'YOUR_DISCORD_WEBHOOK_URL',
),
),
);
},
child: const Text('Feedback Screen'),
),
ElevatedButton(
onPressed: () async {
await FullscreenNativeTimerAd.show(
context,
duration: const Duration(seconds: 10),
);
},
child: const Text('Fullscreen Timer Ad'),
),
const SizedBox(height: 20),
const NativeAdWidget(
type: NativeAdType.small,
useCache: true,
),
const SizedBox(height: 20),
const NativeAdWidget(
type: NativeAdType.medium,
useCache: true,
),
const SizedBox(height: 20),
const NativeAdWidget(
type: NativeAdType.full,
useCache: true,
),
],
),
);
}
}