all_dialog.dart 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. import 'package:flutter/material.dart';
  2. import 'package:get/get.dart';
  3. import 'package:nomo/config/theme/theme_extensions/theme_extension.dart';
  4. import 'custom_dialog.dart';
  5. /// 弹窗使用示例
  6. class AllDialog {
  7. /// 显示Premium激活成功弹窗
  8. static void showPremiumActivated() {
  9. CustomDialog.showSuccess(
  10. title: 'Premium Activated Successfully !',
  11. message:
  12. 'You\'ve been upgraded to Premium. Enjoy all advanced features and an enhanced browsing experience.',
  13. buttonText: 'Got it',
  14. icon: Icons.workspace_premium,
  15. iconColor: const Color(0xFFFF9500),
  16. onPressed: () {
  17. // 处理激活成功后的逻辑
  18. print('Premium activated successfully');
  19. },
  20. );
  21. }
  22. /// 显示邮件发送成功弹窗
  23. static void showEmailSent() {
  24. CustomDialog.showInfo(
  25. title: 'Email Sent Successfully',
  26. message:
  27. 'Your Pre Code has been sent to your email.\nPlease check your inbox (and spam folder).',
  28. buttonText: 'OK',
  29. icon: Icons.mark_email_read,
  30. iconColor: const Color(0xFF00A8E8),
  31. onPressed: () {
  32. // 处理邮件发送成功后的逻辑
  33. print('Email sent successfully');
  34. },
  35. );
  36. }
  37. /// 显示网络连接错误弹窗
  38. static void showNetworkError() {
  39. CustomDialog.showError(
  40. title: 'No Internet Connection',
  41. message:
  42. 'It looks like you\'re offline. Please check your internet connection and try again.',
  43. buttonText: 'Retry',
  44. cancelText: 'Cancel',
  45. icon: Icons.wifi_off,
  46. iconColor: const Color.fromARGB(255, 231, 152, 5),
  47. confirmButtonColor: Get.reactiveTheme.primaryColor,
  48. errorCode: '',
  49. onPressed: () {
  50. // 处理重试逻辑
  51. print('Retry network connection');
  52. },
  53. onCancel: () {
  54. // 处理取消逻辑
  55. print('Cancel network retry');
  56. },
  57. );
  58. }
  59. /// 显示退出登录确认弹窗
  60. static void showLogoutConfirm() {
  61. CustomDialog.showError(
  62. title: 'Log Out?',
  63. message:
  64. 'Are you sure you want to log out? You\'ll need to sign in again to access your Premium features.',
  65. buttonText: 'Log Out',
  66. cancelText: 'Cancel',
  67. icon: Icons.info_outline,
  68. iconColor: const Color(0xFFFF3B30),
  69. confirmButtonColor: const Color(0xFFFF3B30),
  70. onPressed: () {
  71. // 处理退出登录逻辑
  72. print('User confirmed logout');
  73. // 这里可以调用退出登录的API
  74. },
  75. onCancel: () {
  76. // 处理取消退出逻辑
  77. print('User cancelled logout');
  78. },
  79. );
  80. }
  81. /// 显示自定义成功弹窗
  82. static void showCustomSuccess({
  83. required String title,
  84. required String message,
  85. String? buttonText,
  86. VoidCallback? onPressed,
  87. }) {
  88. CustomDialog.showSuccess(
  89. title: title,
  90. message: message,
  91. buttonText: buttonText ?? 'Got it',
  92. onPressed: onPressed,
  93. );
  94. }
  95. /// 显示自定义信息弹窗
  96. static void showCustomInfo({
  97. required String title,
  98. required String message,
  99. String? buttonText,
  100. VoidCallback? onPressed,
  101. }) {
  102. CustomDialog.showInfo(
  103. title: title,
  104. message: message,
  105. buttonText: buttonText ?? 'OK',
  106. onPressed: onPressed,
  107. );
  108. }
  109. /// 显示自定义错误弹窗
  110. static void showCustomError({
  111. required String title,
  112. required String message,
  113. String? buttonText,
  114. String? cancelText,
  115. VoidCallback? onPressed,
  116. VoidCallback? onCancel,
  117. String? errorCode,
  118. }) {
  119. CustomDialog.showError(
  120. title: title,
  121. message: message,
  122. buttonText: buttonText ?? 'Retry',
  123. cancelText: cancelText,
  124. onPressed: onPressed,
  125. onCancel: onCancel,
  126. errorCode: errorCode,
  127. );
  128. }
  129. /// 显示自定义确认弹窗
  130. static void showCustomConfirm({
  131. required String title,
  132. required String message,
  133. String? confirmText,
  134. String? cancelText,
  135. required VoidCallback onConfirm,
  136. VoidCallback? onCancel,
  137. Color? confirmButtonColor,
  138. }) {
  139. CustomDialog.showConfirm(
  140. title: title,
  141. message: message,
  142. confirmText: confirmText ?? 'Confirm',
  143. cancelText: cancelText ?? 'Cancel',
  144. onConfirm: onConfirm,
  145. onCancel: onCancel,
  146. confirmButtonColor: confirmButtonColor,
  147. );
  148. }
  149. }
  150. /// 在控制器中使用弹窗的示例
  151. class ExampleController extends GetxController {
  152. /// 处理Premium激活
  153. void handlePremiumActivation() {
  154. // 模拟激活过程
  155. Future.delayed(const Duration(seconds: 2), () {
  156. AllDialog.showPremiumActivated();
  157. });
  158. }
  159. /// 处理邮件发送
  160. void handleEmailSending() {
  161. // 模拟发送过程
  162. Future.delayed(const Duration(seconds: 1), () {
  163. AllDialog.showEmailSent();
  164. });
  165. }
  166. /// 处理网络错误
  167. void handleNetworkError() {
  168. AllDialog.showNetworkError();
  169. }
  170. /// 处理退出登录
  171. void handleLogout() {
  172. AllDialog.showLogoutConfirm();
  173. }
  174. /// 处理自定义操作
  175. void handleCustomAction() {
  176. AllDialog.showCustomSuccess(
  177. title: '操作成功',
  178. message: '您的操作已成功完成。',
  179. onPressed: () {
  180. print('自定义操作完成');
  181. },
  182. );
  183. }
  184. }