[Solved] Flutter null check operator used on a null value flutter

Question

Asked by cvsrt on December 15, 2021 (source).

I am trying to check if user make a payment or not.If payment is done, user will see homepage.If payment is not done User will see the payment page. The problem is that I am getting null check operator used on a null value. What I am doing wrong?

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);
      },
    );

  }
}

Answer

Question answered by cvsrt (source).

It is my mistake:

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

I didn't assign anything to offer variable.

FLUTTER REVENUECAT
SHARE: