This is your go-to guide for integrating in-app purchases into your FlutterFlow apps. We’ll walk through building a weather app with premium features unlocked via in-app purchases. Think of it like adding superpowers to your app! 💪
🗺️ App Overview: Our Weather App Blueprint
Our app will have three core screens:
- Home: Displays a list of cities with basic weather information. Users can add cities, but the free plan limits them to two.
- Detail: Shows detailed weather information for a selected city, including a 3-day forecast. Unlocking a 7-day forecast requires a premium purchase.
- Settings: Allows users to switch between Celsius and Fahrenheit and manage their premium subscription.
🔑 The Power of RevenueCat: Your In-App Purchase Ally
Instead of handling in-app purchases manually, we’ll use RevenueCat, a powerful tool that simplifies the process. It acts as a bridge between your app and app stores like Apple App Store and Google Play.
Why RevenueCat? 🤔
- Free for most: RevenueCat is free until you hit \$2,500 in monthly revenue. Talk about a generous free tier! 💸
- Simplified management: It handles subscriptions, product offerings, and purchase tracking, making your life easier.
- Cross-platform support: RevenueCat works seamlessly across iOS, Android, and other platforms.
⚙️ Setting Up RevenueCat: Laying the Foundation
- Create a RevenueCat Account: Head over to RevenueCat.com and sign up for a free account.
- New Project: Create a new project in RevenueCat and name it something relevant, like “WeatherProApp”.
- Add Your App: Select the appropriate app store (e.g., Apple App Store) and enter your app details. You’ll need your app’s bundle ID and an App Store Connect app-specific shared secret.
- Configure In-App Purchase Key: Follow RevenueCat’s instructions to generate an in-app purchase key in App Store Connect and upload it to your RevenueCat project.
- Define Products: In App Store Connect, create a subscription group (e.g., “WeatherPro Premium”) and add subscriptions within that group (e.g., a yearly subscription). Define pricing, trial periods, and introductory offers.
- Entitlements in RevenueCat: Create an entitlement in RevenueCat (e.g., “WeatherPro”) and attach the products (subscriptions) you defined in App Store Connect. This entitlement represents the premium access users will purchase.
- Offerings: (Optional) Create offerings in RevenueCat to group and present different product packages to users.
🔌 Connecting FlutterFlow to RevenueCat: Bridging the Gap
- Custom Actions: In FlutterFlow, you’ll use custom actions to interact with RevenueCat. You’ll need three key actions:
- Connect to RevenueCat: Initializes the connection using your RevenueCat API key.
- Check Entitlement: Determines if the user has purchased the premium entitlement.
- Purchase Product: Initiates the purchase flow for a selected product.
- App State Variables: Create App State variables to store:
- Purchase Status: A boolean indicating whether the user has premium access.
- Offerings: A list to store available product offerings retrieved from RevenueCat.
🎨 Building the UI: Designing the User Experience
- Home Screen:
- Design the city list using a
ListView
widget. - Conditionally display a “Get Premium Access” card if the user doesn’t have premium access.
- Use a horizontal
ListView
to display available product offerings retrieved from RevenueCat. - Add a “Continue” button to initiate the purchase flow.
- Design the city list using a
- Detail Screen:
- Display detailed weather information.
- Conditionally show the 7-day forecast only if the user has premium access.
- Settings Screen:
- Use a
SwitchTile
to allow users to toggle between Celsius and Fahrenheit. - Display the premium purchase status (active/inactive).
- Add a button to let users manage their subscription.
- Use a
🧵 Tying It All Together: Implementing the Logic
- Initial Setup: On app launch, use the “Connect to RevenueCat” custom action to establish a connection.
- Check Premium Status: Use the “Check Entitlement” custom action to determine if the user has premium access and update the App State variable accordingly.
- Conditional UI: Based on the premium status, show or hide premium features (e.g., 7-day forecast, additional cities).
- Display Offerings: Use the “Get Offerings” custom action to retrieve available product offerings from RevenueCat and populate the horizontal
ListView
on the Home screen. - Purchase Flow: When the user clicks “Continue,” use the “Purchase Product” custom action, passing the selected package ID.
- Settings Screen: Update the premium status display and link the manage subscription button to RevenueCat’s management screen.
🧪 Testing: Ensuring Everything Works
- StoreKit Configuration File: To test in-app purchases on a simulator, create a
StoreKit Configuration File
in Xcode. This file simulates App Store Connect behavior. - Run on Simulator: Build and run your app on an iOS simulator.
- Test Purchase Flow: Verify that product offerings are displayed correctly, the purchase flow works as expected, and premium features unlock after a successful purchase.
🧰 Resource Toolbox
- RevenueCat: https://www.revenuecat.com
- Purchases Flutter (RevenueCat Flutter Plugin): https://pub.dev/packages/purchases_flutter
- FlutterFlow: https://flutterflow.io
- App Store Connect: https://appstoreconnect.apple.com
Remember, this is just a starting point. You can customize your weather app and in-app purchase implementation to fit your specific needs and create an even more engaging user experience. Good luck! 🎉