我想做个付款页面。首先,用户必须使用单选按钮选择支付方法,它有5个选项,然后当用户选择支付方法并单击“支付”按钮时,显示支付成功的页面。但我希望当用户选择选项5,并单击“支付”按钮,付款将失败(重定向到失败页,并再次回到支付页,以选择另一个选项),我如何能做到这一点?当用户选择数字5选项时,让“支付”按钮重定向到另一个页面?
这是单选按钮和支付按钮的代码:
Expanded(
child: ListView.separated(
itemCount: paymentLabels.length,
itemBuilder: (context, index) {
return ListTile(
leading: Radio<int?>(
activeColor: Colors.black,
value: index,
groupValue: value,
onChanged: (i) => setState(() => value = i),
),
title: Text(
paymentLabels[index],
style: TextStyle(color: Colors.black),
),
trailing: Icon(paymentIcons[index], color: Colors.black),
);
},
separatorBuilder: (context, index) {
return Divider();
},
),
),
DefaultButton(
btnText: 'PAY',
onPressed: () => Navigator.of(context).push(MaterialPageRoute(
builder: (context) => Success(),
)))
],
),
);这是单选按钮的附加代码:
final paymentLabels = [
'Credit card / Debit card',
'Go-Pay',
'OVO',
'ShopeePay',
];
final paymentIcons = [
Icons.credit_card,
Icons.money_outlined,
Icons.payment,
Icons.account_balance_wallet,
];请帮忙,谢谢
发布于 2022-06-21 12:53:28
您可以按索引号检查它。
https://stackoverflow.com/questions/72697874
复制相似问题