如何在 Flutter 中使用 RevenueCat PurchaserInfoUpdateListener

How to use RevenueCat PurchaserInfoUpdateListener in Flutter

我在 Flutter 上使用 RevenueCat,我在哪里调用:

Purchases.addPurchaserInfoUpdateListener((purchaserInfo) => {});

以便我可以在我的整个应用程序中收听购买状态的更新?谢谢

您可以Purchases.addPurchaserInfoUpdateListener((purchaserInfo) => {});到您的应用小工具的initState

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
    Purchases.addPurchaserInfoUpdateListener((purchaserInfo) => {
      // do what you want with the purchase info
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: Constants.appName,
      theme: ThemeConfig.lightTheme,
      home: Splash(),
    );
  }
}