优化界面2

This commit is contained in:
DelLevin-Home
2026-05-22 18:23:40 +08:00
parent 79f813c463
commit 6c3e55fead
18 changed files with 2004 additions and 2695 deletions

View File

@@ -322,22 +322,22 @@ class _MdReaderTabPageState extends State<MdReaderTabPage> {
onPressed: () => Navigator.pop(context),
),
actions: [
if (_canGoBack)
Padding(
padding: const EdgeInsets.only(right: 8),
child: GestureDetector(
onTap: _goBack,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 5),
decoration: BoxDecoration(
color: const Color(0xFFF5F5F5),
borderRadius: BorderRadius.circular(14),
border: Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
),
child: const Text('返回上级', style: TextStyle(fontSize: 12, color: Color(0xFF666666))),
),
),
),
// if (_canGoBack)
// Padding(
// padding: const EdgeInsets.only(right: 8),
// child: GestureDetector(
// onTap: _goBack,
// child: Container(
// padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 5),
// decoration: BoxDecoration(
// color: const Color(0xFFF5F5F5),
// borderRadius: BorderRadius.circular(14),
// border: Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
// ),
// child: const Text('返回上级', style: TextStyle(fontSize: 12, color: Color(0xFF666666))),
// ),
// ),
// ),
if (_currentPath != null)
Padding(
padding: const EdgeInsets.only(right: 4),

View File

@@ -1,554 +0,0 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:path_provider/path_provider.dart';
import 'package:provider/provider.dart';
import 'package:uuid/uuid.dart';
import '../../providers/app_provider.dart';
import '../../models/data_models.dart';
import '../../utils/toast_util.dart';
/// 添加/编辑影视记录页面Typecho 风格)
class MovieFormPage extends StatefulWidget {
final Movie? movie;
const MovieFormPage({super.key, this.movie});
@override
State<MovieFormPage> createState() => _MovieFormPageState();
}
class _MovieFormPageState extends State<MovieFormPage> {
final _formKey = GlobalKey<FormState>();
late TextEditingController _titleController;
late TextEditingController _releaseDateController;
late TextEditingController _directorsController;
late TextEditingController _writersController;
late TextEditingController _actorsController;
late TextEditingController _genresController;
late TextEditingController _alternateTitlesController;
late TextEditingController _summaryController;
late TextEditingController _ratingController;
String _status = 'want_to_watch';
File? _posterImage;
bool _isLoading = false;
final ImagePicker _picker = ImagePicker();
@override
void initState() {
super.initState();
_titleController = TextEditingController(text: widget.movie?.title ?? '');
_releaseDateController = TextEditingController(
text: widget.movie?.releaseDate != null
? _formatDate(widget.movie!.releaseDate!)
: '',
);
_directorsController = TextEditingController(
text: (widget.movie?.directors ?? []).join(', '),
);
_writersController = TextEditingController(
text: (widget.movie?.writers ?? []).join(', '),
);
_actorsController = TextEditingController(
text: (widget.movie?.actors ?? []).join(', '),
);
_genresController = TextEditingController(
text: (widget.movie?.genres ?? []).join(', '),
);
_alternateTitlesController = TextEditingController(
text: (widget.movie?.alternateTitles ?? []).join(', '),
);
_summaryController = TextEditingController(text: widget.movie?.summary ?? '');
_ratingController = TextEditingController(
text: widget.movie?.rating?.toString() ?? '',
);
_status = widget.movie?.status ?? 'want_to_watch';
if (widget.movie?.posterPath != null) {
_posterImage = File(widget.movie!.posterPath!);
}
}
@override
void dispose() {
_titleController.dispose();
_releaseDateController.dispose();
_directorsController.dispose();
_writersController.dispose();
_actorsController.dispose();
_genresController.dispose();
_alternateTitlesController.dispose();
_summaryController.dispose();
_ratingController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final isEdit = widget.movie != null;
return Scaffold(
appBar: AppBar(
title: Text(isEdit ? '编辑影视' : '添加影视'),
actions: [
IconButton(
icon: const Icon(Icons.save),
onPressed: _isLoading ? null : _saveMovie,
),
],
),
body: SingleChildScrollView(
child: Column(
children: [
// 封面上传区域
_buildCoverSection(),
const SizedBox(height: 24),
// 表单区域
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildBasicInfoSection(),
const SizedBox(height: 32),
_buildCastSection(),
const SizedBox(height: 32),
_buildDetailSection(),
const SizedBox(height: 48),
_buildSaveButton(isEdit),
const SizedBox(height: 32),
],
),
),
),
],
),
),
);
}
/// 构建封面上传区域
Widget _buildCoverSection() {
return GestureDetector(
onTap: _pickImage,
child: Container(
width: double.infinity,
height: 300,
color: Theme.of(context).colorScheme.surfaceContainerHighest,
child: _posterImage != null
? Stack(
fit: StackFit.expand,
children: [
Image.file(
_posterImage!,
fit: BoxFit.cover,
),
Positioned(
top: 16,
right: 16,
child: Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.black54,
borderRadius: BorderRadius.circular(20),
),
child: const Icon(
Icons.camera_alt,
color: Colors.white,
),
),
),
],
)
: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.add_photo_alternate_outlined,
size: 64,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
const SizedBox(height: 16),
Text(
'点击上传海报',
style: TextStyle(
fontSize: 16,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
const SizedBox(height: 8),
Text(
'建议尺寸2:3 比例',
style: TextStyle(
fontSize: 14,
color: Theme.of(context).colorScheme.onSurfaceVariant.withOpacity(0.6),
),
),
],
),
),
);
}
/// 构建基本信息区域
Widget _buildBasicInfoSection() {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildSectionTitle('基本信息'),
const SizedBox(height: 16),
TextFormField(
controller: _titleController,
decoration: const InputDecoration(
labelText: '影视名称 *',
hintText: '请输入影视名称',
border: OutlineInputBorder(),
prefixIcon: Icon(Icons.title),
),
validator: (value) {
if (value == null || value.trim().isEmpty) {
return '请输入影视名称';
}
return null;
},
),
const SizedBox(height: 16),
Row(
children: [
Expanded(
child: TextFormField(
controller: _releaseDateController,
decoration: const InputDecoration(
labelText: '上映时间',
hintText: 'YYYY-MM-DD',
border: OutlineInputBorder(),
prefixIcon: Icon(Icons.calendar_today),
),
readOnly: true,
onTap: _selectReleaseDate,
),
),
const SizedBox(width: 16),
Expanded(
child: TextFormField(
controller: _ratingController,
decoration: const InputDecoration(
labelText: '评分',
hintText: '1-10',
border: OutlineInputBorder(),
prefixIcon: Icon(Icons.star),
),
keyboardType: const TextInputType.numberWithOptions(decimal: true),
validator: (value) {
if (value != null && value.isNotEmpty) {
final rating = double.tryParse(value);
if (rating == null || rating < 1 || rating > 10) {
return '1-10';
}
}
return null;
},
),
),
],
),
const SizedBox(height: 16),
DropdownButtonFormField<String>(
value: _status,
decoration: const InputDecoration(
labelText: '状态',
border: OutlineInputBorder(),
prefixIcon: Icon(Icons.check_circle_outline),
),
items: const [
DropdownMenuItem(value: 'watched', child: Text('已看')),
DropdownMenuItem(value: 'want_to_watch', child: Text('想看')),
DropdownMenuItem(value: 'watching', child: Text('在看')),
],
onChanged: (value) {
setState(() {
_status = value!;
});
},
),
],
);
}
/// 构建演职人员区域
Widget _buildCastSection() {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildSectionTitle('演职人员'),
const SizedBox(height: 16),
TextFormField(
controller: _directorsController,
decoration: const InputDecoration(
labelText: '导演',
hintText: '多个用逗号分隔',
border: OutlineInputBorder(),
prefixIcon: Icon(Icons.person),
),
),
const SizedBox(height: 16),
TextFormField(
controller: _writersController,
decoration: const InputDecoration(
labelText: '编剧',
hintText: '多个用逗号分隔',
border: OutlineInputBorder(),
prefixIcon: Icon(Icons.edit_note),
),
),
const SizedBox(height: 16),
TextFormField(
controller: _actorsController,
decoration: const InputDecoration(
labelText: '主演',
hintText: '多个用逗号分隔',
border: OutlineInputBorder(),
prefixIcon: Icon(Icons.people),
),
),
],
);
}
/// 构建详细信息区域
Widget _buildDetailSection() {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildSectionTitle('详细信息'),
const SizedBox(height: 16),
TextFormField(
controller: _genresController,
decoration: const InputDecoration(
labelText: '类型',
hintText: '多个用逗号分隔',
border: OutlineInputBorder(),
prefixIcon: Icon(Icons.category),
),
),
const SizedBox(height: 16),
TextFormField(
controller: _alternateTitlesController,
decoration: const InputDecoration(
labelText: '别名',
hintText: '多个用逗号分隔',
border: OutlineInputBorder(),
prefixIcon: Icon(Icons.alt_route),
),
),
const SizedBox(height: 16),
TextFormField(
controller: _summaryController,
decoration: const InputDecoration(
labelText: '剧情简介',
hintText: '请输入剧情简介...',
border: OutlineInputBorder(),
alignLabelWithHint: true,
prefixIcon: Icon(Icons.description),
),
maxLines: 6,
),
],
);
}
/// 构建保存按钮
Widget _buildSaveButton(bool isEdit) {
return SizedBox(
width: double.infinity,
height: 48,
child: ElevatedButton.icon(
onPressed: _isLoading ? null : _saveMovie,
icon: _isLoading
? const SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(strokeWidth: 2),
)
: const Icon(Icons.save),
label: Text(isEdit ? '保存修改' : '添加记录'),
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
),
);
}
/// 构建区块标题
Widget _buildSectionTitle(String title) {
return Text(
title,
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
);
}
/// 选择图片
Future<void> _pickImage() async {
final XFile? image = await _picker.pickImage(source: ImageSource.gallery);
if (image != null) {
setState(() {
_posterImage = File(image.path);
});
}
}
/// 选择日期
Future<void> _selectReleaseDate() async {
final picked = await showDatePicker(
context: context,
initialDate: DateTime.now(),
firstDate: DateTime(1900),
lastDate: DateTime.now(),
);
if (picked != null) {
setState(() {
_releaseDateController.text = _formatDate(picked);
});
}
}
/// 格式化日期
String _formatDate(DateTime date) {
return '${date.year}-${date.month.toString().padLeft(2, '0')}-${date.day.toString().padLeft(2, '0')}';
}
/// 保存影视记录
Future<void> _saveMovie() async {
if (!_formKey.currentState!.validate()) {
return;
}
setState(() {
_isLoading = true;
});
try {
// 处理列表字段
final directors = _parseList(_directorsController.text);
final writers = _parseList(_writersController.text);
final actors = _parseList(_actorsController.text);
final genres = _parseList(_genresController.text);
final alternateTitles = _parseList(_alternateTitlesController.text);
// 处理评分
final rating = _ratingController.text.isNotEmpty
? double.parse(_ratingController.text)
: null;
// 处理日期
final releaseDate = _releaseDateController.text.isNotEmpty
? DateTime.tryParse(_releaseDateController.text)
: null;
// 处理图片
String? posterPath;
if (_posterImage != null) {
final dir = await getApplicationDocumentsDirectory();
final fileName = '${const Uuid().v4()}.jpg';
final savedImage = await _posterImage!.copy('${dir.path}/posters/$fileName');
posterPath = savedImage.path;
}
if (widget.movie == null) {
// 添加新模式
final now = DateTime.now();
final newMovie = Movie(
id: const Uuid().v4(),
title: _titleController.text.trim(),
posterPath: posterPath,
releaseDate: releaseDate,
directors: directors,
writers: writers,
actors: actors,
genres: genres,
alternateTitles: alternateTitles,
summary: _summaryController.text.trim(),
rating: rating,
status: _status,
createdAt: now,
updatedAt: now,
);
await context.read<AppProvider>().addMovie(newMovie);
} else {
// 编辑现有模式
final updatedMovie = Movie(
id: widget.movie!.id,
title: _titleController.text.trim(),
posterPath: posterPath ?? widget.movie!.posterPath,
releaseDate: releaseDate,
directors: directors,
writers: writers,
actors: actors,
genres: genres,
alternateTitles: alternateTitles,
summary: _summaryController.text.trim(),
rating: rating,
status: _status,
createdAt: widget.movie!.createdAt,
updatedAt: DateTime.now(),
);
await context.read<AppProvider>().updateMovie(updatedMovie);
}
if (!mounted) return;
ToastUtil.show(context, widget.movie == null ? '添加成功' : '更新成功');
Navigator.pop(context);
} catch (e) {
if (!mounted) return;
ToastUtil.show(context, '保存失败:$e');
} finally {
if (mounted) {
setState(() {
_isLoading = false;
});
}
}
}
/// 解析列表
List<String> _parseList(String text) {
return text
.split(',')
.map((item) => item.trim())
.where((item) => item.isNotEmpty)
.toList();
}
}

