0

我正在使用收入猫来管理应用内订阅程序。对于免费用户,我想为高级用户显示不同的主页和不同的主页。这是我的底部导航,请帮助。

所以总的来说,用户将使用电子邮件注册,导航到他们将支付的页面,如果支付成功,我们将向他们显示不同的页面并保持状态。

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();


}
}
4

1 回答 1

0

我有两种可能的解决方案:

  1. 如果您使用自己的后端服务器或 Firestore (Firebase)

您应该为用户添加一个名为“premium”之类的布尔属性,并使用此值来显示高级或免费视图。

  1. 如果您不使用后端服务器。

您可以使用 purchase_flutter 包,并使用一个函数来验证当前用户是否为高级用户,并将此值保存在本地存储中,并在每次打开应用程序时验证此值。

我推荐第一种方式。

于 2021-09-19T16:31:00.303 回答