Browse Source

fix(version_update_dialog): 强制更新时禁用对话框外部关闭和返回键

weicu
lxm 1 year ago
parent
commit
d19d2216d4
  1. 30
      lib/modules/common/widgets/version_update_dialog.dart

30
lib/modules/common/widgets/version_update_dialog.dart

@ -4,7 +4,7 @@ import 'package:get/get.dart';
import '../../../data/models/channel_app_model.dart'; import '../../../data/models/channel_app_model.dart';
import '../../../data/services/version_update_service.dart'; import '../../../data/services/version_update_service.dart';
/// 版本更新提示对话框 /// 版本更新提示对话框 - 禁止外部关闭
class VersionUpdateDialog extends StatelessWidget { class VersionUpdateDialog extends StatelessWidget {
final VersionUpdateInfo updateInfo; final VersionUpdateInfo updateInfo;
final VoidCallback? onCancel; final VoidCallback? onCancel;
@ -21,7 +21,23 @@ class VersionUpdateDialog extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
final isDarkMode = Theme.of(context).brightness == Brightness.dark; final isDarkMode = Theme.of(context).brightness == Brightness.dark;
// 在强制更新时添加拦截层
Widget dialogContent = _buildDialogContent(isDarkMode);
//if (updateInfo.updateType == UpdateType.force) {
return PopScope(
canPop: false, // 完全禁用返回键关闭
child: dialogContent,
);
//}
//return dialogContent;
}
/// 构建对话框内容
Widget _buildDialogContent(bool isDarkMode) {
return Dialog( return Dialog(
// 关键修改:禁用外部点击关闭
//barrierDismissible: false,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16.r), borderRadius: BorderRadius.circular(16.r),
), ),
@ -112,7 +128,9 @@ class VersionUpdateDialog extends StatelessWidget {
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.r), borderRadius: BorderRadius.circular(8.r),
side: BorderSide( side: BorderSide(
color: isDarkMode ? Colors.grey[600]! : Colors.grey[300]!, color: isDarkMode
? Colors.grey[600]!
: Colors.grey[300]!,
), ),
), ),
), ),
@ -120,7 +138,8 @@ class VersionUpdateDialog extends StatelessWidget {
'稍后提醒', '稍后提醒',
style: TextStyle( style: TextStyle(
fontSize: 16.sp, fontSize: 16.sp,
color: isDarkMode ? Colors.grey[400] : Colors.grey[600], color:
isDarkMode ? Colors.grey[400] : Colors.grey[600],
), ),
), ),
), ),
@ -220,7 +239,10 @@ class VersionUpdateDialog extends StatelessWidget {
static Future<void> show(VersionUpdateInfo updateInfo) async { static Future<void> show(VersionUpdateInfo updateInfo) async {
await Get.dialog( await Get.dialog(
VersionUpdateDialog(updateInfo: updateInfo), VersionUpdateDialog(updateInfo: updateInfo),
barrierDismissible: updateInfo.updateType != UpdateType.force, // 关键修改:禁用外部点击关闭
barrierDismissible: false,
// 防止返回键关闭(在强制更新模式下)
//useRootNavigator: true,
); );
} }
} }

Loading…
Cancel
Save