πŸš€ 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:

  • CasInterstitialCallback
  • CasRewardedCallback

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 ❌

Libraries

cas_ad_manager