深色模式、首页设置页面和功能优化

This commit is contained in:
Developer
2026-04-02 07:06:55 +08:00
parent f0a62ed68b
commit 954d173329
88 changed files with 12157 additions and 7578 deletions

View File

@@ -1,8 +1,10 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../../../constants/app_constants.dart';
import '../../../services/get/theme_controller.dart';
import '../../../utils/http/http_client.dart';
import 'user-plan.dart';
import '../components/server_info_dialog.dart';
@@ -25,6 +27,7 @@ enum DownloadType {
}
class _OfflineDataPageState extends State<OfflineDataPage> {
final ThemeController _themeController = Get.find<ThemeController>();
DownloadType _selectedType = DownloadType.poetry;
int _selectedCount = 30;
bool _isLoading = false;
@@ -510,262 +513,109 @@ class _OfflineDataPageState extends State<OfflineDataPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFFF5F5F5),
appBar: AppBar(
title: Text(
'离线使用',
style: TextStyle(
color: AppConstants.primaryColor,
fontWeight: FontWeight.bold,
return Obx(() {
final isDark = _themeController.isDarkMode;
return Scaffold(
backgroundColor: isDark
? const Color(0xFF1A1A1A)
: const Color(0xFFF5F5F5),
appBar: AppBar(
title: Text(
'离线使用',
style: TextStyle(
color: AppConstants.primaryColor,
fontWeight: FontWeight.bold,
),
),
backgroundColor: isDark ? const Color(0xFF2A2A2A) : Colors.white,
elevation: 0,
centerTitle: true,
leading: IconButton(
icon: Icon(Icons.arrow_back, color: AppConstants.primaryColor),
onPressed: () => Navigator.of(context).pop(),
),
actions: [
IconButton(
icon: Icon(
Icons.cloud_outlined,
color: AppConstants.primaryColor,
),
onPressed: _showServerInfo,
tooltip: '服务器信息',
),
],
),
backgroundColor: Colors.white,
elevation: 0,
centerTitle: true,
leading: IconButton(
icon: Icon(Icons.arrow_back, color: AppConstants.primaryColor),
onPressed: () => Navigator.of(context).pop(),
),
actions: [
IconButton(
icon: Icon(Icons.cloud_outlined, color: AppConstants.primaryColor),
onPressed: _showServerInfo,
tooltip: '服务器信息',
),
],
),
body: ListView(
padding: const EdgeInsets.all(16),
children: [
// 缓存状态卡片
Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: 0.05),
blurRadius: 10,
offset: const Offset(0, 2),
),
],
),
child: Column(
children: [
Row(
children: [
Icon(
Icons.download_done,
color: AppConstants.primaryColor,
size: 24,
),
const SizedBox(width: 12),
const Text(
'缓存状态',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
],
),
const SizedBox(height: 16),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'精选诗句: $_poetryCount',
style: const TextStyle(fontSize: 14, color: Colors.grey),
),
const SizedBox(height: 8),
Text(
'答题挑战: $_quizCount',
style: const TextStyle(fontSize: 14, color: Colors.grey),
),
],
),
],
),
),
const SizedBox(height: 20),
// 下载类型选择
Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: 0.05),
blurRadius: 10,
offset: const Offset(0, 2),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(
Icons.category,
color: AppConstants.primaryColor,
size: 20,
),
const SizedBox(width: 8),
const Text(
'下载类型',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
],
),
const SizedBox(height: 16),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
_buildTypeOption(DownloadType.poetry, '精选诗句'),
_buildTypeOption(DownloadType.quiz, '答题挑战'),
],
),
],
),
),
const SizedBox(height: 20),
// 下载数量选择
Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: 0.05),
blurRadius: 10,
offset: const Offset(0, 2),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(
Icons.settings,
color: AppConstants.primaryColor,
size: 20,
),
const SizedBox(width: 8),
const Text(
'下载数量',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
],
),
const SizedBox(height: 16),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: _selectedType == DownloadType.poetry
? [
_buildCountOption(20),
_buildCountOption(30),
_buildCountOption(60),
_buildCountOption(100),
]
: [
_buildCountOption(20),
_buildCountOption(50),
_buildCountOption(80),
_buildCountOption(100),
],
),
],
),
),
const SizedBox(height: 20),
// 下载/取消按钮
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: _isLoading
? (_isCancelling ? null : _cancelDownload)
: _downloadOfflineData,
style: ElevatedButton.styleFrom(
backgroundColor: _isCancelling
? Colors.red
: AppConstants.primaryColor,
padding: const EdgeInsets.symmetric(vertical: 16),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: _isCancelling
? const SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
),
)
: Text(
_isLoading ? '取消下载' : '开始下载',
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
),
),
const SizedBox(height: 16),
// 清空按钮
SizedBox(
width: double.infinity,
child: OutlinedButton(
onPressed: _clearOfflineData,
style: OutlinedButton.styleFrom(
foregroundColor: Colors.red,
side: const BorderSide(color: Colors.red),
padding: const EdgeInsets.symmetric(vertical: 16),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: const Text(
'清空缓存',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600),
),
),
),
const SizedBox(height: 20),
// 进度条
if (_isLoading) ...[
body: ListView(
padding: const EdgeInsets.all(16),
children: [
Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.white,
color: isDark ? const Color(0xFF2A2A2A) : Colors.white,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: 0.05),
color: Colors.black.withValues(alpha: isDark ? 0.3 : 0.05),
blurRadius: 10,
offset: const Offset(0, 2),
),
],
),
child: Column(
children: [
Row(
children: [
Icon(
Icons.download_done,
color: AppConstants.primaryColor,
size: 24,
),
const SizedBox(width: 12),
Text(
'缓存状态',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: isDark ? Colors.white : Colors.black,
),
),
],
),
const SizedBox(height: 16),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'精选诗句: $_poetryCount',
style: TextStyle(
fontSize: 14,
color: isDark ? Colors.grey[400] : Colors.grey,
),
),
const SizedBox(height: 8),
Text(
'答题挑战: $_quizCount',
style: TextStyle(
fontSize: 14,
color: isDark ? Colors.grey[400] : Colors.grey,
),
),
],
),
],
),
),
const SizedBox(height: 20),
Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: isDark ? const Color(0xFF2A2A2A) : Colors.white,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: isDark ? 0.3 : 0.05),
blurRadius: 10,
offset: const Offset(0, 2),
),
@@ -774,145 +624,351 @@ class _OfflineDataPageState extends State<OfflineDataPage> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
_status,
style: const TextStyle(fontSize: 14, color: Colors.grey),
Row(
children: [
Icon(
Icons.category,
color: AppConstants.primaryColor,
size: 20,
),
const SizedBox(width: 8),
Text(
'下载类型',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: isDark ? Colors.white : Colors.black,
),
),
],
),
const SizedBox(height: 16),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
_buildTypeOption(DownloadType.poetry, '精选诗句', isDark),
_buildTypeOption(DownloadType.quiz, '答题挑战', isDark),
],
),
],
),
),
const SizedBox(height: 20),
Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: isDark ? const Color(0xFF2A2A2A) : Colors.white,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: isDark ? 0.3 : 0.05),
blurRadius: 10,
offset: const Offset(0, 2),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(
Icons.settings,
color: AppConstants.primaryColor,
size: 20,
),
const SizedBox(width: 8),
Text(
'下载数量',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: isDark ? Colors.white : Colors.black,
),
),
],
),
const SizedBox(height: 16),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: _selectedType == DownloadType.poetry
? [
_buildCountOption(20, isDark),
_buildCountOption(30, isDark),
_buildCountOption(60, isDark),
_buildCountOption(100, isDark),
]
: [
_buildCountOption(20, isDark),
_buildCountOption(50, isDark),
_buildCountOption(80, isDark),
_buildCountOption(100, isDark),
],
),
],
),
),
const SizedBox(height: 20),
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: _isLoading
? (_isCancelling ? null : _cancelDownload)
: _downloadOfflineData,
style: ElevatedButton.styleFrom(
backgroundColor: _isCancelling
? Colors.red
: AppConstants.primaryColor,
padding: const EdgeInsets.symmetric(vertical: 16),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: _isCancelling
? const SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation<Color>(
Colors.white,
),
),
)
: Text(
_isLoading ? '取消下载' : '开始下载',
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
),
),
const SizedBox(height: 16),
SizedBox(
width: double.infinity,
child: OutlinedButton(
onPressed: _clearOfflineData,
style: OutlinedButton.styleFrom(
foregroundColor: Colors.red,
side: const BorderSide(color: Colors.red),
padding: const EdgeInsets.symmetric(vertical: 16),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: const Text(
'清空缓存',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600),
),
),
),
const SizedBox(height: 20),
if (_isLoading) ...[
Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: isDark ? const Color(0xFF2A2A2A) : Colors.white,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.black.withValues(
alpha: isDark ? 0.3 : 0.05,
),
blurRadius: 10,
offset: const Offset(0, 2),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
_status,
style: TextStyle(
fontSize: 14,
color: isDark ? Colors.grey[400] : Colors.grey,
),
),
const SizedBox(height: 12),
LinearProgressIndicator(
value: _progress / 100,
backgroundColor: isDark
? Colors.grey[700]
: Colors.grey[200],
valueColor: AlwaysStoppedAnimation<Color>(
AppConstants.primaryColor,
),
borderRadius: BorderRadius.circular(10),
),
const SizedBox(height: 8),
Align(
alignment: Alignment.centerRight,
child: Text(
'$_progress%',
style: TextStyle(
fontSize: 12,
color: isDark ? Colors.grey[400] : Colors.grey,
),
),
),
],
),
),
],
const SizedBox(height: 20),
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: isDark
? Colors.blue.withValues(alpha: 0.15)
: Colors.blue.withValues(alpha: 0.05),
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: isDark
? Colors.blue.withValues(alpha: 0.3)
: Colors.blue.withValues(alpha: 0.2),
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(
Icons.info_outline,
color: Colors.blue[600],
size: 20,
),
const SizedBox(width: 8),
Text(
'温馨提示',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.blue[600],
),
),
],
),
const SizedBox(height: 12),
LinearProgressIndicator(
value: _progress / 100,
backgroundColor: Colors.grey[200],
valueColor: AlwaysStoppedAnimation<Color>(
AppConstants.primaryColor,
),
borderRadius: BorderRadius.circular(10),
),
const SizedBox(height: 8),
Align(
alignment: Alignment.centerRight,
child: Text(
'$_progress%',
style: const TextStyle(fontSize: 12, color: Colors.grey),
Padding(
padding: const EdgeInsets.only(left: 4),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'• 数据下载后 需手动开启离线状态',
style: TextStyle(
fontSize: 14,
color: isDark ? Colors.grey[300] : Colors.grey[700],
fontWeight: FontWeight.w500,
),
),
const SizedBox(height: 4),
Padding(
padding: const EdgeInsets.only(left: 20),
child: Text(
'方法:个人 → 下拉 点击头像下面关闭按钮 头像显示离线',
style: TextStyle(
fontSize: 13,
color: isDark
? Colors.grey[400]
: Colors.grey[600],
),
),
),
const SizedBox(height: 8),
Text(
'• 开启离线模式后,将会循环加载本地的数据源',
style: TextStyle(
fontSize: 14,
color: isDark ? Colors.grey[300] : Colors.grey[700],
),
),
const SizedBox(height: 8),
Text(
'• 下载的数据将保存在本地,可在无网络时使用',
style: TextStyle(
fontSize: 14,
color: isDark ? Colors.grey[300] : Colors.grey[700],
),
),
const SizedBox(height: 8),
Text(
'• 下载过程中请保持网络连接',
style: TextStyle(
fontSize: 14,
color: isDark ? Colors.grey[300] : Colors.grey[700],
),
),
const SizedBox(height: 8),
Text(
'• 缓存数据不会写入历史记录',
style: TextStyle(
fontSize: 14,
color: isDark ? Colors.grey[300] : Colors.grey[700],
),
),
const SizedBox(height: 8),
Text(
'• 建议在WiFi环境下下载较多数据',
style: TextStyle(
fontSize: 14,
color: isDark ? Colors.grey[300] : Colors.grey[700],
),
),
],
),
),
],
),
),
],
const SizedBox(height: 20),
// 说明信息
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.blue.withValues(alpha: 0.05),
borderRadius: BorderRadius.circular(12),
border: Border.all(color: Colors.blue.withValues(alpha: 0.2)),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(Icons.info_outline, color: Colors.blue[600], size: 20),
const SizedBox(width: 8),
Text(
'温馨提示',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.blue[600],
),
),
],
),
const SizedBox(height: 12),
Padding(
padding: const EdgeInsets.only(left: 4),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'• 数据下载后 需手动开启离线状态',
style: TextStyle(
fontSize: 14,
color: Colors.grey[700],
fontWeight: FontWeight.w500,
),
),
const SizedBox(height: 4),
Padding(
padding: const EdgeInsets.only(left: 20),
child: Text(
'方法:个人 → 下拉 点击头像下面关闭按钮 头像显示离线',
style: TextStyle(
fontSize: 13,
color: Colors.grey[600],
),
),
),
const SizedBox(height: 8),
Text(
'• 开启离线模式后,将会循环加载本地的数据源',
style: TextStyle(fontSize: 14, color: Colors.grey[700]),
),
const SizedBox(height: 8),
Text(
'• 下载的数据将保存在本地,可在无网络时使用',
style: TextStyle(fontSize: 14, color: Colors.grey[700]),
),
const SizedBox(height: 8),
Text(
'• 下载过程中请保持网络连接',
style: TextStyle(fontSize: 14, color: Colors.grey[700]),
),
const SizedBox(height: 8),
Text(
'• 缓存数据不会写入历史记录',
style: TextStyle(fontSize: 14, color: Colors.grey[700]),
),
const SizedBox(height: 8),
Text(
'• 建议在WiFi环境下下载较多数据',
style: TextStyle(fontSize: 14, color: Colors.grey[700]),
),
],
),
),
],
),
),
],
),
);
),
);
});
}
Widget _buildTypeOption(DownloadType type, String label) {
Widget _buildTypeOption(DownloadType type, String label, bool isDark) {
final isSelected = _selectedType == type;
return GestureDetector(
onTap: () {
setState(() {
_selectedType = type;
// 重置为默认数量
_selectedCount = type == DownloadType.poetry ? 30 : 50;
});
// 重新加载缓存数量
_loadCachedCount();
},
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
decoration: BoxDecoration(
color: isSelected ? AppConstants.primaryColor : Colors.grey[100],
color: isSelected
? AppConstants.primaryColor
: (isDark ? Colors.grey[800] : Colors.grey[100]),
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: isSelected ? AppConstants.primaryColor : Colors.grey[300]!,
color: isSelected
? AppConstants.primaryColor
: (isDark ? Colors.grey[700]! : Colors.grey[300]!),
),
),
child: Text(
label,
style: TextStyle(
color: isSelected ? Colors.white : Colors.black,
color: isSelected
? Colors.white
: (isDark ? Colors.white : Colors.black),
fontSize: 14,
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
),
@@ -921,7 +977,7 @@ class _OfflineDataPageState extends State<OfflineDataPage> {
);
}
Widget _buildCountOption(int count) {
Widget _buildCountOption(int count, bool isDark) {
final isSelected = _selectedCount == count;
return Stack(
children: [
@@ -934,25 +990,28 @@ class _OfflineDataPageState extends State<OfflineDataPage> {
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
decoration: BoxDecoration(
color: isSelected ? AppConstants.primaryColor : Colors.grey[100],
color: isSelected
? AppConstants.primaryColor
: (isDark ? Colors.grey[800] : Colors.grey[100]),
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: isSelected
? AppConstants.primaryColor
: Colors.grey[300]!,
: (isDark ? Colors.grey[700]! : Colors.grey[300]!),
),
),
child: Text(
'$count条',
style: TextStyle(
color: isSelected ? Colors.white : Colors.black,
color: isSelected
? Colors.white
: (isDark ? Colors.white : Colors.black),
fontSize: 12,
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
),
),
),
),
// 为100条添加标记在卡片外面右上角
if (count == 100)
Positioned(
top: -6,