You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
226 lines
7.0 KiB
226 lines
7.0 KiB
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
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;
|
|
final VoidCallback? onUpdate;
|
|
|
|
const VersionUpdateDialog({
|
|
super.key,
|
|
required this.updateInfo,
|
|
this.onCancel,
|
|
this.onUpdate,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final isDarkMode = Theme.of(context).brightness == Brightness.dark;
|
|
|
|
return Dialog(
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(16.r),
|
|
),
|
|
child: Container(
|
|
width: 320.w,
|
|
padding: EdgeInsets.all(24.w),
|
|
decoration: BoxDecoration(
|
|
color: isDarkMode ? Colors.grey[900] : Colors.white,
|
|
borderRadius: BorderRadius.circular(16.r),
|
|
),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
// 标题图标
|
|
Container(
|
|
width: 64.w,
|
|
height: 64.w,
|
|
decoration: BoxDecoration(
|
|
color: Colors.blue.withOpacity(0.1),
|
|
borderRadius: BorderRadius.circular(32.r),
|
|
),
|
|
child: Icon(
|
|
Icons.system_update,
|
|
size: 32.sp,
|
|
color: Colors.blue,
|
|
),
|
|
),
|
|
|
|
SizedBox(height: 16.h),
|
|
|
|
// 标题
|
|
Text(
|
|
'发现新版本',
|
|
style: TextStyle(
|
|
fontSize: 20.sp,
|
|
fontWeight: FontWeight.bold,
|
|
color: isDarkMode ? Colors.white : Colors.black87,
|
|
),
|
|
),
|
|
|
|
SizedBox(height: 8.h),
|
|
|
|
// 版本信息
|
|
Text(
|
|
'${updateInfo.currentVersion} → ${updateInfo.latestVersion}',
|
|
style: TextStyle(
|
|
fontSize: 14.sp,
|
|
color: isDarkMode ? Colors.grey[400] : Colors.grey[600],
|
|
),
|
|
),
|
|
|
|
SizedBox(height: 16.h),
|
|
|
|
// 更新描述
|
|
if (updateInfo.appInfo?.description.isNotEmpty == true) ...[
|
|
Container(
|
|
width: double.infinity,
|
|
padding: EdgeInsets.all(12.w),
|
|
decoration: BoxDecoration(
|
|
color: isDarkMode ? Colors.grey[800] : Colors.grey[100],
|
|
borderRadius: BorderRadius.circular(8.r),
|
|
),
|
|
child: Text(
|
|
updateInfo.appInfo!.description,
|
|
style: TextStyle(
|
|
fontSize: 14.sp,
|
|
color: isDarkMode ? Colors.grey[300] : Colors.grey[700],
|
|
height: 1.4,
|
|
),
|
|
),
|
|
),
|
|
SizedBox(height: 20.h),
|
|
],
|
|
|
|
// 按钮区域
|
|
Row(
|
|
children: [
|
|
// 取消按钮(仅在非强制更新时显示)
|
|
if (updateInfo.updateType != UpdateType.force) ...[
|
|
Expanded(
|
|
child: TextButton(
|
|
onPressed: () {
|
|
Get.back();
|
|
onCancel?.call();
|
|
},
|
|
style: TextButton.styleFrom(
|
|
padding: EdgeInsets.symmetric(vertical: 12.h),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(8.r),
|
|
side: BorderSide(
|
|
color: isDarkMode ? Colors.grey[600]! : Colors.grey[300]!,
|
|
),
|
|
),
|
|
),
|
|
child: Text(
|
|
'稍后提醒',
|
|
style: TextStyle(
|
|
fontSize: 16.sp,
|
|
color: isDarkMode ? Colors.grey[400] : Colors.grey[600],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
SizedBox(width: 12.w),
|
|
],
|
|
|
|
// 更新按钮
|
|
Expanded(
|
|
child: ElevatedButton(
|
|
onPressed: () async {
|
|
Get.back();
|
|
await _handleUpdate();
|
|
onUpdate?.call();
|
|
},
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Colors.blue,
|
|
foregroundColor: Colors.white,
|
|
padding: EdgeInsets.symmetric(vertical: 12.h),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(8.r),
|
|
),
|
|
elevation: 0,
|
|
),
|
|
child: Text(
|
|
_getUpdateButtonText(),
|
|
style: TextStyle(
|
|
fontSize: 16.sp,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
/// 获取更新按钮文本
|
|
String _getUpdateButtonText() {
|
|
switch (updateInfo.updateType) {
|
|
case UpdateType.force:
|
|
return '立即更新';
|
|
case UpdateType.optional:
|
|
return '立即更新';
|
|
default:
|
|
return '检查更新';
|
|
}
|
|
}
|
|
|
|
/// 处理更新操作
|
|
Future<void> _handleUpdate() async {
|
|
try {
|
|
// 显示加载提示
|
|
Get.dialog(
|
|
const Center(
|
|
child: CircularProgressIndicator(),
|
|
),
|
|
barrierDismissible: false,
|
|
);
|
|
|
|
final versionService = VersionUpdateService.to;
|
|
final success = await versionService.performUpdate(updateInfo);
|
|
|
|
// 关闭加载提示
|
|
Get.back();
|
|
|
|
if (!success) {
|
|
Get.snackbar(
|
|
'更新失败',
|
|
'无法打开应用商店,请手动前往应用商店更新',
|
|
snackPosition: SnackPosition.TOP,
|
|
backgroundColor: Colors.red.withOpacity(0.8),
|
|
colorText: Colors.white,
|
|
);
|
|
}
|
|
} catch (e) {
|
|
// 关闭加载提示
|
|
if (Get.isDialogOpen == true) {
|
|
Get.back();
|
|
}
|
|
|
|
Get.snackbar(
|
|
'更新失败',
|
|
'更新过程中发生错误,请稍后重试',
|
|
snackPosition: SnackPosition.TOP,
|
|
backgroundColor: Colors.red.withOpacity(0.8),
|
|
colorText: Colors.white,
|
|
);
|
|
}
|
|
}
|
|
|
|
/// 显示版本更新对话框
|
|
static Future<void> show(VersionUpdateInfo updateInfo) async {
|
|
await Get.dialog(
|
|
VersionUpdateDialog(updateInfo: updateInfo),
|
|
barrierDismissible: updateInfo.updateType != UpdateType.force,
|
|
);
|
|
}
|
|
}
|
|
|