Flutter null 检查运算符用于 null 值 flutter

Flutter null check operator used on a null value flutter

我正在尝试检查用户是否付款或 not.If 付款已完成,用户将看到 homepage.If 付款未完成 用户将看到付款页面。问题是我在空值上使用了空检查运算符。我做错了什么?

class TwoPage extends StatelessWidget {

  Package? offer;
  PurchaserInfo? _purchaserInfo;
  bool? payment;



  Future<bool> ispaymentdone() async {
    await Purchases.setDebugLogsEnabled(true);
    await Purchases.setup("public_key");

    PurchaserInfo purchaserInfo = await Purchases.getPurchaserInfo();
    print(purchaserInfo);
    print("buraya kadar iyi");

    Offerings offerings = await Purchases.getOfferings();
    print(offerings);

    // optional error handling

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    //if (!mounted) return;
    _purchaserInfo = purchaserInfo;


    if(purchaserInfo.entitlements.all["content-usage"]!=null){

      if ( purchaserInfo.entitlements.all["content-usage"]!.isActive) {
        print("trueee");

        return true;
      }

    }

    return false;
}

  @override
  Widget build(BuildContext context) {
    return FutureBuilder(
      future: ispaymentdone(),
      builder: (context, snapshot) {
        if (snapshot.data == null)
          return SizedBox(
            child: Center(child: CircularProgressIndicator(color:Colors.purple)),
            height: 10.0,
            width: 10.0,
          );
        else if (snapshot.data == true)
          return NewHomeScreen();
        else
          return MainPayment(purchaserInfo: _purchaserInfo, offer: offer);
      },
    );

  }
}

这是因为你在你的变量上使用了空值检查运算符,但是当你想使用它时,那个特定变量的值是 NULL,要么你必须给出该变量的一些初始值或确保值不为空。

这是我的错误:

return MainPayment(purchaserInfo: _purchaserInfo, offer: offer);

我没有为提供变量分配任何东西。