Mobile apps primarily rely on two monetization strategies: ads and subscriptions. While ads provide free access to users and generate revenue for developers, they often disrupt the user experience and can lead to frustration. This creates an opportunity for developers to offer a premium, ad-free experience through subscriptions—a win-win solution that enhances user satisfaction while generating recurring revenue.

In this guide, we’ll walk you through the process of implementing an ad-free subscription in your Flutter app using RevenueCat. This tutorial has you covered even if you’re new to subscriptions and ads. Things we will be doing in this tutorial:

  • Adding ads to our app using AdMob and google_mobile_ads package
  • Adding subscriptions to our app using RevenueCat and flutter_purchases
  • Configuring ads to be shown only if user is currently not subscribed, after subscribing all ads will be hidden from the users view

By the end of this article you should have a Flutter app for iOS and Android, that is capable of showing ads, displaying a paywall, and after purchasing a subscription from that paywall also able to hide the ads for the subscribed user.

Track ad revenue in RevenueCat

You can now track your AdMob add revenue in Revenuecat and get a complete picture of your revenue. Simply replace your standard AdMob loading calls with the loadAndTrack methods from the RevenueCat SDK. All ad events are tracked automatically. Read more about our new in-app ad revenue in our announcement blog post.

Prerequisites

In this tutorial, we will build a simple Flutter app, for both iOS and Android, that allows the user to subscribe to a monthly subscription which unlocks an ad-free experience in the app. If you have an existing app in which you’re going to implement subscription functionality, you can jump ahead to the next section.

Start by creating a new Flutter project. Follow the steps in this guide if you need a refresher. Open the project in your editor of choice. After that, run:

flutter run

Testing in-app purchases is best on a real device, so choose that option from the presented list and check that your app runs without problems.

Set up App Store and Play Store

Before we can move to implementing subscriptions in our app, we need to configure our subscription product for all the platforms we want to target. Since Flutter is a cross-platform framework, it’s a good idea to target both iOS and Android. In both cases we want to configure a single subscription: a monthly recurring subscription for 5 dollars.

Create yourself a RevenueCat account and then follow this guide to connect the App Store and Play store to RevenueCat.

Step 1: Add ads to your Flutter app

Displaying ads in the app can be done with Google AdMob. Using it requires creating an account, create one if you haven’t already. After creating your account, create the new apps in the AdMob dashboard for all the platforms you plan to target.

Next step is to integrate the Google Mobile ADs SDK into a Flutter app. Add google_mobile_ads to the pubspec.yaml file:

dependencies:
  google_mobile_ads: 6.0.0

We need to add AdMob App IDs to both the AndroidManifest.xml file (for Android) and the Info.plist file (for iOS) Make the following changes:

<key>GADApplicationIdentifier</key>
<string>ca-app-pub-3940256099942544~1458002511</string>
<!-- Add inside the existing <application> element. Keep the rest of the manifest. -->
<meta-data
    android:name="com.google.android.gms.ads.APPLICATION_ID"
    android:value="ca-app-pub-3940256099942544~3347511713" />

Before we add the code for initializing the ads (and later subscriptions), let’s go over the project structure. Both the subscription and ads logic will be placed in a file called subscription_manager.dart. Create that file inside a services folder . The complete implementation is shown below:

Next we need to initialize the ads at app startup. The complete main.dart example below calls the manager.

Displaying Banner ads

Create a new file called banner_ad_widget.dart file and paste the contents from below:

lib/widgets/banner_ad_widget.dart
import 'package:flutter/material.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';

class BannerAdWidget extends StatefulWidget {
  const BannerAdWidget({super.key, required this.adUnitId});
  final String adUnitId;
  @override
  State<BannerAdWidget> createState() => _BannerAdWidgetState();
}

class _BannerAdWidgetState extends State<BannerAdWidget> {
  BannerAd? _banner;
  bool _loaded = false;
  @override
  void initState() {
    super.initState();
    _banner = BannerAd(
      adUnitId: widget.adUnitId,
      size: AdSize.banner,
      request: const AdRequest(),
      listener: BannerAdListener(
        onAdLoaded: (ad) { if (mounted) setState(() => _loaded = true); },
        onAdFailedToLoad: (ad, error) {
          ad.dispose();
          if (mounted) setState(() { _banner = null; _loaded = false; });
        },
      ),
    )..load();
  }
  @override
  void dispose() { _banner?.dispose(); super.dispose(); }
  @override
  Widget build(BuildContext context) {
    final banner = _banner;
    if (!_loaded || banner == null) return const SizedBox.shrink();
    return SizedBox(width: banner.size.width.toDouble(), height: banner.size.height.toDouble(),
      child: AdWidget(ad: banner));
  }
}

This component will display adaptive banner ads between the paragraphs. The widget manages the banner lifecycle.

Use the complete main.dart example below to make use of the new Banner ads:

After these code changes, your apps should look like this:

Step 2: set up products

Once you’ve configured the store of your choice, or both in the previous steps, it’s time to set up Revenuecat. If you’re not familiar with Revenuecat, or time has passed since the last time you used it, this quickstart guide will help you get up to speed.

You need to configure your RevenueCat products, offerings and entitlements to have:

  • One entitlement for the ad-free subscription level, using the identifier ad_free_entitlement
  • Two separate products for App Store and Play Store, for example with identifier ad_free_monthly (learn more about the naming practices: iOS, Android)
  • Matching subscriptions in Play Store console and App Store connect with the same identifiers

Remember to group your product under the entitlement you created.

Step 3: Add subscriptions to your Flutter app

Now that we have everything configured, it’s time to add purchases_flutter and purchases_ui_flutter; the Flutter client for RevenueCat subscriptions and paywall UI components. Add the dependencies:

dependencies:
  flutter:
    sdk: flutter
  google_mobile_ads: 6.0.0
  purchases_flutter: 11.0.4
  purchases_ui_flutter: 11.0.4

We want RevenueCat to be initialized when the application starts, so at the same time as we initialize the ads. Update SubscriptionManager:

lib/services/subscription_manager.dart
import 'package:flutter/foundation.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';
import 'package:purchases_flutter/purchases_flutter.dart';

class SubscriptionManager extends ChangeNotifier {
  static const entitlementId = 'ad_free_entitlement';
  bool? adFree;
  String? error;
  bool _disposed = false;

  Future<void> initialize() async {
    final String apiKey;
    if (kIsWeb) throw UnsupportedError('This example is for iOS and Android.');
    switch (defaultTargetPlatform) {
      case TargetPlatform.iOS:
        apiKey = const String.fromEnvironment('RC_IOS_KEY');
        break;
      case TargetPlatform.android:
        apiKey = const String.fromEnvironment('RC_ANDROID_KEY');
        break;
      default:
        throw UnsupportedError('This example is for iOS and Android.');
    }
    if (apiKey.isEmpty) throw StateError('Supply the RevenueCat SDK key with --dart-define.');
    await Purchases.configure(PurchasesConfiguration(apiKey));
    Purchases.addCustomerInfoUpdateListener(_update);
    // Complete the consent flow before this call in a production app.
    await MobileAds.instance.initialize();
    await refresh();
  }

  void _update(CustomerInfo info) {
    if (_disposed) return;
    adFree = info.entitlements.active.containsKey(entitlementId);
    error = null;
    notifyListeners();
  }

  Future<void> refresh() async {
    try { _update(await Purchases.getCustomerInfo()); }
    catch (_) {
      if (!_disposed) { error = 'Could not check your subscription.'; notifyListeners(); }
    }
  }

  Future<bool> restore() async {
    final info = await Purchases.restorePurchases();
    _update(info);
    return adFree == true;
  }

  @override
  void dispose() {
    _disposed = true;
    Purchases.removeCustomerInfoUpdateListener(_update);
    super.dispose();
  }
}

You can use the RevenueCat public API key directly or pass RC_API_KEY with --dart-define as in this example. If you see RevenueCat error logs in the console, review and fix them.

Checking user entitlements

To keep track of whether a user has purchased a subscription and is eligible for ad-free experience, we implement a helper service. The manager above checks the entitlement and listens for changes.

Using the entitlement status in your UI

