0

i am using revenuecat to manage a in-app subscription program. For free users, i want to show a different home page and different home page for premium users. This is my bottom navigation, please help.

So overall, user will sign up using email, navigate to a page where they will make payment and if payment is successfull, we will show them a different page and maintain the status.

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:purchases_flutter/offerings_wrapper.dart';
import 'package:purchases_flutter/purchases_flutter.dart';


import 'home.dart';
import 'homefree.dart';


class bottomNavi extends StatefulWidget {
bottomNavi({Key? key}) : super(key: key);


@override
_bottomNaviState createState() => _bottomNaviState();
}

class _bottomNaviState extends State<bottomNavi> {


 int _selectedIndex = 0;

 static const TextStyle optionStyle = TextStyle(fontSize: 30, fontWeight: 
FontWeight.bold);
 final _pages = <Widget>[

 
home() or homeFree(), // based on entitlement status/value
list(),//this is a stateful widget on a separate file
 account(),//this is a stateful widget on a separate file


 ];

  void _onItemTapped(int index) {
  setState(() {
  _selectedIndex = index;
   });
}
@override
Widget build(BuildContext context) {

return Scaffold(

  body: Center(
    child: _pages.elementAt(_selectedIndex),
  ),
  bottomNavigationBar: BottomNavigationBar(
    items: const <BottomNavigationBarItem>[
      BottomNavigationBarItem(
        icon: Icon(Icons.home),
        label: 'home',
      ),
      BottomNavigationBarItem(
        icon: Icon(Icons.description),
        label: 'todo',

      ),
      BottomNavigationBarItem(
        icon: Icon(Icons.account_box),
        label: 'Account',
      ),
    ],
    currentIndex: _selectedIndex,
    selectedItemColor: Colors.amber[800],
    onTap: _onItemTapped,
    ),
   );
   }
   }

  class RevenueCatProvider extends ChangeNotifier{
  RevenueCatProvider() {
  init();
  }

  Entitlement _entitlement = Entitlement.free;
  Entitlement get entitlement => _entitlement;

  Future init() async {
  Purchases.addPurchaserInfoUpdateListener((purchaserInfo) async {
  updatePurchaseStatus();
  });

  }

 Future updatePurchaseStatus() async {
 final purchaseInfo = await Purchases.getPurchaserInfo();
 final entitments = purchaseInfo.entitlements.active.values.toList();

 _entitlement = entitments.isEmpty ? Entitlement.free : Entitlement.all_charts;

 notifyListeners();


}
}
akhicoda
  • 139
  • 1
  • 1
  • 12

1 Answers1

0

I have two possible solutions:

  1. If you use a own backend server or firestore (Firebase)

You should add an a boolean attribute to user called something like "premium", and use this value to show a premium or free view.

  1. If you don't use a backend server.

You can use the purchases_flutter package, and use a function to the verify if a current user is premium, and save this value in the local storage, and verify this each time that you open the app.

I recommended the first way.

Felipe Vergara
  • 849
  • 7
  • 12
  • I am using firestore. Can you please add some more details? – akhicoda Sep 19 '21 at 17:15
  • You can create a collection in firestore called "users", and each document should have the information of user, like name, email, etc. in this document you should add an attribute called "premium", and when you start your app, you verify with the package if the current user is premium or not, and this value you should save in his document on firestore. So every time you start the app you will know if the user is premium or not. – Felipe Vergara Sep 19 '21 at 17:20