Contribute to the Flutter SDK

  • 5 November 2023
  • 0 replies
  • 17 views

Badge +3

The StoreProduct class in the RevenueCat package (purchases_flutter) contains information about purchasable items, such as subscription details, pricing, and currency. For a typical paywall implementation, one needs to derive various display strings from this class, such as:

  • Monthly price conversion
  • Combined period and monthly price (e.g., "$69.99/yr ($5.83/mo)")
  • Subscription period in full text ("Annual" / "Monthly")
  • Subscription period in short form ("yr" / "mo")

...among others. Considering that such functionality is universally needed, I'm pondering the best way to implement these derived calculations.
Option 1: Utility Functions
Write individual functions within a Utils class.
Pro: Centralized location for all related functions.
Con: Potential clutter with a Utils class filled with numerous functions.

Option 2: Class Extensions
Create an extension on StoreProduct to include getters for each needed calculation.
Pro: Elegant and intuitive usage (e.g., myProduct.monthlyPrice).
Con: Overloads the class with additional properties, which may not be desirable.

I want to implement it in a way that is easy to use and understand.

Also, I'm considering contributing this to the RevenueCat flutter SDK, since every person using their package MUST implement this in one way or another.


0 replies

Be the first to reply!

Reply