π cas_ad_manager
A simple and reusable ad manager built around the Clever Ads Solutions (CAS) Flutter SDK. This manager handles initialization, loading, and displaying of interstitial and rewarded ads with automatic reloads and error handling.
β¨ Features
- β Initializes CAS SDK with one method
- π Supports Interstitial and Rewarded ads
- π Automatically reloads ads after each show
- βοΈ Custom callbacks for ad closed, rewarded, or failed events
- π§ Prevents duplicate ad shows (uses internal flags)
π¦ Installation
1οΈβ£ Add Dependency
In your pubspec.yaml file:
dependencies:
flutter:
sdk: flutter
clever_ads_solutions: ^3.5.0 # check for latest version
Then run:
flutter pub get
βοΈ Setup
Step 1: Android Configuration
Ensure you follow the CAS Android integration guide to update your AndroidManifest.xml and other project files.
Step 2: iOS Configuration
Ensure platform-specific setup for iOS is also complete (App Tracking Transparency, Ad Network IDs, etc.)
π Usage
Step 1: Create Config
final casConfig = CasConfig(
casId: 'YOUR_CAS_ID',
testMode: true, // Enable for testing
debugMode: true, // Logs info in console
);
Step 2: Initialize in main.dart
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await CasAdManager().initialize(casConfig);
runApp(MyApp());
}
Step 3: Show Interstitial Ad
CasAdManager().showInterstitial(onFinished: () {
print('Interstitial closed.');
});
Step 4: Show Rewarded Ad
CasAdManager().showRewardedAd(
onCompleted: () {
print('User earned reward.');
},
onFailed: () {
print('Rewarded ad failed or not ready.');
},
);
π§ Internals
CasAdManager Singleton
Handles:
- Initialization (only once)
- Loading interstitial and rewarded ads
- Showing ads with state checks
- Resetting and reloading ads after interaction
CasConfig
class CasConfig {
final String casId;
final bool testMode;
final bool debugMode;
const CasConfig({
required this.casId,
this.testMode = false,
this.debugMode = false,
});
}
Custom Callbacks
Located in cas_callbacks.dart:
CasInterstitialCallbackCasRewardedCallback
These manage ad events and reset flags or reload ads accordingly.
β FAQ
Q: Does it handle ad loading automatically?
A: Yes, ads are loaded on initialization and reloaded after each display.
Q: What happens if the ad isnβt ready?
A: The fallback logic triggers your onFinished or onFailed callbacks, and it tries to reload the ad.
Q: Can I use it for banner/native ads?
A: No, this package is focused on interstitial and rewarded ads only.
π§ͺ Optional: Manual Reload
CasAdManager().loadAll(); // Reload both ad types manually
π± Platform Support
| Platform | Supported |
|---|---|
| Android | β |
| iOS | β |
| Web | β |
| Desktop | β |