【发布时间】:2021-07-27 10:03:13
【问题描述】:
在我的应用程序中,我在一个页面中调用 startTransaction() 插件方法,并将响应存储在 paytm 文档中。在收到响应时,我想将成功或失败的状态返回到上一页。所以在 init() 函数中,我调用了另一个异步方法来 startTransaction 并检查响应。
PlatformException (0, Unknown error, {response : { response of transaction})
class StartTransaction extends StatefulWidget {
int orderId;
double totalAmount;
PaymentPayload paymentPayload;
bool success;
StartTransaction({this.orderId,this.totalAmount});
@override
_StartTransactionState createState() => _StartTransactionState();
}
class _StartTransactionState extends State<StartTransaction> {
@override
void initState() {
super.initState();
initiateTransaction();
}
Future initiateTransaction() async {
if(widget.success == null){
widget.paymentPayload = await createPaymentGateway(
widget.orderId,
userBloc.userData.username,
widget.totalAmount.toStringAsFixed(2),
context);
var pgResp = AllInOneSdk.startTransaction(
widget.paymentPayload.mid,
widget.orderId.toString(),
widget.totalAmount.toStringAsFixed(2),
widget.paymentPayload.txnToken,
widget.paymentPayload.callbackUrl,
true,
false);
pgResp.then((value) {
print(value);
setState(() {
widget.success = value['RESPCODE'] == 01;
});
}).catchError((onError) {
setState(() {
widget.success = false;
});
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: FutureBuilder(
builder: (context, snapshot) {
if(widget.success == true) {
print('Payment successful');
Navigator.pop(context,true);
} else if(widget.success == false) {
print('Payment unsuccessful');
Navigator.pop(context,false);
}
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text('We are processing your transaction', style: TextStyle(fontSize: 36),),
CircularProgressIndicator(),
],
),
);
}
),
),
);
}
}```
【问题讨论】:
标签: flutter exception hybrid-mobile-app platform paytm