pay_result.dart 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /// 支付结果对话框:支付流程结束后统一展示结果,点「完成」回到商品页
  2. ///
  3. /// 展示内容:结果图标 + 标题(成功/失败/取消)、支付渠道、订单号、后端状态说明。
  4. /// App 拉起支付(微信/支付宝/云闪付等)返回本 App 后,由 pay_service 调用,
  5. /// 替代仅 toast 的弱反馈。
  6. library;
  7. import 'package:flutter/material.dart';
  8. /// 弹出支付结果对话框
  9. /// - [success] 是否支付成功
  10. /// - [cancelled] 用户主动取消(优先级低于 success)
  11. /// - [paymentId] 订单号(payment_id)
  12. /// - [channelName] 支付渠道展示名,如「微信支付」
  13. /// - [note] 后端状态说明(可选)
  14. Future<void> showPayResultDialog(
  15. BuildContext context, {
  16. required bool success,
  17. required String paymentId,
  18. String? channelName,
  19. String? note,
  20. bool cancelled = false,
  21. }) {
  22. final title = success
  23. ? '支付成功'
  24. : cancelled
  25. ? '已取消支付'
  26. : '支付失败';
  27. final icon = success
  28. ? const Icon(Icons.check_circle, color: Colors.green, size: 64)
  29. : cancelled
  30. ? const Icon(Icons.cancel, color: Colors.grey, size: 64)
  31. : const Icon(Icons.error, color: Colors.red, size: 64);
  32. return showDialog<void>(
  33. context: context,
  34. barrierDismissible: false,
  35. builder: (dialogContext) => AlertDialog(
  36. title: Center(child: Text(title, style: const TextStyle(fontSize: 18))),
  37. content: Column(
  38. mainAxisSize: MainAxisSize.min,
  39. children: [
  40. const SizedBox(height: 8),
  41. icon,
  42. const SizedBox(height: 16),
  43. if (channelName != null) ...[
  44. Text('渠道:$channelName',
  45. style: const TextStyle(color: Colors.grey, fontSize: 14)),
  46. const SizedBox(height: 4),
  47. ],
  48. Text('订单号:$paymentId',
  49. style: const TextStyle(color: Colors.grey, fontSize: 14)),
  50. if (note != null && note.isNotEmpty) ...[
  51. const SizedBox(height: 4),
  52. Text(note,
  53. textAlign: TextAlign.center,
  54. style: const TextStyle(color: Colors.grey, fontSize: 13)),
  55. ],
  56. ],
  57. ),
  58. actions: [
  59. TextButton(
  60. onPressed: () => Navigator.of(dialogContext).pop(),
  61. child: const Text('完成'),
  62. ),
  63. ],
  64. ),
  65. );
  66. }