Browse Source

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

newdev_shunjiawei
lxm 1 year ago
parent
commit
ffc15654b8
  1. 50
      lib/modules/common/widgets/version_update_dialog.dart

50
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/services/version_update_service.dart';
/// 版本更新提示对话框
/// 版本更新提示对话框 - 禁止外部关闭
class VersionUpdateDialog extends StatelessWidget {
final VersionUpdateInfo updateInfo;
final VoidCallback? onCancel;
@ -20,8 +20,24 @@ class VersionUpdateDialog extends StatelessWidget {
@override
Widget build(BuildContext context) {
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(
// 关键修改:禁用外部点击关闭
//barrierDismissible: false,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16.r),
),
@ -49,9 +65,9 @@ class VersionUpdateDialog extends StatelessWidget {
color: Colors.blue,
),
),
SizedBox(height: 16.h),
// 标题
Text(
'发现新版本',
@ -61,9 +77,9 @@ class VersionUpdateDialog extends StatelessWidget {
color: isDarkMode ? Colors.white : Colors.black87,
),
),
SizedBox(height: 8.h),
// 版本信息
Text(
'${updateInfo.currentVersion} → ${updateInfo.latestVersion}',
@ -72,9 +88,9 @@ class VersionUpdateDialog extends StatelessWidget {
color: isDarkMode ? Colors.grey[400] : Colors.grey[600],
),
),
SizedBox(height: 16.h),
// 更新描述
if (updateInfo.appInfo?.description.isNotEmpty == true) ...[
Container(
@ -95,7 +111,7 @@ class VersionUpdateDialog extends StatelessWidget {
),
SizedBox(height: 20.h),
],
// 按钮区域
Row(
children: [
@ -112,7 +128,9 @@ class VersionUpdateDialog extends StatelessWidget {
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.r),
side: BorderSide(
color: isDarkMode ? Colors.grey[600]! : Colors.grey[300]!,
color: isDarkMode
? Colors.grey[600]!
: Colors.grey[300]!,
),
),
),
@ -120,14 +138,15 @@ class VersionUpdateDialog extends StatelessWidget {
'稍后提醒',
style: TextStyle(
fontSize: 16.sp,
color: isDarkMode ? Colors.grey[400] : Colors.grey[600],
color:
isDarkMode ? Colors.grey[400] : Colors.grey[600],
),
),
),
),
SizedBox(width: 12.w),
],
// 更新按钮
Expanded(
child: ElevatedButton(
@ -205,7 +224,7 @@ class VersionUpdateDialog extends StatelessWidget {
if (Get.isDialogOpen == true) {
Get.back();
}
Get.snackbar(
'更新失败',
'更新过程中发生错误,请稍后重试',
@ -220,7 +239,10 @@ class VersionUpdateDialog extends StatelessWidget {
static Future<void> show(VersionUpdateInfo updateInfo) async {
await Get.dialog(
VersionUpdateDialog(updateInfo: updateInfo),
barrierDismissible: updateInfo.updateType != UpdateType.force,
// 关键修改:禁用外部点击关闭
barrierDismissible: false,
// 防止返回键关闭(在强制更新模式下)
//useRootNavigator: true,
);
}
}

Loading…
Cancel
Save