PurchasesDart
PurchasesDart is a Dart implementation of the purchases_flutter plugin, designed to facilitate in-app purchases and subscriptions with Web Billing. The purchases_dart package closely follows the native APIs from purchases_flutter.
Usage
Configure
Before using PurchasesDart, you must configure it with a PurchasesDartConfiguration. This configuration requires a Web Billing API key and an appUserId.
await PurchasesDart.configure(
PurchasesDartConfiguration(
apiKey: WEB_BILLING_API_KEY,
appUserId: "MY_USER_ID",
),
);
appUserId is an optional parameter used to identify users of your app. While optional, it is crucial to provide a persistent appUserId per user if you want to restore purchases after re-installing the app.
Why it matters: Purchase data is stored on RevenueCat's backend and associated with the appUserId. If you can provide the same appUserId after reinstall, purchases can be restored. If not provided, an anonymous ID is generated and stored locally on the device, which is lost when the app is uninstalled.
Best practice: Use an authentication system (e.g., Firebase Authentication) to generate and persist a stable appUserId that can be retrieved after app reinstall.
Get Customer Info
await PurchasesDart.getCustomerInfo();
Get Offerings
await PurchasesDart.getOfferings();
Purchase a Package
Step 1: Configure Web Purchase Link in RevenueCat Dashboard
In order to make purchases, you need a webCheckoutUrl. In order to have webCheckoutUrl populated, you need to create a Web Purchase Link for your offering. Here are the docs that explain how to do that.
Step 2: Get and Launch the Web Purchase Link
Retrieve the web purchase link for a package and launch it in the user's browser:
Uri? webCheckoutUrl = await PurchasesDart.getWebCheckoutUrl(
package,
email: userEmail, // Optional: pre-fill the user's email
);
if (webCheckoutUrl != null) {
await launchUrl(webCheckoutUrl); // Using url_launcher package
}
Make sure to import and use the url_launcher package to launch the URL.
Step 3 (Optional): Configure Deep Linking for Post-Purchase Redirect
To redirect users back to your app after a successful purchase:
- In the Web Purchase Link configuration, go to the Success section
- Choose Redirect to a custom success page
- Set a URL that can open your app using a deep link
- Configure deep link handling in your app using app_links
🧩 Apps using Purchases Dart
Here are some of the apps leveraging the power of purchases_dart in production:
| BT Cam A Bluetooth remote app for DSLR and mirrorless cameras. Compatible with Canon, Nikon, Sony, Fujifilm, GoPro, Olympus, Panasonic, Pentax, and Blackmagic. Built using Purchases Dart to enable app purchases across iOS, Android, macOS, Windows, Linux & Web. |
|---|
💡 Built something cool with Purchases Dart?
We'd love to showcase your app here!
Open a pull request and add it to this section. Please include your app icon in svg!