Home > Net >  flutter problem: This expression has a type of 'void' so its value can't be used
flutter problem: This expression has a type of 'void' so its value can't be used

Time:09-17

this is my flutter stripe code, Here I want response of SetupPaymentSheetParameters and presentPaymentSheet I want to check what king of response I am getting,

Future<void> makePayment(data) async {
    print(data['clientSecret']);
  try {
      await Stripe.instance
          .initPaymentSheet(
              paymentSheetParameters: SetupPaymentSheetParameters(
            paymentIntentClientSecret: "${data['clientSecret']}",
            style: ThemeMode.dark,
          ))
          .then((value) {});

      ///now finally display payment sheeet
    displayPaymentSheet();
  } catch (e, s) {
    print('exception:$e$s');
  }
}

displayPaymentSheet() async {
  try {
    await Stripe.instance.presentPaymentSheet(
    ).then((value){
      showDialog(
          context: context,
          builder: (_) => AlertDialog(
            content: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                Row(
                  children: const [
                    Icon(Icons.check_circle, color: Colors.green,),
                    Text("Payment Successfull"),
                  ],
                ),
              ],
            ),
          ));
      // ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text("paid successfully")));
    }).onError((error, stackTrace){
      print('Error is:--->$error $stackTrace');
    });
  } on StripeException catch (e) {
    print('Error is:---> $e');
    showDialog(
        context: context,
        builder: (_) => const AlertDialog(
          content: Text("Cancelled "),
        ));
  } catch (e) {
    print('$e');
  }
}

Here I getting something like this is happening I dont know. enter image description here

CodePudding user response:

try this :

return type of SetupPaymentSheetParameters should be Future

change your print method to this :

print(value.toString());

hope it will help!

CodePudding user response:

For help with the flutter_stripe package you'll want to reach out to the developers to get better explanations.

However, it looks like your value is actually attached to the result of initPaymentSheet, which is void. SetupPaymentSheetParameters should return json data for use with initPaymentSheet.

  • Related