feat: 下载队列进度条视图切换;设置新增用户须知入口;检查更新/创造者/开源许可合并至关于软件页
This commit is contained in:
1 parent
eb2f9e9ea7
commit
4277dc9f84
5 files changed
+248
-60
No files matched your search
@@ -26,6 +26,9 @@ class _DownloadPageState extends State<DownloadPage> {
|
||||
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<DownloadPage> {
|
||||
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<DownloadPage> {
|
||||
}
|
||||
}
|
||||
|
||||
/// 进度条视图:每个任务一条横向进度条 + 百分比。
|
||||
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) {
|
||||
|
||||
@@ -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<AboutPage> createState() => _AboutPageState();
|
||||
}
|
||||
|
||||
class _AboutPageState extends State<AboutPage> {
|
||||
String _currentVersion = '';
|
||||
bool _checkingUpdate = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadVersion();
|
||||
}
|
||||
|
||||
Future<void> _loadVersion() async {
|
||||
final info = await PackageInfo.fromPlatform();
|
||||
if (mounted) setState(() => _currentVersion = info.version);
|
||||
}
|
||||
|
||||
Future<void> _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,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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<SettingsPage> {
|
||||
String _currentVersion = '';
|
||||
bool _checkingUpdate = false;
|
||||
String? _currentBgType;
|
||||
String? _currentBgPath;
|
||||
bool _videoSoundEnabled = false;
|
||||
@@ -33,16 +31,10 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadVersion();
|
||||
_loadCurrentBg();
|
||||
_loadVideoSound();
|
||||
}
|
||||
|
||||
Future<void> _loadVersion() async {
|
||||
final info = await PackageInfo.fromPlatform();
|
||||
if (mounted) setState(() => _currentVersion = info.version);
|
||||
}
|
||||
|
||||
Future<void> _loadCurrentBg() async {
|
||||
final data = await BackgroundService.getBackground();
|
||||
if (mounted) {
|
||||
@@ -58,30 +50,6 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
if (mounted) setState(() => _videoSoundEnabled = enabled);
|
||||
}
|
||||
|
||||
Future<void> _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<SettingsPage> {
|
||||
),
|
||||
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()),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
Reference in new issue
Block a user