From 4277dc9f84353533cec3b91ada2535377e1e08b2 Mon Sep 17 00:00:00 2001 From: ZV Team Date: Sat, 24 Oct 2026 10:56:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=8B=E8=BD=BD=E9=98=9F=E5=88=97?= =?UTF-8?q?=E8=BF=9B=E5=BA=A6=E6=9D=A1=E8=A7=86=E5=9B=BE=E5=88=87=E6=8D=A2?= =?UTF-8?q?=EF=BC=9B=E8=AE=BE=E7=BD=AE=E6=96=B0=E5=A2=9E=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E9=A1=BB=E7=9F=A5=E5=85=A5=E5=8F=A3=EF=BC=9B=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E6=9B=B4=E6=96=B0/=E5=88=9B=E9=80=A0=E8=80=85/=E5=BC=80?= =?UTF-8?q?=E6=BA=90=E8=AE=B8=E5=8F=AF=E5=90=88=E5=B9=B6=E8=87=B3=E5=85=B3?= =?UTF-8?q?=E4=BA=8E=E8=BD=AF=E4=BB=B6=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/core/l10n/strings.dart | 9 ++ lib/core/widgets/user_agreement_dialog.dart | 31 ++++-- lib/features/download/download_page.dart | 85 +++++++++++++++ lib/features/settings/about_page.dart | 108 ++++++++++++++++++++ lib/features/settings/settings_page.dart | 75 ++++---------- 5 files changed, 248 insertions(+), 60 deletions(-) create mode 100644 lib/features/settings/about_page.dart diff --git a/lib/core/l10n/strings.dart b/lib/core/l10n/strings.dart index b069288..082a5c2 100644 --- a/lib/core/l10n/strings.dart +++ b/lib/core/l10n/strings.dart @@ -405,6 +405,15 @@ class S { '目录下没有日志文件': 'No log files in this directory', '读取失败:{0}': 'Failed to read: {0}', '自动刷新并跟随底部(每 5 秒)': 'Auto refresh & follow bottom (every 5s)', + '卡片视图': 'Card view', + '进度条视图': 'Progress bar view', + '用户须知': 'User Notice', + '查看用户守则全部条款': 'View all terms of the user agreement', + '关于软件': 'About', + '版本、检查更新、创造者与开源许可': 'Version, updates, creators and licenses', + '我知道了': 'Got it', + '创造者': 'Creators', + 'ZV Manager 是一款 Minecraft 服务器远程管理工具,本软件与 Mojang、微软无任何隶属关系。': 'ZV Manager is a remote management tool for Minecraft servers. Not affiliated with Mojang or Microsoft.', }; static String t(String zh) => en ? (_en[zh] ?? zh) : zh; diff --git a/lib/core/widgets/user_agreement_dialog.dart b/lib/core/widgets/user_agreement_dialog.dart index 7a1f5dc..398ab07 100644 --- a/lib/core/widgets/user_agreement_dialog.dart +++ b/lib/core/widgets/user_agreement_dialog.dart @@ -5,7 +5,14 @@ import '../l10n/strings.dart'; class UserAgreementDialog extends StatefulWidget { final VoidCallback onAgree; - const UserAgreementDialog({super.key, required this.onAgree}); + /// 只读模式:设置「用户须知」入口使用,无需倒计时/勾选,按钮直接关闭。 + final bool readOnly; + + const UserAgreementDialog({super.key, required this.onAgree, this.readOnly = false}); + + /// 只读查看入口。 + static Widget readView() => + UserAgreementDialog(onAgree: () {}, readOnly: true); @override State createState() => _UserAgreementDialogState(); @@ -13,6 +20,7 @@ class UserAgreementDialog extends StatefulWidget { class _UserAgreementDialogState extends State { bool _isChecked = false; + bool get _readOnly => widget.readOnly; /// 强制阅读:倒计时 10 秒 + 滚动到底,两者都满足才能勾选同意。 static const int _readSeconds = 10; @@ -24,6 +32,11 @@ class _UserAgreementDialogState extends State { @override void initState() { super.initState(); + if (widget.readOnly) { + _countdown = 0; + _readToEnd = true; + return; + } _timer = Timer.periodic(const Duration(seconds: 1), (t) { if (!mounted) return t.cancel(); setState(() => _countdown--); @@ -48,9 +61,11 @@ class _UserAgreementDialogState extends State { } } - bool get _canAgree => _isChecked && _countdown <= 0 && _readToEnd; + bool get _canAgree => + _readOnly || (_isChecked && _countdown <= 0 && _readToEnd); String get _buttonLabel { + if (_readOnly) return S.t('我知道了'); if (_countdown > 0) return S.f('请仔细阅读守则({0}s)', [_countdown]); if (!_readToEnd) return S.t('请阅读至守则底部'); return S.t('同意并进入'); @@ -59,7 +74,7 @@ class _UserAgreementDialogState extends State { @override Widget build(BuildContext context) { return PopScope( - canPop: false, + canPop: _readOnly, child: Dialog( shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)), insetPadding: const EdgeInsets.symmetric(horizontal: 20), @@ -152,8 +167,8 @@ class _UserAgreementDialogState extends State { ), const SizedBox(height: 16), - // 同意勾选(倒计时结束且阅读到底后才可勾选) - GestureDetector( + // 同意勾选(倒计时结束且阅读到底后才可勾选);只读模式不显示 + if (!_readOnly) GestureDetector( onTap: _countdown <= 0 && _readToEnd ? () { setState(() { @@ -197,7 +212,11 @@ class _UserAgreementDialogState extends State { SizedBox( width: double.infinity, child: FilledButton( - onPressed: _canAgree ? widget.onAgree : null, + onPressed: !_canAgree + ? null + : (_readOnly + ? () => Navigator.of(context).pop() + : widget.onAgree), style: FilledButton.styleFrom( backgroundColor: const Color(0xFF28A745), disabledBackgroundColor: const Color(0xFFCCCCCC), diff --git a/lib/features/download/download_page.dart b/lib/features/download/download_page.dart index 57c9a3b..15fb537 100644 --- a/lib/features/download/download_page.dart +++ b/lib/features/download/download_page.dart @@ -26,6 +26,9 @@ class _DownloadPageState extends State { static const _mcVersions = ['1.21.4', '1.21.1', '1.20.6', '1.20.4', '1.20.1', '1.19.4', '1.18.2', '1.16.5']; static const _loaders = ['fabric', 'forge', 'quilt', 'neoforge', 'paper', 'bukkit', 'spigot']; + /// 任务队列视图:false=卡片列表,true=进度条视图。 + bool _barView = false; + @override void initState() { super.initState(); @@ -78,6 +81,11 @@ class _DownloadPageState extends State { MaterialPageRoute(builder: (_) => const DownloadSettingsPage()), ), ), + IconButton( + icon: Icon(_barView ? Icons.view_list_outlined : Icons.equalizer), + tooltip: _barView ? S.t('卡片视图') : S.t('进度条视图'), + onPressed: () => setState(() => _barView = !_barView), + ), ], bottom: const TabBar(tabs: [Tab(text: '搜索下载'), Tab(text: '任务队列')]), ), @@ -235,12 +243,89 @@ class _DownloadPageState extends State { } } + /// 进度条视图:每个任务一条横向进度条 + 百分比。 + Widget _buildBarList(DownloadProvider dp, List tasks) { + return ListView.builder( + padding: const EdgeInsets.symmetric(vertical: 8), + itemCount: tasks.length, + itemBuilder: (context, i) { + final t = tasks[i]; + return Padding( + padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + children: [ + Expanded( + child: Text('${i + 1}. ${t.fileName}', + overflow: TextOverflow.ellipsis, + style: Theme.of(context).textTheme.bodyMedium), + ), + Text('${(t.progress * 100).toStringAsFixed(0)}%', + style: Theme.of(context).textTheme.bodySmall), + const SizedBox(width: 4), + _statusChip(t.status), + ], + ), + const SizedBox(height: 6), + LinearProgressIndicator( + value: t.status == DownloadStatus.completed ? 1 : t.progress, + minHeight: 8, + borderRadius: BorderRadius.circular(4), + ), + const SizedBox(height: 4), + Row( + children: [ + Text( + '${_fmt(t.receivedBytes)} / ${_fmt(t.totalBytes)}' + '${t.status == DownloadStatus.running ? " · ${_fmt(t.speed)}/s" : ""}', + style: Theme.of(context).textTheme.bodySmall, + ), + const Spacer(), + if (t.status == DownloadStatus.running) + IconButton( + icon: const Icon(Icons.pause, size: 20), + tooltip: S.t('暂停'), + onPressed: () => dp.manager.pause(t.id), + ), + if (t.status == DownloadStatus.paused) + IconButton( + icon: const Icon(Icons.play_arrow, size: 20), + tooltip: S.t('继续'), + onPressed: () => dp.manager.resume(t.id), + ), + if (t.status == DownloadStatus.failed) + IconButton( + icon: const Icon(Icons.replay, size: 20), + tooltip: S.t('重试'), + onPressed: () => dp.manager.retry(t.id), + ), + IconButton( + icon: const Icon(Icons.close, size: 20), + tooltip: S.t('取消'), + onPressed: () => dp.manager.cancel(t.id), + ), + ], + ), + if (t.error != null) + Text(t.error!, + style: TextStyle( + color: Theme.of(context).colorScheme.error, fontSize: 12)), + ], + ), + ); + }, + ); + } + Widget _buildQueueTab(DownloadProvider dp) { return AnimatedBuilder( animation: dp.manager, builder: (context, _) { final tasks = dp.manager.tasks; if (tasks.isEmpty) return const Center(child: T('暂无下载任务')); + if (_barView) return _buildBarList(dp, tasks); return ListView.builder( itemCount: tasks.length, itemBuilder: (context, i) { diff --git a/lib/features/settings/about_page.dart b/lib/features/settings/about_page.dart new file mode 100644 index 0000000..09f5eb4 --- /dev/null +++ b/lib/features/settings/about_page.dart @@ -0,0 +1,108 @@ +import 'package:flutter/material.dart'; +import 'package:package_info_plus/package_info_plus.dart'; +import '../../core/l10n/strings.dart'; +import '../../core/utils/update_service.dart'; + +/// 关于软件页:版本与检查更新 + 开发者信息 + 开源许可。 +class AboutPage extends StatefulWidget { + const AboutPage({super.key}); + + @override + State createState() => _AboutPageState(); +} + +class _AboutPageState extends State { + String _currentVersion = ''; + bool _checkingUpdate = false; + + @override + void initState() { + super.initState(); + _loadVersion(); + } + + Future _loadVersion() async { + final info = await PackageInfo.fromPlatform(); + if (mounted) setState(() => _currentVersion = info.version); + } + + Future _checkUpdate() async { + setState(() => _checkingUpdate = true); + try { + final updateInfo = await UpdateService.fetchInfo(userAgent: _currentVersion); + if (!mounted) return; + setState(() => _checkingUpdate = false); + + if (updateInfo == null) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: T('获取更新信息失败')), + ); + return; + } + + UpdateService.showUpdateDialog(context, updateInfo, _currentVersion); + } catch (e) { + if (!mounted) return; + setState(() => _checkingUpdate = false); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text(S.f('检查更新失败:{0}', [e]))), + ); + } + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar(title: T('关于软件')), + body: ListView( + children: [ + const SizedBox(height: 24), + Column( + children: [ + const Icon(Icons.extension, size: 64), + const SizedBox(height: 8), + T('ZV Manager', style: Theme.of(context).textTheme.titleLarge), + Text(S.f('版本 {0}', [_currentVersion]), + style: Theme.of(context).textTheme.bodySmall), + ], + ), + const SizedBox(height: 16), + const Divider(), + ListTile( + leading: const Icon(Icons.system_update_outlined), + title: T('检查更新'), + trailing: _checkingUpdate + ? const SizedBox( + width: 20, + height: 20, + child: CircularProgressIndicator(strokeWidth: 2)) + : const Icon(Icons.chevron_right), + onTap: _checkingUpdate ? null : _checkUpdate, + ), + const Divider(), + const ListTile( + leading: Icon(Icons.person_outline), + title: T('创造者'), + subtitle: T('开发者:Z有3笔,协作者:venti1112'), + ), + const Divider(), + ListTile( + leading: const Icon(Icons.fact_check_outlined), + title: T('开源许可'), + trailing: const Icon(Icons.chevron_right), + onTap: () => showLicensePage(context: context), + ), + const Divider(), + Padding( + padding: const EdgeInsets.all(16), + child: Text( + S.t('ZV Manager 是一款 Minecraft 服务器远程管理工具,本软件与 Mojang、微软无任何隶属关系。'), + style: Theme.of(context).textTheme.bodySmall, + textAlign: TextAlign.center, + ), + ), + ], + ), + ); + } +} diff --git a/lib/features/settings/settings_page.dart b/lib/features/settings/settings_page.dart index cbe3aed..f1b6189 100644 --- a/lib/features/settings/settings_page.dart +++ b/lib/features/settings/settings_page.dart @@ -1,18 +1,18 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; -import 'package:package_info_plus/package_info_plus.dart'; import 'package:image_picker/image_picker.dart'; import 'package:file_picker/file_picker.dart'; import 'dart:io'; import 'package:path_provider/path_provider.dart'; import '../../core/theme/app_theme.dart'; -import '../../core/utils/update_service.dart'; import '../../core/utils/background_service.dart'; import '../../core/widgets/background_widget.dart'; import '../../providers/theme_provider.dart'; import '../../providers/wallpaper_provider.dart'; import 'help_page.dart'; import 'server_log_page.dart'; +import 'about_page.dart'; +import '../../core/widgets/user_agreement_dialog.dart'; import 'download_settings_page.dart'; import '../../providers/language_provider.dart'; import '../../core/l10n/strings.dart'; @@ -24,8 +24,6 @@ class SettingsPage extends StatefulWidget { } class _SettingsPageState extends State { - String _currentVersion = ''; - bool _checkingUpdate = false; String? _currentBgType; String? _currentBgPath; bool _videoSoundEnabled = false; @@ -33,16 +31,10 @@ class _SettingsPageState extends State { @override void initState() { super.initState(); - _loadVersion(); _loadCurrentBg(); _loadVideoSound(); } - Future _loadVersion() async { - final info = await PackageInfo.fromPlatform(); - if (mounted) setState(() => _currentVersion = info.version); - } - Future _loadCurrentBg() async { final data = await BackgroundService.getBackground(); if (mounted) { @@ -58,30 +50,6 @@ class _SettingsPageState extends State { if (mounted) setState(() => _videoSoundEnabled = enabled); } - Future _checkUpdate() async { - setState(() => _checkingUpdate = true); - try { - final updateInfo = await UpdateService.fetchInfo(userAgent: _currentVersion); - if (!mounted) return; - setState(() => _checkingUpdate = false); - - if (updateInfo == null) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: T('获取更新信息失败')), - ); - return; - } - - UpdateService.showUpdateDialog(context, updateInfo, _currentVersion); - } catch (e) { - if (!mounted) return; - setState(() => _checkingUpdate = false); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text(S.f('检查更新失败:{0}', [e]))), - ); - } - } - // ==================== 背景相关方法 ==================== void _showBackgroundPicker() { @@ -358,31 +326,30 @@ class _SettingsPageState extends State { ), const Divider(), - // ---------- 检查更新 ---------- + // ---------- 用户须知 ---------- ListTile( - leading: const Icon(Icons.system_update_outlined), - title: T('检查更新'), - subtitle: Text(S.f('当前版本: {0}', [_currentVersion])), - trailing: _checkingUpdate - ? const SizedBox(width: 20, height: 20, child: CircularProgressIndicator(strokeWidth: 2)) - : const Icon(Icons.chevron_right), - onTap: _checkingUpdate ? null : _checkUpdate, + leading: const Icon(Icons.gavel_outlined), + title: T('用户须知'), + subtitle: T('查看用户守则全部条款'), + trailing: const Icon(Icons.chevron_right), + onTap: () => showDialog( + context: context, + barrierDismissible: true, + builder: (_) => UserAgreementDialog.readView(), + ), ), const Divider(), - // ---------- 关于 ---------- - const ListTile( - leading: Icon(Icons.info_outline), - title: T('关于'), - subtitle: T('开发者:Z有3笔,协作者:venti1112'), - ), - const Divider(), - - // ---------- 开源许可 ---------- + // ---------- 关于软件(检查更新 + 创造者 + 开源许可) ---------- ListTile( - leading: const Icon(Icons.fact_check_outlined), - title: T('开源许可'), - onTap: () => showLicensePage(context: context), + leading: const Icon(Icons.info_outline), + title: T('关于软件'), + subtitle: T('版本、检查更新、创造者与开源许可'), + trailing: const Icon(Icons.chevron_right), + onTap: () => Navigator.push( + context, + MaterialPageRoute(builder: (_) => const AboutPage()), + ), ), ], ),