View File

@@ -59,11 +59,9 @@ class _NoteFormPageState extends State<NoteFormPage> {
@override
Widget build(BuildContext context) {
final bottomInset = MediaQuery.of(context).viewInsets.bottom;
return Scaffold(
backgroundColor: Colors.white,
resizeToAvoidBottomInset: false,
resizeToAvoidBottomInset: true,
appBar: AppBar(
title: GestureDetector(
onLongPress: _showTitleDialog,
@@ -92,7 +90,7 @@ class _NoteFormPageState extends State<NoteFormPage> {
children: [
// 主内容区域 — 图片网格固定在内容下方
Padding(
padding: EdgeInsets.only(bottom: 56 + bottomInset),
padding: const EdgeInsets.only(bottom: 56),
child: Column(
children: [
// 顶部信息栏
@@ -176,7 +174,7 @@ class _NoteFormPageState extends State<NoteFormPage> {
Positioned(
left: 0,
right: 0,
bottom: bottomInset,
bottom: 0,
child: _buildFloatingToolbar(),
),
],
@@ -391,15 +389,16 @@ class _NoteFormPageState extends State<NoteFormPage> {
color: Color(0xFF1A1A1A),
height: 1.6,
),
decoration: InputDecoration(
decoration: const InputDecoration(
hintText: '使用 Markdown 格式书写...',
hintStyle: const TextStyle(
hintStyle: TextStyle(
fontSize: 16,
color: Color(0xFFCCCCCC),
height: 1.6,
),
border: InputBorder.none,
contentPadding: const EdgeInsets.all(16),
focusedBorder: InputBorder.none,
contentPadding: EdgeInsets.all(16),
),
);
}

View File

@@ -435,31 +435,11 @@ class _ProfilePageState extends State<ProfilePage> {
_buildMenuItem(
icon: Icons.backup_outlined,
title: '本地备份',
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const BackupPage()),
).then((_) {
// 返回时刷新用户数据
_loadUserData();
});
},
title: '备份',
onTap: () => _showBackupOptions(context),
),
const Divider(height: 1, indent: 72, endIndent: 16, color: Color(0xFFE8E8E8)),
_buildMenuItem(
icon: Icons.cloud_sync_outlined,
title: '云备份',
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const CloudSyncPage()),
);
},
),
const Divider(height: 1, indent: 72, endIndent: 16, color: Color(0xFFE8E8E8)),
_buildMenuItem(
icon: Icons.delete_outline,
title: '回收站',
@@ -527,6 +507,82 @@ class _ProfilePageState extends State<ProfilePage> {
);
}
/// 显示备份选项
void _showBackupOptions(BuildContext context) {
showModalBottomSheet(
context: context,
backgroundColor: Colors.white,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
),
builder: (ctx) => Padding(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 36, height: 4,
decoration: BoxDecoration(
color: const Color(0xFFDDDDDD),
borderRadius: BorderRadius.circular(2),
),
),
const SizedBox(height: 20),
const Align(
alignment: Alignment.centerLeft,
child: Text('选择备份方式', style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A))),
),
const SizedBox(height: 16),
ListTile(
contentPadding: EdgeInsets.zero,
leading: Container(
width: 44, height: 44,
decoration: BoxDecoration(
color: const Color(0xFFF5F5F5),
borderRadius: BorderRadius.circular(10),
),
child: const Icon(Icons.folder_outlined, color: Color(0xFF666666)),
),
title: const Text('本地备份', style: TextStyle(fontSize: 15, fontWeight: FontWeight.w500, color: Color(0xFF1A1A1A))),
subtitle: const Text('备份到本地文件夹,支持恢复', style: TextStyle(fontSize: 12, color: Color(0xFF999999))),
trailing: const Icon(Icons.chevron_right, color: Color(0xFFCCCCCC)),
onTap: () {
Navigator.pop(ctx);
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const BackupPage()),
).then((_) => _loadUserData());
},
),
const Divider(height: 0.5, color: Color(0xFFF0F0F0)),
ListTile(
contentPadding: EdgeInsets.zero,
leading: Container(
width: 44, height: 44,
decoration: BoxDecoration(
color: const Color(0xFFF5F5F5),
borderRadius: BorderRadius.circular(10),
),
child: const Icon(Icons.cloud_outlined, color: Color(0xFF666666)),
),
title: const Text('云备份', style: TextStyle(fontSize: 15, fontWeight: FontWeight.w500, color: Color(0xFF1A1A1A))),
subtitle: const Text('通过 WebDAV 同步到云端', style: TextStyle(fontSize: 12, color: Color(0xFF999999))),
trailing: const Icon(Icons.chevron_right, color: Color(0xFFCCCCCC)),
onTap: () {
Navigator.pop(ctx);
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const CloudSyncPage()),
);
},
),
const SizedBox(height: 20),
],
),
),
);
}
/// 显示提示
void _showToast(String message) {
ToastUtil.show(context, message);
@@ -541,22 +597,22 @@ class _ProfilePageState extends State<ProfilePage> {
maxHeight: 400,
imageQuality: 85,
);
if (pickedFile != null) {
final appDir = await getApplicationDocumentsDirectory();
final fileName = 'avatar_${DateTime.now().millisecondsSinceEpoch}.jpg';
final savedPath = path.join(appDir.path, 'avatars', fileName);
final avatarDir = Directory(path.join(appDir.path, 'avatars'));
if (!await avatarDir.exists()) {
await avatarDir.create(recursive: true);
}
await File(pickedFile.path).copy(savedPath);
// 保存到本地存储
await _userPrefs.setAvatarPath(savedPath);
setState(() => _avatarPath = savedPath);
}
} catch (e) {
@@ -565,8 +621,6 @@ class _ProfilePageState extends State<ProfilePage> {
}
}
}
/// 编辑昵称
void _editNickname(BuildContext context) {
final controller = TextEditingController(text: _nickname);

View File

@@ -58,6 +58,7 @@ class _StrollPageState extends State<StrollPage> {
imagePath: m.posterPath,
icon: Icons.movie_outlined,
label: '影视',
createdAt: m.createdAt,
);
break;
case 'book':
@@ -70,6 +71,7 @@ class _StrollPageState extends State<StrollPage> {
imagePath: b.coverPath,
icon: Icons.menu_book_outlined,
label: '书籍',
createdAt: b.createdAt,
);
break;
case 'note':
@@ -82,6 +84,7 @@ class _StrollPageState extends State<StrollPage> {
imagePath: n.images.isNotEmpty ? n.images.first : null,
icon: Icons.note_outlined,
label: '笔记',
createdAt: n.createdAt,
);
break;
default:
@@ -110,6 +113,29 @@ class _StrollPageState extends State<StrollPage> {
return parts.join(' · ');
}
String _getTimeAgoText(DateTime date) {
final diff = DateTime.now().difference(date);
if (diff.inDays >= 365) return '1年前';
if (diff.inDays >= 180) return '6个月前';
if (diff.inDays >= 90) return '3个月前';
if (diff.inDays >= 30) return '1个月前';
return '${diff.inDays}天前';
}
String _getActionTimeAgo(_StrollItem item) {
final timeAgo = _getTimeAgoText(item.createdAt);
switch (item.type) {
case 'movie':
return '${timeAgo}看过';
case 'book':
return '${timeAgo}读过';
case 'note':
return '${timeAgo}写下';
default:
return timeAgo;
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
@@ -226,6 +252,13 @@ class _StrollPageState extends State<StrollPage> {
),
],
// 时间
const SizedBox(height: 10),
Text(
_getActionTimeAgo(item),
style: const TextStyle(fontSize: 12, color: Color(0xFFCCCCCC)),
),
const SizedBox(height: 40),
],
),
@@ -309,6 +342,11 @@ class _StrollPageState extends State<StrollPage> {
'${item.detail.length}',
style: const TextStyle(fontSize: 11, color: Color(0xFFBBBBBB)),
),
const SizedBox(width: 10),
Text(
_getActionTimeAgo(item),
style: const TextStyle(fontSize: 11, color: Color(0xFFBBBBBB)),
),
const Spacer(),
const Text(
'Mooknote',
@@ -350,6 +388,7 @@ class _StrollItem {
final String? imagePath;
final IconData icon;
final String label;
final DateTime createdAt;
_StrollItem({
required this.type,
@@ -359,5 +398,6 @@ class _StrollItem {
this.imagePath,
required this.icon,
required this.label,
required this.createdAt,
});
}

View File

@@ -50,11 +50,14 @@ class _BackupPageState extends State<BackupPage> {
: ListView(
padding: const EdgeInsets.all(24),
children: [
// 数据操作区域
// 自动备份开关 - 紧凑一行
_buildAutoBackupSection(),
const SizedBox(height: 24),
// 手动备份
_buildSectionTitle('手动备份'),
const SizedBox(height: 16),
// 导出数据
const SizedBox(height: 12),
_buildActionCard(
title: '导出数据',
description: '将所有数据导出为 zip 文件,可用于备份或迁移到其他设备',
@@ -63,10 +66,7 @@ class _BackupPageState extends State<BackupPage> {
isLoading: _isExporting,
onTap: _exportData,
),
const SizedBox(height: 16),
// 导入数据
const SizedBox(height: 12),
_buildActionCard(
title: '导入数据',
description: '从备份文件导入数据,将覆盖当前所有数据',
@@ -76,14 +76,9 @@ class _BackupPageState extends State<BackupPage> {
onTap: _importData,
isDestructive: true,
),
const SizedBox(height: 32),
// 自动备份开关
_buildAutoBackupSection(),
const SizedBox(height: 32),
// 使用说明
_buildInfoSection(),
],
@@ -144,8 +139,8 @@ class _BackupPageState extends State<BackupPage> {
color: Colors.white,
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: isDestructive
? Colors.red.withOpacity(0.3)
color: isDestructive
? Colors.red.withOpacity(0.3)
: const Color(0xFFE8E8E8),
width: 0.5,
),
@@ -184,37 +179,34 @@ class _BackupPageState extends State<BackupPage> {
],
),
const SizedBox(height: 20),
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: isLoading ? null : onTap,
style: ElevatedButton.styleFrom(
backgroundColor: isDestructive
? Colors.red
: const Color(0xFF1A1A1A),
foregroundColor: Colors.white,
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
padding: const EdgeInsets.symmetric(vertical: 14),
GestureDetector(
onTap: isLoading ? null : onTap,
child: Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(vertical: 14),
decoration: BoxDecoration(
color: isLoading ? const Color(0xFFCCCCCC) : const Color(0xFF1A1A1A),
borderRadius: BorderRadius.circular(8),
),
child: isLoading
? const SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation(Colors.white),
child: Center(
child: isLoading
? const SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation(Colors.white),
),
)
: Text(
buttonText,
style: const TextStyle(
fontSize: 15,
fontWeight: FontWeight.w500,
color: Colors.white,
),
),
)
: Text(
buttonText,
style: const TextStyle(
fontSize: 15,
fontWeight: FontWeight.w500,
),
),
),
),
),
],
@@ -311,6 +303,78 @@ class _BackupPageState extends State<BackupPage> {
);
}
/// 显示成功弹窗
void _showSuccessDialog({
required String title,
required String content,
String? detail,
}) {
showDialog(
context: context,
builder: (ctx) => AlertDialog(
backgroundColor: Colors.white,
elevation: 0,
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.zero),
title: Column(
children: [
Container(
width: 48,
height: 48,
decoration: BoxDecoration(
color: const Color(0xFFF5F5F5),
borderRadius: BorderRadius.circular(12),
),
child: const Icon(Icons.check, color: Color(0xFF1A1A1A), size: 24),
),
const SizedBox(height: 16),
Text(title, style: const TextStyle(fontSize: 17, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A))),
],
),
titlePadding: const EdgeInsets.fromLTRB(24, 24, 24, 0),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
const SizedBox(height: 12),
Text(
content,
style: const TextStyle(fontSize: 14, color: Color(0xFF666666), height: 1.6),
textAlign: TextAlign.center,
),
if (detail != null && detail.isNotEmpty) ...[
const SizedBox(height: 12),
Container(
width: double.infinity,
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: const Color(0xFFF8F8F8),
borderRadius: BorderRadius.circular(8),
),
child: Text(
detail,
style: const TextStyle(fontSize: 11, color: Color(0xFF999999)),
maxLines: 3,
overflow: TextOverflow.ellipsis,
),
),
],
],
),
contentPadding: const EdgeInsets.fromLTRB(24, 0, 24, 0),
actionsPadding: const EdgeInsets.fromLTRB(16, 20, 16, 16),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx),
style: TextButton.styleFrom(
minimumSize: const Size(120, 40),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
),
child: const Text('确定', style: TextStyle(fontSize: 14, color: Color(0xFF1A1A1A))),
),
],
),
);
}
/// 导出数据
Future<void> _exportData() async {
setState(() => _isExporting = true);
@@ -323,29 +387,10 @@ class _BackupPageState extends State<BackupPage> {
if (result.cancelled) {
ToastUtil.show(context, '已取消导出');
} else if (result.success) {
// 显示导出成功信息
showDialog(
context: context,
builder: (context) => AlertDialog(
backgroundColor: Colors.white,
elevation: 0,
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.zero),
title: const Text('导出成功'),
content: Text(
'备份文件已保存到:\n${result.filePath}\n\n'
'包含数据:\n'
'• 影视: ${result.movieCount}\n'
'• 书籍: ${result.bookCount}\n'
'• 笔记: ${result.noteCount}\n'
'• 图片: ${result.imageCount}',
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('确定'),
),
],
),
_showSuccessDialog(
title: '导出成功',
content: '备份文件已保存,包含:\n影视 ${result.movieCount} · 书籍 ${result.bookCount} · 笔记 ${result.noteCount} · 图片 ${result.imageCount}',
detail: result.filePath ?? '',
);
} else {
ToastUtil.show(context, result.errorMessage ?? '导出失败');
@@ -370,18 +415,47 @@ class _BackupPageState extends State<BackupPage> {
backgroundColor: Colors.white,
elevation: 0,
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.zero),
title: const Text('确认导入'),
content: const Text(
'导入数据将覆盖当前所有数据,此操作不可恢复。\n\n是否继续?',
title: Row(
children: [
Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: Colors.red.withOpacity(0.08),
borderRadius: BorderRadius.circular(10),
),
child: const Icon(Icons.warning_amber_rounded, color: Colors.red, size: 22),
),
const SizedBox(width: 12),
const Text('确认导入', style: TextStyle(fontSize: 17, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A))),
],
),
titlePadding: const EdgeInsets.fromLTRB(24, 24, 24, 0),
content: const Padding(
padding: EdgeInsets.only(top: 16),
child: Text(
'导入数据将覆盖当前所有数据,此操作不可恢复。',
style: TextStyle(fontSize: 14, color: Color(0xFF666666), height: 1.6),
),
),
contentPadding: const EdgeInsets.fromLTRB(24, 0, 24, 0),
actionsPadding: const EdgeInsets.fromLTRB(16, 20, 16, 16),
actions: [
TextButton(
onPressed: () => Navigator.pop(context, false),
child: const Text('取消', style: TextStyle(color: Color(0xFF666666))),
style: TextButton.styleFrom(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
),
child: const Text('取消', style: TextStyle(color: Color(0xFF666666), fontSize: 14)),
),
TextButton(
onPressed: () => Navigator.pop(context, true),
child: const Text('确认导入', style: TextStyle(color: Colors.red)),
style: TextButton.styleFrom(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
),
child: const Text('确认导入', style: TextStyle(color: Colors.red, fontSize: 14, fontWeight: FontWeight.w600)),
),
],
),
@@ -403,22 +477,12 @@ class _BackupPageState extends State<BackupPage> {
await context.read<AppProvider>().loadMovies();
await context.read<AppProvider>().loadBooks();
await context.read<AppProvider>().loadNotes();
showDialog(
context: context,
builder: (context) => AlertDialog(
backgroundColor: Colors.white,
elevation: 0,
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.zero),
title: const Text('导入成功'),
content: Text('成功导入数据:\n${result.statsText}'),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('确定'),
),
],
),
if (!mounted) return;
_showSuccessDialog(
title: '导入成功',
content: result.statsText,
);
} else {
ToastUtil.show(context, result.errorMessage ?? '导入失败');
@@ -434,109 +498,68 @@ class _BackupPageState extends State<BackupPage> {
}
}
/// 构建自动备份区域
/// 构建自动备份区域 - 紧凑一行
Widget _buildAutoBackupSection() {
return Container(
padding: const EdgeInsets.all(20),
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
decoration: BoxDecoration(
color: const Color(0xFFFAFAFA),
borderRadius: BorderRadius.circular(12),
border: Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
child: Row(
children: [
Row(
children: [
Container(
width: 44,
height: 44,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
border: Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
),
child: const Icon(
Icons.schedule,
size: 22,
color: Color(0xFF666666),
),
),
const SizedBox(width: 16),
const Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'自动本地备份',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: Color(0xFF1A1A1A),
),
),
SizedBox(height: 4),
Text(
'每2分钟自动备份保留最近5个备份',
style: TextStyle(
fontSize: 13,
color: Color(0xFF666666),
),
),
],
),
),
Switch(
value: _autoBackupEnabled,
onChanged: (value) async {
setState(() => _autoBackupEnabled = value);
await AutoBackupService.instance.setEnabled(value);
if (value) {
ToastUtil.show(context, '自动备份已开启');
} else {
ToastUtil.show(context, '自动备份已关闭');
}
await _loadAutoBackupStatus();
},
activeColor: const Color(0xFF1A1A1A),
activeTrackColor: const Color(0xFF1A1A1A).withOpacity(0.3),
inactiveThumbColor: Colors.white,
inactiveTrackColor: const Color(0xFFE5E5E5),
),
],
),
if (_backupDirPath != null && _autoBackupEnabled) ...[
const SizedBox(height: 16),
Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8),
border: Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
),
child: Row(
children: [
const Icon(
Icons.folder_outlined,
size: 16,
color: Color(0xFF999999),
),
const SizedBox(width: 8),
Expanded(
child: Text(
_backupDirPath!,
style: const TextStyle(
fontSize: 12,
color: Color(0xFF666666),
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
],
),
Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
border: Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
),
],
child: const Icon(Icons.schedule, size: 20, color: Color(0xFF666666)),
),
const SizedBox(width: 12),
Expanded(
child: _backupDirPath != null && _autoBackupEnabled
? Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'自动本地备份',
style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A)),
),
const SizedBox(height: 2),
Text(
_backupDirPath!,
style: const TextStyle(fontSize: 11, color: Color(0xFF999999)),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
)
: const Text(
'自动本地备份',
style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A)),
),
),
Switch(
value: _autoBackupEnabled,
onChanged: (value) async {
setState(() => _autoBackupEnabled = value);
await AutoBackupService.instance.setEnabled(value);
if (value) {
ToastUtil.show(context, '自动备份已开启');
} else {
ToastUtil.show(context, '自动备份已关闭');
}
await _loadAutoBackupStatus();
},
activeColor: const Color(0xFF1A1A1A),
activeTrackColor: const Color(0xFF1A1A1A).withOpacity(0.3),
inactiveThumbColor: Colors.white,
inactiveTrackColor: const Color(0xFFE5E5E5),
),
],
),
);

