rewarded_ad_counter 0.0.3
rewarded_ad_counter: ^0.0.3 copied to clipboard
A stateful Flutter package to manage, count, and persist multiple AdMob rewarded ad views. Easily implement 'watch X ads to unlock' monetization mechanics.
import 'package:flutter/material.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';
import 'package:rewarded_ad_counter/rewarded_ad_counter.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
MobileAds.instance.initialize();
runApp(const ExampleApp());
}
class ExampleApp extends StatelessWidget {
const ExampleApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(home: ExampleHome());
}
}
class ExampleHome extends StatelessWidget {
const ExampleHome({super.key});
@override
Widget build(BuildContext context) {
const defaultConfig = RewardedAdCounterConfig(
productId: 'com.example.app.pro',
rewardedAdUnitIdAndroid: 'ca-app-pub-3940256099942544/5224354917',
rewardedAdUnitIdIos: 'ca-app-pub-3940256099942544/1712485313',
);
const customConfig = RewardedAdCounterConfig(
productId: 'com.example.app.pro',
rewardTimes: 2,
rewardDays: 5,
rewardedAdUnitIdAndroid: 'ca-app-pub-3940256099942544/5224354917',
rewardedAdUnitIdIos: 'ca-app-pub-3940256099942544/1712485313',
watchAdButtonBgColor: Color(0xFF1A73E8),
buyButtonBgColor: Color(0xFFEA4335),
strings: RewardedAdCounterStrings(
pageTitle: 'Earn Free Access',
proTitle: 'Get Premium — No ads forever',
proDescription:
'Buy the Premium version to remove all advertisements permanently.',
proLifetimeTitle: 'Premium — Ad-free forever',
proLifetimeDescription:
'You own the Premium version. Enjoy a completely ad-free experience.',
buyButtonText: 'Purchase Now',
rewardTitle: 'View {count} videos to win {days} days free',
rewardDescription:
'Watch {count} rewarded videos and unlock {days} days of premium features.',
activeTitle: 'Ads are hidden',
activeDescription: 'You still have {val} of ad-free time left.',
watchedCountText: '{val} out of {total} videos seen',
watchMoreText: 'See {val} more to unlock {days} days of premium',
activeBadgeText: 'Active — {val} left',
activeTipText: 'All advertisements are currently hidden from view.',
watchButtonText: 'Watch video',
loadingButtonText: 'Loading video…',
loadingRewardText: 'Please wait…',
unlockSnackbarText: 'Premium unlocked for {days} days!',
progressSavedText: '{val} out of {total} videos watched. Keep it up!',
adNotReadyText: 'The video is not ready yet. Please try again.',
alreadyUnlockedText: 'Premium is already active on this account.',
unavailableText: 'Purchases are not available at this time.',
productUnavailableText: 'The Premium product is not available yet.',
purchaseFailedText: 'We could not complete your Premium purchase.',
purchaseSucceededText: 'Premium is now active. Ads are now hidden.',
restoreSucceededText: 'Your Premium purchase has been restored.',
restoreFailedText: 'Could not restore your previous purchases.',
),
);
return Scaffold(
appBar: AppBar(title: const Text('Rewarded Ad Counter Example')),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Padding(
padding: EdgeInsets.symmetric(horizontal: 32),
child: Text(
'This example demonstrates the rewarded_ad_counter '
'package. Tap either button to open the rewarded ad '
'unlock page.',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 16),
),
),
const SizedBox(height: 40),
SizedBox(
width: 260,
child: const RewardedAdCounterEntryButton(
label: 'Open (default)',
config: defaultConfig,
),
),
const SizedBox(height: 12),
SizedBox(
width: 260,
child: const RewardedAdCounterEntryButton(
label: 'Open (custom)',
config: customConfig,
),
),
],
),
),
);
}
}