我正在使用收入猫来管理应用内订阅程序。对于免费用户,我想为高级用户显示不同的主页和不同的主页。这是我的底部导航,请帮助。
所以总的来说,用户将使用电子邮件注册,导航到他们将支付的页面,如果支付成功,我们将向他们显示不同的页面并保持状态。
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();
}
}