Flutter tip RevenueCat boilerplate

Flutter tips Published on

Working with subscriptions in your Flutter app using the RevenueCat package is great, but sometimes you need little helpers to make things smoother. Here are some useful extension methods that can save you time and make your code cleaner.

Get subscription product period as Duration

Understanding the exact duration of a subscription period can be tricky with different formats like P1W, P1M, etc. This extension converts the subscriptionPeriod property into a standard Dart Duration object.

duration get duration => switch(revenueCatPackage.storeProduct.subscriptionPeriod) {
  'P1W' => const Duration(days: 7),
  'P1M' => const Duration(days: 30),
  'P3M' => const Duration(days: 90),
  'P6M' => const Duration(days: 180),
  'P1Y' => const Duration(days: 365),
  _ => Duration.zero,
};

Get the number of trial days for a product

If your product offers a free trial, you'll often need to know how many days it lasts. This method checks the introductory price and calculates the total trial days.

int? get trialDays {
  final introductory = revenueCatPackage.storeProduct.introductoryPrice;
  if (introductory == null) {
    return null;
  }
  if (introductory.price == 0) {
    final unit = introductory.periodUnit;
    switch (unit) {
      case PeriodUnit.day:
        return introductory.periodNumberOfUnits;
      case PeriodUnit.week:
        return introductory.periodNumberOfUnits * 7;
      case PeriodUnit.month:
        return introductory.periodNumberOfUnits * 30;
      case PeriodUnit.year:
        return introductory.periodNumberOfUnits * 365;
      default:
        return null;
    }
  }
  return null;
}

Get the list of features from the RevenueCat metadata according to user language

Product metadata is a handy place to store information like key features. This extension helps you fetch a list of features stored in the metadata, specifically for the user's current language.

List<String>? get features {
  final locale = LocaleSettings.currentLocale.languageCode;
  if (revenueCatOffer.metadata[locale] == null) {
    return null;
  }
  final data = revenueCatOffer.metadata[locale] as Map<Object?, Object?>;
  final featuersObj = data["features"]! as List<Object?>;
  return featuersObj.map((e) => e! as String).toList();
}

These simple extensions can help you manage common tasks with RevenueCat data more effectively in your Flutter app.

Save 3 months of work

Create your app using our 6 years of making Flutter apps and more than 50+ apps

kickstarter for flutter apps

Frequently Asked Questions

What is RevenueCat?

RevenueCat is a service and SDK used by app developers to handle subscriptions and in-app purchases easily across different platforms like iOS and Android.

What do these code examples show?

These are Dart code examples for Flutter, showing how to create helpful extension methods to get information from the RevenueCat package, specifically about subscription duration, trial days, and features stored in metadata.

How can these methods make my life easier?

They provide ready-to-use functions to access common data points from RevenueCat objects in a more convenient format, saving you from writing the same logic repeatedly in your app.

Read more
You may also be interested in
Flutter tips: how to create a responsive layout  blog card image
Flutter tips: how to create a responsive layout
Published on 2025-05-03
How to open the system app settings page  blog card image
How to open the system app settings page
Published on 2025-05-02
ApparenceKit is a flutter template generator tool by Apparence.io © 2025.
All rights reserved