11
This commit is contained in:
1 parent
60d9380a65
commit
fe6d988fa3
46 files changed
+5738
-1013
No files matched your search
@@ -1,407 +1,538 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:background_downloader/background_downloader.dart';
|
||||
import 'package:common_utils/common_utils.dart';
|
||||
import 'package:ducafe_ui_core/ducafe_ui_core.dart';
|
||||
import 'dart:io';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:external_path/external_path.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:dio/io.dart';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:flutter_html/flutter_html.dart';
|
||||
import 'package:forui/forui.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
import 'package:pj_supermarket_cloud/common/index.dart';
|
||||
|
||||
import 'setting_components.dart';
|
||||
|
||||
/// 版本管理页面控制器,负责终端平台精确查询、当前版本识别和人工下载。
|
||||
class VersionManageController extends GetxController {
|
||||
static const String _tag = "版本管理 Controller";
|
||||
/// 版本页诊断日志使用的稳定模块标签。
|
||||
static const String _tag = '版本管理 Controller';
|
||||
|
||||
final appC = Get.find<AppControl>();
|
||||
/// 当前服务端分页页码,从 1 开始。
|
||||
final currentPage = 1.obs;
|
||||
|
||||
RxInt currentPage = RxInt(1);
|
||||
/// 服务端返回的版本总条数。
|
||||
final total = 0.obs;
|
||||
|
||||
RxInt totalPage = RxInt(0);
|
||||
/// 紧凑列表固定每页展示 8 条。
|
||||
final pageSize = 8.obs;
|
||||
|
||||
RxInt pageSize = RxInt(3);
|
||||
/// 当前页中与本机 App 编码、终端平台精确匹配的已发布版本。
|
||||
final versionList = <ServiceAppVersion>[].obs;
|
||||
|
||||
RxList<ServiceAppVersion> versionList = RxList();
|
||||
/// 当前是否正在读取版本列表。
|
||||
final isLoading = false.obs;
|
||||
|
||||
/// 列表加载失败时展示的可恢复错误摘要。
|
||||
final errorMessage = ''.obs;
|
||||
|
||||
/// 当前安装 APK 的内部版本码,用于标记“当前版本”并禁止误判升级。
|
||||
final currentVersionCode = 0.obs;
|
||||
|
||||
/// 初始化当前安装版本后加载第一页数据。
|
||||
@override
|
||||
void onInit() async {
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
unawaited(_initialize());
|
||||
}
|
||||
|
||||
/// 先读取本机 Build,再请求终端平台版本列表,避免首帧标识跳变。
|
||||
Future<void> _initialize() async {
|
||||
final package = await PackageInfo.fromPlatform();
|
||||
currentVersionCode.value = int.tryParse(package.buildNumber) ?? 0;
|
||||
await getVersionList();
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {}
|
||||
|
||||
/// 搜索
|
||||
/// 切换页码或刷新当前页。
|
||||
Future<void> doPage({int? page}) async {
|
||||
if (page != null) currentPage.value = page;
|
||||
await getVersionList(isLoading: true);
|
||||
await getVersionList(showLoading: true);
|
||||
}
|
||||
|
||||
/// 获取版本列表
|
||||
Future<void> getVersionList({bool isLoading = false}) async {
|
||||
if (isLoading) {
|
||||
EasyLoading.show(
|
||||
status: '查询中...',
|
||||
maskType: EasyLoadingMaskType.black,
|
||||
);
|
||||
/// 根据本机 SysType 传递精确平台编码,只读取服务端返回的已发布版本。
|
||||
Future<void> getVersionList({bool showLoading = false}) async {
|
||||
isLoading.value = true;
|
||||
errorMessage.value = '';
|
||||
if (showLoading) {
|
||||
EasyLoading.show(status: '查询中...', maskType: EasyLoadingMaskType.black);
|
||||
}
|
||||
try {
|
||||
final params = {
|
||||
"appUniqueCode": Constants.deviceUniqueCode,
|
||||
};
|
||||
final data = await AppApi.openCardList(params);
|
||||
logger.d("|$_tag|获取版本列表成功:${json.encode(data)}");
|
||||
if (data == null || ObjectUtil.isEmptyList(data.records)) {
|
||||
final setting = await AppSettingTool.getSysSetting();
|
||||
final data = await AppApi.openCardList({
|
||||
'appUniqueCode': Constants.deviceUniqueCode,
|
||||
'platform': AppPlatformEnum.terminalCode(setting.sysType),
|
||||
'current': currentPage.value,
|
||||
'size': pageSize.value,
|
||||
});
|
||||
versionList.assignAll(data?.records ?? const []);
|
||||
total.value = data?.total ?? 0;
|
||||
} catch (error, stack) {
|
||||
versionList.clear();
|
||||
errorMessage.value = '版本列表加载失败,请检查网络后重试';
|
||||
logger.e('|$_tag|获取版本列表失败error:|$error|stack:|$stack|');
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
if (showLoading) EasyLoading.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
/// 打开右侧版本详情抽屉,列表本身不承载更新说明和下载操作。
|
||||
Future<void> openDetails(
|
||||
BuildContext context,
|
||||
ServiceAppVersion item,
|
||||
) async {
|
||||
await _showVersionDrawer(
|
||||
context,
|
||||
item: item,
|
||||
currentVersionCode: currentVersionCode.value,
|
||||
onDownload: () => doDownload(item.downloadUrl ?? ''),
|
||||
);
|
||||
}
|
||||
|
||||
/// 人工下载继续保存到系统下载目录,不参与 Root 自动安装流程。
|
||||
Future<void> doDownload(String url) async {
|
||||
if (url.isEmpty) {
|
||||
Toast.error(msg: '当前版本没有可用下载地址');
|
||||
return;
|
||||
}
|
||||
var downUrl = url;
|
||||
if (!url.startsWith('http://') && !url.startsWith('https://')) {
|
||||
downUrl = '${Constants.ossUrl}/api/admin/sys-file/oss/file?fileName=$url';
|
||||
}
|
||||
if (!Platform.isAndroid) {
|
||||
EasyLoading.showInfo('当前平台不支持系统下载');
|
||||
return;
|
||||
}
|
||||
EasyLoading.show(status: '下载中...', maskType: EasyLoadingMaskType.black);
|
||||
try {
|
||||
var granted = await Permission.storage.request().isGranted;
|
||||
if (!granted && await Permission.manageExternalStorage.isDenied) {
|
||||
granted = await Permission.manageExternalStorage.request().isGranted;
|
||||
}
|
||||
if (!granted) {
|
||||
EasyLoading.showError('存储权限未授权,无法下载');
|
||||
return;
|
||||
}
|
||||
versionList.value = data.records!;
|
||||
totalPage.value = data.total;
|
||||
} finally {
|
||||
if (isLoading) {
|
||||
Future.delayed(const Duration(seconds: 1), () {
|
||||
EasyLoading.dismiss();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 远程下载apk
|
||||
Future<void> doDownload(String url) async {
|
||||
if (url.isEmpty) return;
|
||||
String downUrl = url;
|
||||
if (!url.startsWith("http") && !url.startsWith("https")) {
|
||||
downUrl = "${Constants.ossUrl}/api/admin/sys-file/oss/file?fileName=$url";
|
||||
}
|
||||
logger.d("|$_tag|远程下载apk,url:$downUrl");
|
||||
try {
|
||||
EasyLoading.show(
|
||||
status: '下载中...',
|
||||
maskType: EasyLoadingMaskType.black,
|
||||
final ext = AppFileTool.getFileExtension(downUrl);
|
||||
final useExt = ObjectUtil.isEmpty(ext) ? '.apk' : ext;
|
||||
final fileName = 'pj_xfj_${DateTime.now().millisecondsSinceEpoch}$useExt';
|
||||
final task = DownloadTask(
|
||||
url: downUrl,
|
||||
filename: fileName,
|
||||
updates: Updates.statusAndProgress,
|
||||
baseDirectory: BaseDirectory.applicationDocuments,
|
||||
);
|
||||
if (Platform.isAndroid) {
|
||||
var hasStorage = await Permission.storage.request().isGranted;
|
||||
if (!hasStorage) {
|
||||
EasyLoading.showError("存储权限未授权,无法下载");
|
||||
return;
|
||||
}
|
||||
if (await Permission.manageExternalStorage.isDenied) {
|
||||
final g = await Permission.manageExternalStorage.request();
|
||||
hasStorage = hasStorage || g.isGranted;
|
||||
}
|
||||
final ext = AppFileTool.getFileExtension(downUrl);
|
||||
final useExt = ObjectUtil.isEmpty(ext) ? ".apk" : ext;
|
||||
final now = DateTime.now();
|
||||
final dateStr = DateUtil.formatDate(
|
||||
now,
|
||||
format: DateFormats.full,
|
||||
);
|
||||
final fileName =
|
||||
"pj_xfj_${dateStr}_${now.millisecondsSinceEpoch}$useExt";
|
||||
final task = DownloadTask(
|
||||
url: downUrl,
|
||||
filename: fileName,
|
||||
updates: Updates.statusAndProgress,
|
||||
baseDirectory: BaseDirectory.applicationDocuments,
|
||||
);
|
||||
final result = await FileDownloader().download(
|
||||
task,
|
||||
onProgress: (progress) {
|
||||
logger.d("|$_tag|下载进度:$progress");
|
||||
EasyLoading.showProgress(
|
||||
progress,
|
||||
status: "(${(progress * 100).toStringAsFixed(2)}%)下载中...",
|
||||
);
|
||||
},
|
||||
onStatus: (status) => {logger.d("|$_tag|下载状态:$status")},
|
||||
);
|
||||
if (result.status == TaskStatus.complete) {
|
||||
final movedPath = await FileDownloader().moveToSharedStorage(
|
||||
task,
|
||||
SharedStorage.downloads,
|
||||
mimeType: useExt == ".apk"
|
||||
? "application/vnd.android.package-archive"
|
||||
: "application/octet-stream",
|
||||
);
|
||||
if (ObjectUtil.isNotEmpty(movedPath)) {
|
||||
logger.i("|$_tag|下载完成:$movedPath");
|
||||
EasyLoading.showSuccess("下载完成");
|
||||
} else {
|
||||
EasyLoading.showError("移动到下载目录失败");
|
||||
}
|
||||
} else {
|
||||
EasyLoading.showError("下载失败");
|
||||
}
|
||||
} else {
|
||||
EasyLoading.showInfo("当前平台不支持系统下载");
|
||||
final result = await FileDownloader().download(
|
||||
task,
|
||||
onProgress: (progress) => EasyLoading.showProgress(
|
||||
progress,
|
||||
status: '(${(progress * 100).toStringAsFixed(0)}%) 下载中...',
|
||||
),
|
||||
onStatus: (status) => logger.d('|$_tag|下载状态:$status'),
|
||||
);
|
||||
if (result.status != TaskStatus.complete) {
|
||||
EasyLoading.showError('下载失败');
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
logger.e("|$_tag|远程下载apk,下载失败:$e");
|
||||
EasyLoading.showError("下载失败");
|
||||
final movedPath = await FileDownloader().moveToSharedStorage(
|
||||
task,
|
||||
SharedStorage.downloads,
|
||||
mimeType: useExt == '.apk'
|
||||
? 'application/vnd.android.package-archive'
|
||||
: 'application/octet-stream',
|
||||
);
|
||||
if (ObjectUtil.isEmpty(movedPath)) {
|
||||
EasyLoading.showError('移动到下载目录失败');
|
||||
return;
|
||||
}
|
||||
logger.i('|$_tag|人工下载完成:$movedPath');
|
||||
EasyLoading.showSuccess('下载完成');
|
||||
} catch (error, stack) {
|
||||
logger.e('|$_tag|下载失败error:|$error|stack:|$stack|');
|
||||
EasyLoading.showError('下载失败');
|
||||
} finally {
|
||||
EasyLoading.dismiss();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 构建每页 8 条的紧凑版本列表,点击行后从右侧展开完整详情。
|
||||
Widget settingVersionSetting(BuildContext context) {
|
||||
final versionC = Get.put<VersionManageController>(
|
||||
VersionManageController(),
|
||||
);
|
||||
final controller = Get.isRegistered<VersionManageController>()
|
||||
? Get.find<VersionManageController>()
|
||||
: Get.put(VersionManageController());
|
||||
return <Widget>[
|
||||
buildSettingVersionSettingSearch(context),
|
||||
buildSettingVersionSettingList(context).expanded(),
|
||||
SettingActionButton(
|
||||
label: '刷新版本列表',
|
||||
icon: FAssets.icons.refreshCw,
|
||||
primary: true,
|
||||
onTap: controller.doPage,
|
||||
).alignRight(),
|
||||
Obx(() {
|
||||
if (controller.isLoading.value) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
if (controller.errorMessage.isNotEmpty) {
|
||||
return SettingEmpty(message: controller.errorMessage.value);
|
||||
}
|
||||
if (controller.versionList.isEmpty) {
|
||||
return const SettingEmpty(message: '暂无已发布版本');
|
||||
}
|
||||
return SettingGroup(
|
||||
title: '已发布版本',
|
||||
child: List.generate(
|
||||
controller.versionList.length,
|
||||
(index) {
|
||||
final item = controller.versionList[index];
|
||||
return _VersionRow(
|
||||
item: item,
|
||||
latest: controller.currentPage.value == 1 && index == 0,
|
||||
current: item.versionCode == controller.currentVersionCode.value,
|
||||
onTap: () => controller.openDetails(context, item),
|
||||
);
|
||||
},
|
||||
growable: false,
|
||||
).toColumn(
|
||||
separator: const Divider(
|
||||
height: 1,
|
||||
color: XfjDesignTokens.line,
|
||||
),
|
||||
),
|
||||
);
|
||||
}).expanded(),
|
||||
Obx(
|
||||
() => appPage(
|
||||
context,
|
||||
pageNo: versionC.currentPage.value,
|
||||
pageSize: versionC.pageSize.value,
|
||||
total: versionC.totalPage.value,
|
||||
onPageChanged: (pageNo) => versionC.doPage(page: pageNo),
|
||||
pageNo: controller.currentPage.value,
|
||||
pageSize: controller.pageSize.value,
|
||||
total: controller.total.value,
|
||||
onPageChanged: (pageNo) => controller.doPage(page: pageNo),
|
||||
),
|
||||
)
|
||||
].toColumn();
|
||||
}
|
||||
|
||||
// 版本更新搜索区域
|
||||
Widget buildSettingVersionSettingSearch(BuildContext context) {
|
||||
final versionC = Get.find<VersionManageController>();
|
||||
final theme = FTheme.of(context);
|
||||
return <Widget>[
|
||||
const Spacer(),
|
||||
FButton(
|
||||
prefix: FIcon(
|
||||
FAssets.icons.search,
|
||||
size: theme.typography.base.fontSize,
|
||||
),
|
||||
label: Text(
|
||||
'搜索',
|
||||
style: theme.typography.base.copyWith(
|
||||
color: theme.colorScheme.secondary,
|
||||
),
|
||||
),
|
||||
onPress: () => versionC.doPage(),
|
||||
),
|
||||
].toRow();
|
||||
].toColumnSpace(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
space: XfjDesignTokens.cardGap.h,
|
||||
);
|
||||
}
|
||||
|
||||
// 版本更新列表区域
|
||||
Widget buildSettingVersionSettingList(BuildContext context) {
|
||||
final versionC = Get.find<VersionManageController>();
|
||||
return Obx(() {
|
||||
if (versionC.versionList.isEmpty) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(Icons.info_outline, size: 48, color: Colors.grey),
|
||||
const SizedBox(height: 10),
|
||||
Text("暂无版本信息", style: TextStyle(color: Colors.grey[600])),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
return GridView.builder(
|
||||
padding: const EdgeInsets.all(10),
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 1,
|
||||
crossAxisSpacing: 10,
|
||||
mainAxisSpacing: 10,
|
||||
childAspectRatio: 6,
|
||||
),
|
||||
itemCount: versionC.versionList.length,
|
||||
itemBuilder: (context, index) {
|
||||
final item = versionC.versionList[index];
|
||||
return buildSettingVersionSettingCardCopy(context, item);
|
||||
},
|
||||
);
|
||||
/// 单条版本只展示版本名、Build、平台、发布状态和当前/最新标识。
|
||||
class _VersionRow extends StatelessWidget {
|
||||
/// 创建一个具有稳定高度和完整点击热区的版本行。
|
||||
const _VersionRow({
|
||||
required this.item,
|
||||
required this.latest,
|
||||
required this.current,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
/// 服务端版本记录。
|
||||
final ServiceAppVersion item;
|
||||
|
||||
/// 是否为第一页版本码最高记录。
|
||||
final bool latest;
|
||||
|
||||
/// 是否与当前安装 Build 相同。
|
||||
final bool current;
|
||||
|
||||
/// 打开右侧详情抽屉的回调。
|
||||
final VoidCallback onTap;
|
||||
|
||||
/// 构建固定列宽的紧凑扫描行。
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = FTheme.of(context);
|
||||
final platform =
|
||||
AppPlatformEnum.values.fromCode(item.platform ?? '')?.title ?? '未知平台';
|
||||
final status =
|
||||
AppVersionStatusEnum.values.fromCode(item.status ?? '')?.title ??
|
||||
'未知状态';
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
child: <Widget>[
|
||||
<Widget>[
|
||||
Text(
|
||||
item.versionName ?? '--',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: theme.typography.base.copyWith(
|
||||
color: XfjDesignTokens.ink,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'Build ${item.versionCode ?? '--'}',
|
||||
style: theme.typography.sm.copyWith(
|
||||
color: XfjDesignTokens.muted,
|
||||
fontFeatures: const [FontFeature.tabularFigures()],
|
||||
),
|
||||
),
|
||||
]
|
||||
.toColumnSpace(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
space: 4.h,
|
||||
)
|
||||
.expanded(flex: 3),
|
||||
Text(platform, style: theme.typography.sm).expanded(flex: 2),
|
||||
_versionBadge(status, XfjDesignTokens.success),
|
||||
<Widget>[
|
||||
if (current) _versionBadge('当前', XfjDesignTokens.primary),
|
||||
if (latest) _versionBadge('最新', XfjDesignTokens.warning),
|
||||
if (!current && !latest)
|
||||
Text('--',
|
||||
style:
|
||||
theme.typography.sm.copyWith(color: XfjDesignTokens.muted)),
|
||||
]
|
||||
.toRowSpace(mainAxisSize: MainAxisSize.min, space: 8.w)
|
||||
.expanded(flex: 2),
|
||||
FIcon(
|
||||
FAssets.icons.chevronRight,
|
||||
color: XfjDesignTokens.muted,
|
||||
size: 20.sp,
|
||||
),
|
||||
]
|
||||
.toRowSpace(space: 18.w)
|
||||
.padding(horizontal: 20.w, vertical: 10.h)
|
||||
.constrained(minHeight: 68.h),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Widget buildSettingVersionSettingCardCopy(
|
||||
BuildContext context,
|
||||
ServiceAppVersion item,
|
||||
) {
|
||||
final versionC = Get.find<VersionManageController>();
|
||||
/// 构建同时带文字与语义色的版本状态标签,避免只依靠颜色表达状态。
|
||||
Widget _versionBadge(String label, Color color) => Text(
|
||||
label,
|
||||
maxLines: 1,
|
||||
style: TextStyle(
|
||||
color: color,
|
||||
fontSize: 13.sp,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
).padding(horizontal: 10.w, vertical: 5.h).decorated(
|
||||
color: color.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(XfjDesignTokens.controlRadius),
|
||||
);
|
||||
|
||||
/// 从右侧展示完整版本信息与静态 HTML 更新内容,遮罩点击和关闭图标均可退出。
|
||||
Future<void> _showVersionDrawer(
|
||||
BuildContext context, {
|
||||
required ServiceAppVersion item,
|
||||
required int currentVersionCode,
|
||||
required VoidCallback onDownload,
|
||||
}) async {
|
||||
await showGeneralDialog<void>(
|
||||
context: context,
|
||||
barrierDismissible: true,
|
||||
barrierLabel: '关闭版本详情',
|
||||
barrierColor: Colors.black.withValues(alpha: 0.45),
|
||||
transitionDuration: const Duration(milliseconds: 220),
|
||||
pageBuilder: (dialogContext, _, __) {
|
||||
final width = math.min(MediaQuery.sizeOf(context).width * 0.52, 960.w);
|
||||
return Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Material(
|
||||
color: XfjDesignTokens.surface,
|
||||
child: SafeArea(
|
||||
child: _VersionDetail(
|
||||
item: item,
|
||||
currentVersionCode: currentVersionCode,
|
||||
onClose: () => Navigator.of(dialogContext).pop(),
|
||||
onDownload: onDownload,
|
||||
).width(width),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
transitionBuilder: (_, animation, __, child) => SlideTransition(
|
||||
position: Tween<Offset>(
|
||||
begin: const Offset(1, 0),
|
||||
end: Offset.zero,
|
||||
).animate(CurvedAnimation(parent: animation, curve: Curves.easeOutCubic)),
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 右侧抽屉内容,详情与 HTML 使用单一滚动区域,底部下载操作保持可见。
|
||||
class _VersionDetail extends StatelessWidget {
|
||||
/// 创建版本详情内容。
|
||||
const _VersionDetail({
|
||||
required this.item,
|
||||
required this.currentVersionCode,
|
||||
required this.onClose,
|
||||
required this.onDownload,
|
||||
});
|
||||
|
||||
/// 服务端版本记录。
|
||||
final ServiceAppVersion item;
|
||||
|
||||
/// 当前安装版本码,用于详情状态说明。
|
||||
final int currentVersionCode;
|
||||
|
||||
/// 关闭抽屉回调。
|
||||
final VoidCallback onClose;
|
||||
|
||||
/// 人工下载 APK 回调。
|
||||
final VoidCallback onDownload;
|
||||
|
||||
/// 构建标题、元数据、静态 HTML 与底部操作。
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = FTheme.of(context);
|
||||
final platform =
|
||||
AppPlatformEnum.values.fromCode(item.platform ?? '')?.title ?? '未知平台';
|
||||
final status =
|
||||
AppVersionStatusEnum.values.fromCode(item.status ?? '')?.title ??
|
||||
'未知状态';
|
||||
return <Widget>[
|
||||
<Widget>[
|
||||
<Widget>[
|
||||
Text(
|
||||
'版本 ${item.versionName ?? '--'}',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: theme.typography.xl2.copyWith(
|
||||
color: XfjDesignTokens.ink,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'Build ${item.versionCode ?? '--'}',
|
||||
style: theme.typography.sm.copyWith(color: XfjDesignTokens.muted),
|
||||
),
|
||||
]
|
||||
.toColumnSpace(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
space: 4.h,
|
||||
)
|
||||
.expanded(),
|
||||
IconButton(
|
||||
tooltip: '关闭版本详情',
|
||||
onPressed: onClose,
|
||||
icon: FIcon(FAssets.icons.x, size: 22.sp),
|
||||
),
|
||||
]
|
||||
.toRowSpace(space: 12.w)
|
||||
.padding(horizontal: 24.w, vertical: 18.h)
|
||||
.decorated(
|
||||
border:
|
||||
const Border(bottom: BorderSide(color: XfjDesignTokens.line)),
|
||||
),
|
||||
<Widget>[
|
||||
_detailLine(context, '平台', platform),
|
||||
_detailLine(context, '状态', status),
|
||||
_detailLine(context, 'App 编码', item.appUniqueCode ?? '--'),
|
||||
_detailLine(context, '强制更新', item.isForce == true ? '是' : '否'),
|
||||
_detailLine(context, '静默更新', item.isSilent == true ? '是' : '否'),
|
||||
_detailLine(
|
||||
context,
|
||||
'本机状态',
|
||||
item.versionCode == currentVersionCode ? '当前版本' : '非当前版本',
|
||||
),
|
||||
Text(
|
||||
'更新内容',
|
||||
style: theme.typography.lg.copyWith(
|
||||
color: XfjDesignTokens.ink,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
).paddingOnly(top: 16.h, bottom: 6.h),
|
||||
Html(
|
||||
data: ObjectUtil.isEmpty(item.updateContent)
|
||||
? '<p>暂无更新内容</p>'
|
||||
: item.updateContent!,
|
||||
shrinkWrap: true,
|
||||
// 只允许静态文本排版标签;a 标签保留文字但回调不执行任何外链跳转。
|
||||
onlyRenderTheseTags: const {
|
||||
'html',
|
||||
'body',
|
||||
'div',
|
||||
'span',
|
||||
'p',
|
||||
'br',
|
||||
'ul',
|
||||
'ol',
|
||||
'li',
|
||||
'strong',
|
||||
'b',
|
||||
'em',
|
||||
'i',
|
||||
'h1',
|
||||
'h2',
|
||||
'h3',
|
||||
'h4',
|
||||
'h5',
|
||||
'h6',
|
||||
'blockquote',
|
||||
'a',
|
||||
},
|
||||
doNotRenderTheseTags: const {
|
||||
'script',
|
||||
'iframe',
|
||||
'object',
|
||||
'embed',
|
||||
'form',
|
||||
'input',
|
||||
'button',
|
||||
},
|
||||
onLinkTap: (_, __, ___) {},
|
||||
style: {
|
||||
'body': Style(
|
||||
color: XfjDesignTokens.ink,
|
||||
fontSize: FontSize(15.sp),
|
||||
lineHeight: const LineHeight(1.6),
|
||||
margin: Margins.zero,
|
||||
),
|
||||
'p': Style(margin: Margins.only(bottom: 10.h)),
|
||||
'li': Style(margin: Margins.only(bottom: 6.h)),
|
||||
},
|
||||
),
|
||||
]
|
||||
.toColumn(crossAxisAlignment: CrossAxisAlignment.stretch)
|
||||
.padding(horizontal: 24.w, vertical: 18.h)
|
||||
.scrollable()
|
||||
.expanded(),
|
||||
SettingActionButton(
|
||||
label: '下载 APK',
|
||||
icon: FAssets.icons.arrowDownToLine,
|
||||
primary: true,
|
||||
enabled: ObjectUtil.isNotEmpty(item.downloadUrl),
|
||||
onTap: onDownload,
|
||||
).alignRight().padding(horizontal: 24.w, vertical: 16.h).decorated(
|
||||
border: const Border(top: BorderSide(color: XfjDesignTokens.line)),
|
||||
),
|
||||
].toColumn(crossAxisAlignment: CrossAxisAlignment.stretch);
|
||||
}
|
||||
}
|
||||
|
||||
/// 构建抽屉元数据键值行,长值允许换行且不会挤压标签。
|
||||
Widget _detailLine(BuildContext context, String label, String value) {
|
||||
final theme = FTheme.of(context);
|
||||
return <Widget>[
|
||||
<Widget>[
|
||||
Text(
|
||||
"${AppPlatformEnum.values.fromCode(item.platform ?? '')?.title ?? '未知平台'} - ${item.versionName ?? '未知版本'}",
|
||||
style: theme.typography.lg.copyWith(fontWeight: FontWeight.bold),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
SizedBox(width: 20.w),
|
||||
FBadge(
|
||||
label: Text(
|
||||
AppVersionStatusEnum.values.fromCode(item.status ?? '')?.title ??
|
||||
'未知状态',
|
||||
style: theme.typography.sm.copyWith(height: 1, color: Colors.white),
|
||||
).padding(),
|
||||
),
|
||||
].toRow(),
|
||||
SizedBox(height: 10.w),
|
||||
Text(
|
||||
"更新内容",
|
||||
style: theme.typography.base.copyWith(fontWeight: FontWeight.bold),
|
||||
),
|
||||
SizedBox(height: 10.w),
|
||||
label,
|
||||
style: theme.typography.sm.copyWith(color: XfjDesignTokens.muted),
|
||||
).width(130.w),
|
||||
Text(
|
||||
item.updateContent ?? '暂无更新内容',
|
||||
style: theme.typography.base.copyWith(color: Colors.grey),
|
||||
),
|
||||
SizedBox(height: 10.w),
|
||||
<Widget>[
|
||||
FIcon(
|
||||
FAssets.icons.sendHorizontal,
|
||||
size: theme.typography.base.fontSize,
|
||||
value,
|
||||
textAlign: TextAlign.right,
|
||||
style: theme.typography.base.copyWith(
|
||||
color: XfjDesignTokens.ink,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
SizedBox(width: 10.w),
|
||||
Text(
|
||||
item.downloadUrl ?? '未知下载地址',
|
||||
style: theme.typography.sm.copyWith(color: Colors.grey),
|
||||
),
|
||||
const Spacer(),
|
||||
FIcon(
|
||||
FAssets.icons.arrowDownToLine,
|
||||
size: theme.typography.base.fontSize,
|
||||
),
|
||||
]
|
||||
.toRow()
|
||||
.padding(horizontal: 20.w, vertical: 15.w)
|
||||
.decorated(
|
||||
color: theme.colorScheme.secondary,
|
||||
border: Border.all(
|
||||
color: theme.colorScheme.primary,
|
||||
width: 1,
|
||||
),
|
||||
borderRadius: theme.style.borderRadius,
|
||||
)
|
||||
.onTap(() => versionC.doDownload(item.downloadUrl ?? '')),
|
||||
).expanded(),
|
||||
]
|
||||
.toColumn(crossAxisAlignment: CrossAxisAlignment.start)
|
||||
.padding(horizontal: 20.w, vertical: 15.w)
|
||||
.decorated(
|
||||
color: theme.colorScheme.muted,
|
||||
border: Border.all(
|
||||
color: theme.colorScheme.primary,
|
||||
width: 1,
|
||||
),
|
||||
borderRadius: theme.style.borderRadius,
|
||||
);
|
||||
}
|
||||
|
||||
// 版本管理卡片
|
||||
Widget buildSettingVersionSettingCard(
|
||||
BuildContext context,
|
||||
ServiceAppVersion item,
|
||||
) {
|
||||
final theme = FTheme.of(context);
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(15),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: Colors.grey.shade300),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.05),
|
||||
blurRadius: 4,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
"${item.platform ?? '未知平台'} - ${item.versionName ?? '未知版本'}",
|
||||
style:
|
||||
theme.typography.lg.copyWith(fontWeight: FontWeight.bold),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: item.status == '已发布'
|
||||
? Colors.green.withOpacity(0.1)
|
||||
: Colors.grey.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Text(
|
||||
item.status ?? '未知状态',
|
||||
style: theme.typography.sm.copyWith(
|
||||
color: item.status == '已发布' ? Colors.green : Colors.grey,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
Text("Build: ${item.versionCode ?? '-'}",
|
||||
style: theme.typography.base.copyWith(color: Colors.grey)),
|
||||
const SizedBox(width: 10),
|
||||
if (item.isForce == true) _buildTag(context, "强制更新", Colors.red),
|
||||
if (item.isSilent == true)
|
||||
_buildTag(context, "静默更新", Colors.orange),
|
||||
],
|
||||
),
|
||||
const Divider(height: 20),
|
||||
Text("更新内容:",
|
||||
style: theme.typography.base.copyWith(fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
item.updateContent ?? '暂无更新内容',
|
||||
style: theme.typography.base.copyWith(color: Colors.grey[800]),
|
||||
),
|
||||
if (item.downloadUrl != null && item.downloadUrl!.isNotEmpty) ...[
|
||||
const SizedBox(height: 10),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[100],
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.link, size: 16, color: Colors.blue),
|
||||
const SizedBox(width: 5),
|
||||
Expanded(
|
||||
child: Text(
|
||||
item.downloadUrl!,
|
||||
style: theme.typography.sm.copyWith(color: Colors.blue),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTag(BuildContext context, String text, Color color) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(left: 8),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: color),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Text(text, style: TextStyle(color: color, fontSize: 10)),
|
||||
);
|
||||
.toRowSpace(crossAxisAlignment: CrossAxisAlignment.start, space: 16.w)
|
||||
.padding(vertical: 8.h);
|
||||
}
|
||||
Reference in new issue
Block a user