Before showing ads we need to check if user is subscribed:

lib/main.dart
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:purchases_ui_flutter/purchases_ui_flutter.dart';
import 'services/subscription_manager.dart';
import 'widgets/banner_ad_widget.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  final manager = SubscriptionManager();
  try {
    await manager.initialize();
    runApp(MaterialApp(home: ArticlePage(manager: manager)));
  } catch (_) {
    runApp(const MaterialApp(home: Scaffold(body: Center(child: Text('Could not initialize the app.')))));
  }
}

class ArticlePage extends StatefulWidget {
  const ArticlePage({super.key, required this.manager});
  final SubscriptionManager manager;
  @override
  State<ArticlePage> createState() => _ArticlePageState();
}

class _ArticlePageState extends State<ArticlePage> with WidgetsBindingObserver {
  bool _busy = false;
  String _message = '';
  @override
  void initState() { super.initState(); WidgetsBinding.instance.addObserver(this); }
  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    if (state == AppLifecycleState.resumed) widget.manager.refresh();
  }
  @override
  void dispose() {
    WidgetsBinding.instance.removeObserver(this);
    widget.manager.dispose();
    super.dispose();
  }
  Future<void> _purchase() async {
    setState(() => _busy = true);
    try {
      final result = await RevenueCatUI.presentPaywall(displayCloseButton: true);
      if (result == PaywallResult.error) throw StateError('Paywall failed.');
      await widget.manager.refresh();
    } catch (_) { if (mounted) setState(() => _message = 'Could not complete the purchase. Please retry.'); }
    finally { if (mounted) setState(() => _busy = false); }
  }
  Future<void> _restore() async {
    setState(() => _busy = true);
    try {
      final restored = await widget.manager.restore();
      if (mounted) setState(() => _message = restored ? 'Ad-free access restored.' : 'No active subscription found.');
    } catch (_) { if (mounted) setState(() => _message = 'Could not restore purchases. Please retry.'); }
    finally { if (mounted) setState(() => _busy = false); }
  }
  @override
  Widget build(BuildContext context) => ListenableBuilder(
    listenable: widget.manager,
    builder: (context, _) {
      final manager = widget.manager;
      if (manager.adFree == null && manager.error == null) {
        return const Scaffold(body: Center(child: CircularProgressIndicator()));
      }
      // Google's published test banner IDs. Replace only for release builds.
      final testId = defaultTargetPlatform == TargetPlatform.iOS
        ? 'ca-app-pub-3940256099942544/2934735716'
        : 'ca-app-pub-3940256099942544/6300978111';
      return Scaffold(
        appBar: AppBar(title: const Text('Article')),
        body: ListView(padding: const EdgeInsets.all(16), children: [
          const Text('Your article content goes here.'),
          Text(manager.error ?? _message),
          if (manager.adFree == false && manager.error == null)
            Center(child: BannerAdWidget(adUnitId: testId)),
          if (manager.adFree != true)
            ElevatedButton(onPressed: _busy ? null : _purchase, child: const Text('Remove ads')),
          TextButton(onPressed: _busy ? null : _restore, child: const Text('Restore purchases')),
          if (manager.error != null)
            TextButton(onPressed: () { manager.refresh(); }, child: const Text('Retry access check')),
        ]),
      );
    },
  );
}

Implement purchasing functionality

Now that we can check if a user has purchased a subscription, it’s time to implement the purchasing functionality. We can do this easily with RevenueCat paywalls, which you can then customize through RevenueCat’s dashboard. Learn more about paywalls here.

The complete main.dart example below shows the paywall and restore actions:

Run the app on a real device, press the button, and complete the purchase flow. After a successful purchase, the app will update to remove ads and give the user the ad-free experience.

Conclusion

Great work! You’ve successfully built a Flutter app that lets users subscribe to unlock an ad-free experience. From integrating AdMob for ads to implementing subscriptions with RevenueCat, you now have a strong foundation for monetizing your app. From here, you can take things further—customize your paywall directly in the RevenueCat dashboard, experiment with different pricing strategies, or add premium features that offer even more value behind the subscription. This is just the beginning of what’s possible with a flexible, subscription-based model.