/// 支付结果对话框:支付流程结束后统一展示结果,点「完成」回到商品页 /// /// 展示内容:结果图标 + 标题(成功/失败/取消)、支付渠道、订单号、后端状态说明。 /// App 拉起支付(微信/支付宝/云闪付等)返回本 App 后,由 pay_service 调用, /// 替代仅 toast 的弱反馈。 library; import 'package:flutter/material.dart'; /// 弹出支付结果对话框 /// - [success] 是否支付成功 /// - [cancelled] 用户主动取消(优先级低于 success) /// - [paymentId] 订单号(payment_id) /// - [channelName] 支付渠道展示名,如「微信支付」 /// - [note] 后端状态说明(可选) Future showPayResultDialog( BuildContext context, { required bool success, required String paymentId, String? channelName, String? note, bool cancelled = false, }) { final title = success ? '支付成功' : cancelled ? '已取消支付' : '支付失败'; final icon = success ? const Icon(Icons.check_circle, color: Colors.green, size: 64) : cancelled ? const Icon(Icons.cancel, color: Colors.grey, size: 64) : const Icon(Icons.error, color: Colors.red, size: 64); return showDialog( context: context, barrierDismissible: false, builder: (dialogContext) => AlertDialog( title: Center(child: Text(title, style: const TextStyle(fontSize: 18))), content: Column( mainAxisSize: MainAxisSize.min, children: [ const SizedBox(height: 8), icon, const SizedBox(height: 16), if (channelName != null) ...[ Text('渠道:$channelName', style: const TextStyle(color: Colors.grey, fontSize: 14)), const SizedBox(height: 4), ], Text('订单号:$paymentId', style: const TextStyle(color: Colors.grey, fontSize: 14)), if (note != null && note.isNotEmpty) ...[ const SizedBox(height: 4), Text(note, textAlign: TextAlign.center, style: const TextStyle(color: Colors.grey, fontSize: 13)), ], ], ), actions: [ TextButton( onPressed: () => Navigator.of(dialogContext).pop(), child: const Text('完成'), ), ], ), ); }