View File

@@ -18,13 +18,13 @@ class CloudSyncPage extends StatelessWidget {
// 备份方式标题
_buildSectionTitle('选择备份方式'),
const SizedBox(height: 16),
// WebDAV 备份选项
_buildSyncOption(
context,
icon: Icons.storage_outlined,
title: 'WebDAV 备份',
subtitle: '通过 WebDAV 协议备份到个人云盘如坚果云、Nextcloud 等)',
subtitle: '通过 WebDAV 协议备份到个人云盘',
onTap: () {
Navigator.push(
context,
@@ -32,9 +32,9 @@ class CloudSyncPage extends StatelessWidget {
);
},
),
const SizedBox(height: 32),
// 说明文字
_buildInfoSection(),
],
@@ -86,7 +86,8 @@ class CloudSyncPage extends StatelessWidget {
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8),
border: Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
border:
Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
),
child: const Icon(
Icons.info_outline,
@@ -176,15 +177,16 @@ class CloudSyncPage extends StatelessWidget {
color: enabled ? Colors.white : const Color(0xFFEEEEEE),
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: enabled ? const Color(0xFFE8E8E8) : const Color(0xFFEEEEEE),
color: enabled
? const Color(0xFFE8E8E8)
: const Color(0xFFEEEEEE),
width: 0.5,
),
),
child: Icon(
icon,
color: enabled
? const Color(0xFF666666)
: const Color(0xFF999999),
color:
enabled ? const Color(0xFF666666) : const Color(0xFF999999),
size: 22,
),
),
@@ -198,8 +200,8 @@ class CloudSyncPage extends StatelessWidget {
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: enabled
? const Color(0xFF1A1A1A)
color: enabled
? const Color(0xFF1A1A1A)
: const Color(0xFF999999),
),
),
@@ -208,8 +210,8 @@ class CloudSyncPage extends StatelessWidget {
subtitle,
style: TextStyle(
fontSize: 13,
color: enabled
? const Color(0xFF666666)
color: enabled
? const Color(0xFF666666)
: const Color(0xFF999999),
height: 1.4,
),
@@ -219,9 +221,8 @@ class CloudSyncPage extends StatelessWidget {
),
Icon(
Icons.chevron_right,
color: enabled
? const Color(0xFFCCCCCC)
: const Color(0xFFE5E5E5),
color:
enabled ? const Color(0xFFCCCCCC) : const Color(0xFFE5E5E5),
),
],
),

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,659 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../providers/app_provider.dart';
import '../utils/toast_util.dart';
class TagManagementPage extends StatefulWidget {
const TagManagementPage({super.key});
@override
State<TagManagementPage> createState() => _TagManagementPageState();
}
class _TagManagementPageState extends State<TagManagementPage> {
int _currentIndex = 0;
static const _tabTypes = ['movie_genre', 'book_genre', 'note_tag'];
static const _typeLabels = ['影视类型', '书籍类型', '笔记标签'];
final Map<String, List<Map<String, dynamic>>> _tagCache = {};
@override
void initState() {
super.initState();
_loadTags(_tabTypes[0]);
}
Future<void> _loadTags(String type) async {
final provider = context.read<AppProvider>();
final tags = await provider.getTags(type);
if (mounted) {
setState(() => _tagCache[type] = tags);
}
}
String get _currentType => _tabTypes[_currentIndex];
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
title: const Text('标签管理'),
),
body: Column(
children: [
const SizedBox(height: 8),
_buildTabSelector(),
const SizedBox(height: 20),
Expanded(
child: _buildTagList(_currentType),
),
],
),
floatingActionButton: GestureDetector(
onTap: _showAddDialog,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
decoration: BoxDecoration(
color: const Color(0xFF1A1A1A),
borderRadius: BorderRadius.circular(24),
boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: 0.12),
blurRadius: 12,
offset: const Offset(0, 4),
),
],
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(Icons.add, size: 18, color: Colors.white),
const SizedBox(width: 6),
Text(
'添加${_typeLabels[_currentIndex]}',
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: Colors.white,
),
),
],
),
),
),
);
}
/// 胶囊式 Tab 选择器
Widget _buildTabSelector() {
return Container(
margin: const EdgeInsets.symmetric(horizontal: 20),
padding: const EdgeInsets.all(4),
decoration: BoxDecoration(
color: const Color(0xFFF2F2F2),
borderRadius: BorderRadius.circular(22),
),
child: Row(
children: List.generate(3, (i) {
final selected = _currentIndex == i;
return Expanded(
child: GestureDetector(
onTap: () {
setState(() => _currentIndex = i);
_loadTags(_tabTypes[i]);
},
child: AnimatedContainer(
duration: const Duration(milliseconds: 200),
padding: const EdgeInsets.symmetric(vertical: 9),
decoration: BoxDecoration(
color: selected ? Colors.white : Colors.transparent,
borderRadius: BorderRadius.circular(20),
boxShadow: selected
? [
BoxShadow(
color: Colors.black.withValues(alpha: 0.06),
blurRadius: 6,
offset: const Offset(0, 2),
),
]
: null,
),
child: Text(
_typeLabels[i],
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 14,
fontWeight: selected ? FontWeight.w600 : FontWeight.normal,
color: selected
? const Color(0xFF1A1A1A)
: const Color(0xFF888888),
),
),
),
),
);
}),
),
);
}
Widget _buildTagList(String type) {
final tags = _tagCache[type] ?? [];
if (tags.isEmpty) {
return Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 56,
height: 56,
decoration: BoxDecoration(
color: const Color(0xFFF5F5F5),
borderRadius: BorderRadius.circular(16),
),
child: const Icon(Icons.label_outline,
size: 24, color: Color(0xFFCCCCCC)),
),
const SizedBox(height: 16),
const Text('暂无标签',
style: TextStyle(
fontSize: 14,
color: Color(0xFFBBBBBB),
fontWeight: FontWeight.w500)),
const SizedBox(height: 6),
const Text('点击下方按钮添加',
style: TextStyle(fontSize: 12, color: Color(0xFFD5D5D5))),
],
),
);
}
return SingleChildScrollView(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Wrap(
spacing: 10,
runSpacing: 10,
children: tags.map((tag) => _buildTagChip(tag)).toList(),
),
);
}
Widget _buildTagChip(Map<String, dynamic> tag) {
final name = tag['name'] as String;
return GestureDetector(
onLongPress: () => _showRenameDialog(tag),
onTap: () => _showDeleteDialog(tag),
child: Container(
padding: const EdgeInsets.only(left: 14, right: 6, top: 8, bottom: 8),
decoration: BoxDecoration(
color: const Color(0xFFF8F8F8),
borderRadius: BorderRadius.circular(20),
border: Border.all(color: const Color(0xFFECECEC), width: 0.5),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(
name,
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: Color(0xFF1A1A1A),
),
),
const SizedBox(width: 6),
Container(
width: 22,
height: 22,
decoration: BoxDecoration(
color: const Color(0xFFECECEC),
borderRadius: BorderRadius.circular(11),
),
child: const Icon(Icons.close,
size: 12, color: Color(0xFF999999)),
),
],
),
),
);
}
void _showAddDialog() {
final controller = TextEditingController();
final type = _currentType;
showDialog(
context: context,
builder: (ctx) => AlertDialog(
backgroundColor: Colors.white,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
title: Text(
'添加${_typeLabels[_currentIndex]}',
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
color: Color(0xFF1A1A1A)),
),
content: TextField(
controller: controller,
autofocus: true,
style: const TextStyle(fontSize: 15, color: Color(0xFF1A1A1A)),
decoration: InputDecoration(
hintText: '输入标签名称',
hintStyle:
const TextStyle(fontSize: 14, color: Color(0xFFAAAAAA)),
filled: true,
fillColor: const Color(0xFFFAFAFA),
contentPadding:
const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide.none,
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide:
const BorderSide(color: Color(0xFF1A1A1A), width: 1),
),
),
onSubmitted: (value) =>
_doAddTag(ctx, controller.text.trim(), type),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx),
child: const Text('取消',
style: TextStyle(color: Color(0xFF999999))),
),
Container(
decoration: BoxDecoration(
color: const Color(0xFF1A1A1A),
borderRadius: BorderRadius.circular(20),
),
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: () =>
_doAddTag(ctx, controller.text.trim(), type),
borderRadius: BorderRadius.circular(20),
child: const Padding(
padding:
EdgeInsets.symmetric(horizontal: 20, vertical: 8),
child: Text('添加',
style: TextStyle(
fontSize: 14,
color: Colors.white,
fontWeight: FontWeight.w500)),
),
),
),
),
],
),
);
}
Future<void> _doAddTag(
BuildContext ctx, String name, String type) async {
if (name.isEmpty) return;
try {
await context.read<AppProvider>().addTag(name, type);
} catch (e) {
if (ctx.mounted) {
ToastUtil.show(ctx, '添加失败:该标签已存在');
}
return;
}
if (ctx.mounted) {
Navigator.pop(ctx);
ToastUtil.show(context, '添加成功');
}
await _loadTags(type);
}
void _showRenameDialog(Map<String, dynamic> tag) {
final controller = TextEditingController(text: tag['name'] as String);
final tagId = tag['id'] as String;
final type = tag['type'] as String;
final oldName = tag['name'] as String;
showDialog(
context: context,
builder: (ctx) => AlertDialog(
backgroundColor: Colors.white,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
title: const Text(
'重命名标签',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
color: Color(0xFF1A1A1A)),
),
content: TextField(
controller: controller,
autofocus: true,
style: const TextStyle(fontSize: 15, color: Color(0xFF1A1A1A)),
decoration: InputDecoration(
hintText: '输入新名称',
hintStyle:
const TextStyle(fontSize: 14, color: Color(0xFFAAAAAA)),
filled: true,
fillColor: const Color(0xFFFAFAFA),
contentPadding:
const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide.none,
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide:
const BorderSide(color: Color(0xFF1A1A1A), width: 1),
),
),
onSubmitted: (value) =>
_doRenameTag(ctx, tagId, value.trim(), type, oldName),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx),
child: const Text('取消',
style: TextStyle(color: Color(0xFF999999))),
),
Container(
decoration: BoxDecoration(
color: const Color(0xFF1A1A1A),
borderRadius: BorderRadius.circular(20),
),
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: () =>
_doRenameTag(ctx, tagId, controller.text.trim(), type, oldName),
borderRadius: BorderRadius.circular(20),
child: const Padding(
padding:
EdgeInsets.symmetric(horizontal: 20, vertical: 8),
child: Text('确定',
style: TextStyle(
fontSize: 14,
color: Colors.white,
fontWeight: FontWeight.w500)),
),
),
),
),
],
),
);
}
Future<void> _doRenameTag(BuildContext ctx, String tagId, String newName,
String type, String oldName) async {
if (newName.isEmpty || newName == oldName) {
if (ctx.mounted) Navigator.pop(ctx);
return;
}
final success =
await context.read<AppProvider>().renameTag(tagId, newName, type);
if (ctx.mounted) {
Navigator.pop(ctx);
ToastUtil.show(
context, success ? '重命名成功' : '重命名失败:标签名已存在');
}
if (success) await _loadTags(type);
}
void _showDeleteDialog(Map<String, dynamic> tag) {
final tagId = tag['id'] as String;
final type = tag['type'] as String;
final name = tag['name'] as String;
String? selectedAction = 'remove';
final replacementController = TextEditingController();
final otherTags = (_tagCache[type] ?? [])
.where((t) => t['id'] != tagId)
.map((t) => t['name'] as String)
.toList();
showDialog(
context: context,
builder: (ctx) => StatefulBuilder(
builder: (ctx, setDialogState) => AlertDialog(
backgroundColor: Colors.white,
shape:
RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
title: Row(
children: [
Container(
padding:
const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
decoration: BoxDecoration(
color: const Color(0xFFF5F5F5),
borderRadius: BorderRadius.circular(12),
),
child: Text(
name,
style: const TextStyle(
fontSize: 13,
fontWeight: FontWeight.w500,
color: Color(0xFF666666)),
),
),
const SizedBox(width: 10),
const Text(
'删除标签',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
color: Color(0xFF1A1A1A)),
),
],
),
titlePadding: const EdgeInsets.fromLTRB(24, 24, 24, 0),
content: SizedBox(
width: double.maxFinite,
child: ConstrainedBox(
constraints: BoxConstraints(
maxHeight: MediaQuery.of(ctx).size.height * 0.45,
),
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 4),
const Text(
'删除后对已有条目的影响:',
style: TextStyle(fontSize: 13, color: Color(0xFF999999)),
),
const SizedBox(height: 12),
_buildDeleteOption(
value: 'remove',
groupValue: selectedAction,
onChanged: (v) => setDialogState(() => selectedAction = v),
title: '从所有条目中移除该标签',
),
const SizedBox(height: 4),
_buildDeleteOption(
value: 'replace',
groupValue: selectedAction,
onChanged: (v) => setDialogState(() => selectedAction = v),
title: '替换为其他标签',
),
if (selectedAction == 'replace')
Padding(
padding: const EdgeInsets.only(left: 40, top: 10),
child: otherTags.isNotEmpty
? Wrap(
spacing: 8,
runSpacing: 8,
children: otherTags.map((t) {
final isSelected =
replacementController.text == t;
return GestureDetector(
onTap: () {
replacementController.text =
isSelected ? '' : t;
setDialogState(() {});
},
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 14, vertical: 7),
decoration: BoxDecoration(
color: isSelected
? const Color(0xFF1A1A1A)
: const Color(0xFFF5F5F5),
borderRadius: BorderRadius.circular(16),
border: Border.all(
color: isSelected
? const Color(0xFF1A1A1A)
: const Color(0xFFE8E8E8),
width: 0.5,
),
),
child: Text(
t,
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w500,
color: isSelected
? Colors.white
: const Color(0xFF555555),
),
),
),
);
}).toList(),
)
: Container(
padding: const EdgeInsets.symmetric(
horizontal: 14, vertical: 8),
decoration: BoxDecoration(
color: const Color(0xFFFAFAFA),
borderRadius: BorderRadius.circular(12),
),
child: const Text('无其他标签可替换',
style: TextStyle(
fontSize: 13,
color: Color(0xFFAAAAAA))),
),
),
],
),
),
),
),
contentPadding: const EdgeInsets.fromLTRB(24, 16, 24, 0),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx),
child: const Text('取消',
style: TextStyle(color: Color(0xFF999999))),
),
Container(
decoration: BoxDecoration(
color: const Color(0xFFE53935),
borderRadius: BorderRadius.circular(20),
),
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: () {
String? replacement;
if (selectedAction == 'replace') {
replacement =
replacementController.text.trim().isNotEmpty
? replacementController.text.trim()
: null;
if (replacement == null) return;
}
Navigator.pop(ctx, {
'replacement': replacement,
});
},
borderRadius: BorderRadius.circular(20),
child: const Padding(
padding:
EdgeInsets.symmetric(horizontal: 20, vertical: 8),
child: Text('删除',
style: TextStyle(
fontSize: 14,
color: Colors.white,
fontWeight: FontWeight.w500)),
),
),
),
),
],
actionsPadding: const EdgeInsets.fromLTRB(16, 8, 16, 16),
),
),
).then((result) async {
if (result == null) return;
final replacement = result['replacement'] as String?;
await context
.read<AppProvider>()
.deleteTag(tagId, type, replacementName: replacement);
if (mounted) {
ToastUtil.show(context, '删除成功');
}
await _loadTags(type);
});
}
Widget _buildDeleteOption({
required String value,
required String? groupValue,
required ValueChanged<String?> onChanged,
required String title,
}) {
final selected = value == groupValue;
return GestureDetector(
onTap: () => onChanged(value),
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
decoration: BoxDecoration(
color: selected ? const Color(0xFFFAFAFA) : Colors.white,
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: selected ? const Color(0xFF1A1A1A) : const Color(0xFFEEEEEE),
width: selected ? 1 : 0.5,
),
),
child: Row(
children: [
Container(
width: 18,
height: 18,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
color: selected
? const Color(0xFF1A1A1A)
: const Color(0xFFCCCCCC),
width: selected ? 5 : 1.5,
),
),
),
const SizedBox(width: 12),
Text(
title,
style: TextStyle(
fontSize: 14,
fontWeight: selected ? FontWeight.w500 : FontWeight.normal,
color:
selected ? const Color(0xFF1A1A1A) : const Color(0xFF666666),
),
),
],
),
),
);
}
}