import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:nomo/config/theme/theme_extensions/theme_extension.dart'; import 'custom_dialog.dart'; /// 弹窗使用示例 class AllDialog { /// 显示Premium激活成功弹窗 static void showPremiumActivated() { CustomDialog.showSuccess( title: 'Premium Activated Successfully !', message: 'You\'ve been upgraded to Premium. Enjoy all advanced features and an enhanced browsing experience.', buttonText: 'Got it', icon: Icons.workspace_premium, iconColor: const Color(0xFFFF9500), onPressed: () { // 处理激活成功后的逻辑 print('Premium activated successfully'); }, ); } /// 显示邮件发送成功弹窗 static void showEmailSent() { CustomDialog.showInfo( title: 'Email Sent Successfully', message: 'Your Pre Code has been sent to your email.\nPlease check your inbox (and spam folder).', buttonText: 'OK', icon: Icons.mark_email_read, iconColor: const Color(0xFF00A8E8), onPressed: () { // 处理邮件发送成功后的逻辑 print('Email sent successfully'); }, ); } /// 显示网络连接错误弹窗 static void showNetworkError() { CustomDialog.showError( title: 'No Internet Connection', message: 'It looks like you\'re offline. Please check your internet connection and try again.', buttonText: 'Retry', cancelText: 'Cancel', icon: Icons.wifi_off, iconColor: const Color.fromARGB(255, 231, 152, 5), confirmButtonColor: Get.reactiveTheme.primaryColor, errorCode: '', onPressed: () { // 处理重试逻辑 print('Retry network connection'); }, onCancel: () { // 处理取消逻辑 print('Cancel network retry'); }, ); } /// 显示退出登录确认弹窗 static void showLogoutConfirm() { CustomDialog.showError( title: 'Log Out?', message: 'Are you sure you want to log out? You\'ll need to sign in again to access your Premium features.', buttonText: 'Log Out', cancelText: 'Cancel', icon: Icons.info_outline, iconColor: const Color(0xFFFF3B30), confirmButtonColor: const Color(0xFFFF3B30), onPressed: () { // 处理退出登录逻辑 print('User confirmed logout'); // 这里可以调用退出登录的API }, onCancel: () { // 处理取消退出逻辑 print('User cancelled logout'); }, ); } /// 显示自定义成功弹窗 static void showCustomSuccess({ required String title, required String message, String? buttonText, VoidCallback? onPressed, }) { CustomDialog.showSuccess( title: title, message: message, buttonText: buttonText ?? 'Got it', onPressed: onPressed, ); } /// 显示自定义信息弹窗 static void showCustomInfo({ required String title, required String message, String? buttonText, VoidCallback? onPressed, }) { CustomDialog.showInfo( title: title, message: message, buttonText: buttonText ?? 'OK', onPressed: onPressed, ); } /// 显示自定义错误弹窗 static void showCustomError({ required String title, required String message, String? buttonText, String? cancelText, VoidCallback? onPressed, VoidCallback? onCancel, String? errorCode, }) { CustomDialog.showError( title: title, message: message, buttonText: buttonText ?? 'Retry', cancelText: cancelText, onPressed: onPressed, onCancel: onCancel, errorCode: errorCode, ); } /// 显示自定义确认弹窗 static void showCustomConfirm({ required String title, required String message, String? confirmText, String? cancelText, required VoidCallback onConfirm, VoidCallback? onCancel, Color? confirmButtonColor, }) { CustomDialog.showConfirm( title: title, message: message, confirmText: confirmText ?? 'Confirm', cancelText: cancelText ?? 'Cancel', onConfirm: onConfirm, onCancel: onCancel, confirmButtonColor: confirmButtonColor, ); } } /// 在控制器中使用弹窗的示例 class ExampleController extends GetxController { /// 处理Premium激活 void handlePremiumActivation() { // 模拟激活过程 Future.delayed(const Duration(seconds: 2), () { AllDialog.showPremiumActivated(); }); } /// 处理邮件发送 void handleEmailSending() { // 模拟发送过程 Future.delayed(const Duration(seconds: 1), () { AllDialog.showEmailSent(); }); } /// 处理网络错误 void handleNetworkError() { AllDialog.showNetworkError(); } /// 处理退出登录 void handleLogout() { AllDialog.showLogoutConfirm(); } /// 处理自定义操作 void handleCustomAction() { AllDialog.showCustomSuccess( title: '操作成功', message: '您的操作已成功完成。', onPressed: () { print('自定义操作完成'); }, ); } }