【问题标题】:How to show different page to free users and different page to paid users如何向免费用户显示不同的页面,向付费用户显示不同的页面
【发布时间】:2021-11-13 14:18:58
【问题描述】:

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

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

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


}
}

【问题讨论】:

    标签: flutter in-app-purchase revenuecat flutter-in-app-purchase


    【解决方案1】:

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

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

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

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

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

    我推荐第一种方式。

    【讨论】:

    • 我正在使用 Firestore。你能补充一些细节吗?
    • 您可以在firestore中创建一个名为“users”的集合,每个文档都应该有用户的信息,例如姓名,电子邮件等。在这个文档中您应该添加一个名为“premium”的属性,当您启动您的应用程序时,您会使用包验证当前用户是否是高级用户,并且您应该将此值保存在他在 firestore 上的文档中。因此,每次启动应用程序时,您都会知道用户是否是高级用户。
    猜你喜欢
    • 2020-12-28
    • 1970-01-01
    • 1970-01-01
    • 2013-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-22
    相关资源
    最近更新 更多