generated from dellevin/template
优化项目结构
This commit is contained in:
120
lib/pages/settings/legal_page.dart
Normal file
120
lib/pages/settings/legal_page.dart
Normal file
@@ -0,0 +1,120 @@
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_markdown_plus/flutter_markdown_plus.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import '../utils/server_config.dart';
|
||||
|
||||
/// 用户服务协议 / 隐私政策查看页面
|
||||
class LegalPage extends StatefulWidget {
|
||||
final String slug;
|
||||
final String title;
|
||||
|
||||
const LegalPage({super.key, required this.slug, required this.title});
|
||||
|
||||
@override
|
||||
State<LegalPage> createState() => _LegalPageState();
|
||||
}
|
||||
|
||||
class _LegalPageState extends State<LegalPage> {
|
||||
String _content = '';
|
||||
bool _isLoading = true;
|
||||
String? _error;
|
||||
|
||||
static final String _baseUrl = ServerConfig.baseUrl;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_load();
|
||||
}
|
||||
|
||||
Future<void> _load() async {
|
||||
try {
|
||||
final resp = await http.get(
|
||||
Uri.parse('$_baseUrl/api/pages/${widget.slug}'),
|
||||
);
|
||||
if (!mounted) return;
|
||||
if (resp.statusCode == 200) {
|
||||
final data = json.decode(resp.body);
|
||||
setState(() {
|
||||
_content = data['content'] ?? '';
|
||||
_isLoading = false;
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
_error = '暂无内容';
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_error = '加载失败,请检查网络';
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
return Scaffold(
|
||||
backgroundColor: colors.surface,
|
||||
appBar: AppBar(title: Text(widget.title)),
|
||||
body: _isLoading
|
||||
? Center(child: CircularProgressIndicator(color: colors.primary))
|
||||
: _error != null
|
||||
? _buildError(colors)
|
||||
: _buildContent(colors),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildContent(ColorScheme colors) {
|
||||
return Markdown(
|
||||
data: _content,
|
||||
padding: const EdgeInsets.fromLTRB(20, 8, 20, 40),
|
||||
styleSheet: MarkdownStyleSheet(
|
||||
h1: TextStyle(fontSize: 22, fontWeight: FontWeight.w600, color: colors.onSurface, height: 1.4),
|
||||
h2: TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: colors.onSurface, height: 1.4),
|
||||
h3: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: colors.onSurface, height: 1.4),
|
||||
p: TextStyle(fontSize: 14, color: colors.onSurface, height: 1.8),
|
||||
code: TextStyle(fontSize: 13, color: colors.onSurface, backgroundColor: colors.surfaceContainerHighest),
|
||||
codeblockDecoration: BoxDecoration(
|
||||
color: colors.surfaceContainerHighest,
|
||||
border: Border.all(color: colors.outline),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
codeblockPadding: const EdgeInsets.all(12),
|
||||
blockquote: TextStyle(fontSize: 14, color: colors.onSurface.withValues(alpha: 0.6), fontStyle: FontStyle.italic),
|
||||
blockquoteDecoration: BoxDecoration(
|
||||
border: Border(left: BorderSide(color: colors.onSurface.withValues(alpha: 0.4), width: 4)),
|
||||
),
|
||||
blockquotePadding: const EdgeInsets.only(left: 12),
|
||||
listBullet: TextStyle(fontSize: 14, color: colors.onSurface),
|
||||
listIndent: 24,
|
||||
a: const TextStyle(fontSize: 14, color: Color(0xFF4A90D9), decoration: TextDecoration.underline),
|
||||
horizontalRuleDecoration: BoxDecoration(
|
||||
border: Border(top: BorderSide(color: colors.outline, width: 0.5)),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildError(ColorScheme colors) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.article_outlined, size: 48, color: colors.onSurface.withValues(alpha: 0.25)),
|
||||
const SizedBox(height: 16),
|
||||
Text(_error!, style: TextStyle(fontSize: 14, color: colors.onSurface.withValues(alpha: 0.4))),
|
||||
const SizedBox(height: 16),
|
||||
TextButton(
|
||||
onPressed: () { setState(() { _isLoading = true; _error = null; }); _load(); },
|
||||
child: Text('重试', style: TextStyle(color: colors.primary)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
508
lib/pages/settings/recycle_bin_page.dart
Normal file
508
lib/pages/settings/recycle_bin_page.dart
Normal file
@@ -0,0 +1,508 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../providers/app_provider.dart';
|
||||
import '../models/data_models.dart';
|
||||
import '../utils/toast_util.dart';
|
||||
|
||||
/// 回收站页面
|
||||
class RecycleBinPage extends StatefulWidget {
|
||||
const RecycleBinPage({super.key});
|
||||
|
||||
@override
|
||||
State<RecycleBinPage> createState() => _RecycleBinPageState();
|
||||
}
|
||||
|
||||
enum _ItemType { movie, book, note, movieReview, bookReview, bookExcerpt }
|
||||
|
||||
class _DeletedItem {
|
||||
final _ItemType type;
|
||||
final String id;
|
||||
final String title;
|
||||
final String subtitle;
|
||||
final IconData icon;
|
||||
final String typeLabel;
|
||||
|
||||
_DeletedItem.movie(Movie m)
|
||||
: type = _ItemType.movie,
|
||||
id = m.id,
|
||||
title = m.title,
|
||||
subtitle = '删除于 ${m.updatedAt.year}.${m.updatedAt.month.toString().padLeft(2, '0')}.${m.updatedAt.day.toString().padLeft(2, '0')}',
|
||||
icon = Icons.movie_outlined,
|
||||
typeLabel = '影视';
|
||||
|
||||
_DeletedItem.book(Book b)
|
||||
: type = _ItemType.book,
|
||||
id = b.id,
|
||||
title = b.title,
|
||||
subtitle = '删除于 ${b.updatedAt.year}.${b.updatedAt.month.toString().padLeft(2, '0')}.${b.updatedAt.day.toString().padLeft(2, '0')}',
|
||||
icon = Icons.menu_book_outlined,
|
||||
typeLabel = '书籍';
|
||||
|
||||
_DeletedItem.note(Note n)
|
||||
: type = _ItemType.note,
|
||||
id = n.id,
|
||||
title = n.title.isNotEmpty ? n.title : n.summary,
|
||||
subtitle = '删除于 ${n.updatedAt.year}.${n.updatedAt.month.toString().padLeft(2, '0')}.${n.updatedAt.day.toString().padLeft(2, '0')}',
|
||||
icon = Icons.description_outlined,
|
||||
typeLabel = '笔记';
|
||||
|
||||
_DeletedItem.movieReview(MovieReview r)
|
||||
: type = _ItemType.movieReview,
|
||||
id = r.id,
|
||||
title = r.content.isNotEmpty ? r.content : '影评',
|
||||
subtitle = '删除于 ${r.updatedAt.year}.${r.updatedAt.month.toString().padLeft(2, '0')}.${r.updatedAt.day.toString().padLeft(2, '0')}',
|
||||
icon = Icons.rate_review_outlined,
|
||||
typeLabel = '影评';
|
||||
|
||||
_DeletedItem.bookReview(BookReview r)
|
||||
: type = _ItemType.bookReview,
|
||||
id = r.id,
|
||||
title = r.content.isNotEmpty ? r.content : '书评',
|
||||
subtitle = '删除于 ${r.updatedAt.year}.${r.updatedAt.month.toString().padLeft(2, '0')}.${r.updatedAt.day.toString().padLeft(2, '0')}',
|
||||
icon = Icons.rate_review_outlined,
|
||||
typeLabel = '书评';
|
||||
|
||||
_DeletedItem.bookExcerpt(BookExcerpt e)
|
||||
: type = _ItemType.bookExcerpt,
|
||||
id = e.id,
|
||||
title = e.content.isNotEmpty ? e.content : '摘抄',
|
||||
subtitle = '删除于 ${e.updatedAt.year}.${e.updatedAt.month.toString().padLeft(2, '0')}.${e.updatedAt.day.toString().padLeft(2, '0')}',
|
||||
icon = Icons.format_quote_outlined,
|
||||
typeLabel = '书摘';
|
||||
|
||||
}
|
||||
|
||||
class _RecycleBinPageState extends State<RecycleBinPage> {
|
||||
List<_DeletedItem> _allItems = [];
|
||||
_ItemType? _filterType;
|
||||
bool _isLoading = true;
|
||||
|
||||
List<_DeletedItem> get _filteredItems =>
|
||||
_filterType == null ? _allItems : _allItems.where((i) => i.type == _filterType).toList();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadDeletedItems();
|
||||
}
|
||||
|
||||
Future<void> _loadDeletedItems() async {
|
||||
setState(() => _isLoading = true);
|
||||
final provider = context.read<AppProvider>();
|
||||
final movies = await provider.getDeletedMovies();
|
||||
final books = await provider.getDeletedBooks();
|
||||
final notes = await provider.getDeletedNotes();
|
||||
final movieReviews = await provider.getDeletedMovieReviews();
|
||||
final bookReviews = await provider.getDeletedBookReviews();
|
||||
final bookExcerpts = await provider.getDeletedBookExcerpts();
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_allItems = [
|
||||
for (final m in movies) _DeletedItem.movie(m),
|
||||
for (final b in books) _DeletedItem.book(b),
|
||||
for (final n in notes) _DeletedItem.note(n),
|
||||
for (final r in movieReviews) _DeletedItem.movieReview(r),
|
||||
for (final r in bookReviews) _DeletedItem.bookReview(r),
|
||||
for (final e in bookExcerpts) _DeletedItem.bookExcerpt(e),
|
||||
];
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
return Scaffold(
|
||||
backgroundColor: colors.surface,
|
||||
appBar: AppBar(
|
||||
title: const Text('回收站'),
|
||||
actions: [
|
||||
if (_allItems.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 12),
|
||||
child: TextButton(
|
||||
onPressed: _showClearAllDialog,
|
||||
style: TextButton.styleFrom(
|
||||
backgroundColor: colors.surface,
|
||||
foregroundColor: Colors.red,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 6),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
side: BorderSide(color: colors.error.withValues(alpha: 0.15), width: 0.5),
|
||||
),
|
||||
minimumSize: Size.zero,
|
||||
),
|
||||
child: const Text('清空', style: TextStyle(fontSize: 12, fontWeight: FontWeight.w500)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: _isLoading
|
||||
? Center(child: CircularProgressIndicator(strokeWidth: 2, color: colors.primary))
|
||||
: Column(
|
||||
children: [
|
||||
if (_allItems.isNotEmpty) _buildFilterRow(),
|
||||
Expanded(
|
||||
child: _filteredItems.isEmpty
|
||||
? _buildEmptyState()
|
||||
: RefreshIndicator(
|
||||
onRefresh: _loadDeletedItems,
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
itemCount: _filteredItems.length,
|
||||
itemBuilder: (_, i) => _buildCard(_filteredItems[i]),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFilterRow() {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
border: Border(bottom: BorderSide(color: colors.outlineVariant, width: 0.5)),
|
||||
),
|
||||
child: Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
_filterChip('全部', null),
|
||||
_filterChip('影视', _ItemType.movie),
|
||||
_filterChip('书籍', _ItemType.book),
|
||||
_filterChip('笔记', _ItemType.note),
|
||||
_filterChip('影评', _ItemType.movieReview),
|
||||
_filterChip('书评', _ItemType.bookReview),
|
||||
_filterChip('书摘', _ItemType.bookExcerpt),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _filterChip(String label, _ItemType? type) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
final active = _filterType == type;
|
||||
final count = type == null ? _allItems.length : _allItems.where((i) => i.type == type).length;
|
||||
return GestureDetector(
|
||||
onTap: () => setState(() => _filterType = type),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 5),
|
||||
decoration: BoxDecoration(
|
||||
color: active ? colors.primary : colors.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Text(
|
||||
'$label · $count',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: active ? colors.onPrimary : colors.onSurface.withValues(alpha: 0.5),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCard(_DeletedItem item) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
return Dismissible(
|
||||
key: Key('${item.type.name}_${item.id}'),
|
||||
direction: DismissDirection.endToStart,
|
||||
background: _buildDismissBackground(),
|
||||
confirmDismiss: (_) async => _showConfirmDialog('确定要彻底删除吗?此操作不可恢复。'),
|
||||
onDismissed: (_) => _permanentDelete(item),
|
||||
child: Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: colors.surfaceContainerHigh,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: colors.outlineVariant, width: 0.5),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: colors.surface,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: colors.outlineVariant, width: 0.5),
|
||||
),
|
||||
child: Icon(item.icon, size: 20, color: colors.onSurface.withValues(alpha: 0.5)),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
item.title,
|
||||
style: TextStyle(fontSize: 14, fontWeight: FontWeight.w500, color: colors.onSurface, height: 1.3),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 1),
|
||||
decoration: BoxDecoration(
|
||||
color: colors.surface,
|
||||
borderRadius: BorderRadius.circular(3),
|
||||
border: Border.all(color: colors.outlineVariant, width: 0.5),
|
||||
),
|
||||
child: Text(
|
||||
item.typeLabel,
|
||||
style: TextStyle(fontSize: 9, fontWeight: FontWeight.w600, color: colors.onSurface.withValues(alpha: 0.4)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 3),
|
||||
Text(
|
||||
item.subtitle,
|
||||
style: TextStyle(fontSize: 11, color: colors.onSurface.withValues(alpha: 0.35)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
_actionBtn(Icons.restore, '恢复', colors.primary, () => _restore(item)),
|
||||
const SizedBox(width: 6),
|
||||
_actionBtn(Icons.delete_outline, '删除', colors.error, () => _permanentDelete(item)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDismissBackground() {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.red,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
alignment: Alignment.centerRight,
|
||||
padding: const EdgeInsets.only(right: 24),
|
||||
child: const Icon(Icons.delete_forever, color: Colors.white, size: 22),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _actionBtn(IconData icon, String tooltip, Color color, VoidCallback onTap) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
return Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
child: Tooltip(
|
||||
message: tooltip,
|
||||
child: Container(
|
||||
width: 32,
|
||||
height: 32,
|
||||
decoration: BoxDecoration(
|
||||
color: colors.surface,
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
border: Border.all(color: colors.outlineVariant, width: 0.5),
|
||||
),
|
||||
child: Icon(icon, size: 16, color: color),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmptyState() {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
width: 72,
|
||||
height: 72,
|
||||
decoration: BoxDecoration(
|
||||
color: colors.surfaceContainerHigh,
|
||||
borderRadius: BorderRadius.circular(18),
|
||||
),
|
||||
child: Icon(Icons.delete_outline, size: 32, color: colors.onSurface.withValues(alpha: 0.15)),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
_filterType == null ? '回收站是空的' : '没有删除的项目',
|
||||
style: TextStyle(fontSize: 14, color: colors.onSurface.withValues(alpha: 0.35)),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text('删除的项目会显示在这里', style: TextStyle(fontSize: 12, color: colors.onSurface.withValues(alpha: 0.25))),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _restore(_DeletedItem item) async {
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
backgroundColor: Theme.of(context).colorScheme.surface,
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
title: Text('确认恢复', style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: Theme.of(context).colorScheme.onSurface)),
|
||||
content: Text('确定要恢复"${item.title}"到${item.typeLabel}里面吗?', style: TextStyle(fontSize: 14, color: Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.6), height: 1.5)),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(ctx, false),
|
||||
style: TextButton.styleFrom(foregroundColor: Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.6)),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () => Navigator.pop(ctx, true),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||
foregroundColor: Theme.of(context).colorScheme.onPrimary,
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
||||
),
|
||||
child: const Text('恢复'),
|
||||
),
|
||||
],
|
||||
actionsPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
),
|
||||
);
|
||||
if (confirmed != true || !mounted) return;
|
||||
final provider = context.read<AppProvider>();
|
||||
switch (item.type) {
|
||||
case _ItemType.movie:
|
||||
await provider.restoreMovie(item.id);
|
||||
if (mounted) ToastUtil.show(context, '影视已恢复');
|
||||
case _ItemType.book:
|
||||
await provider.restoreBook(item.id);
|
||||
if (mounted) ToastUtil.show(context, '书籍已恢复');
|
||||
case _ItemType.note:
|
||||
await provider.restoreNote(item.id);
|
||||
if (mounted) ToastUtil.show(context, '笔记已恢复');
|
||||
case _ItemType.movieReview:
|
||||
await provider.restoreMovieReview(item.id);
|
||||
if (mounted) ToastUtil.show(context, '影评已恢复');
|
||||
case _ItemType.bookReview:
|
||||
await provider.restoreBookReview(item.id);
|
||||
if (mounted) ToastUtil.show(context, '书评已恢复');
|
||||
case _ItemType.bookExcerpt:
|
||||
await provider.restoreBookExcerpt(item.id);
|
||||
if (mounted) ToastUtil.show(context, '书摘已恢复');
|
||||
}
|
||||
_loadDeletedItems();
|
||||
}
|
||||
|
||||
Future<void> _permanentDelete(_DeletedItem item) async {
|
||||
final confirmed = await _showConfirmDialog('确定要彻底删除吗?此操作不可恢复。');
|
||||
if (!confirmed) return;
|
||||
final provider = context.read<AppProvider>();
|
||||
switch (item.type) {
|
||||
case _ItemType.movie:
|
||||
await provider.permanentDeleteMovie(item.id);
|
||||
case _ItemType.book:
|
||||
await provider.permanentDeleteBook(item.id);
|
||||
case _ItemType.note:
|
||||
await provider.permanentDeleteNote(item.id);
|
||||
case _ItemType.movieReview:
|
||||
await provider.permanentDeleteMovieReview(item.id);
|
||||
case _ItemType.bookReview:
|
||||
await provider.permanentDeleteBookReview(item.id);
|
||||
case _ItemType.bookExcerpt:
|
||||
await provider.permanentDeleteBookExcerpt(item.id);
|
||||
}
|
||||
_loadDeletedItems();
|
||||
if (mounted) ToastUtil.show(context, '已彻底删除');
|
||||
}
|
||||
|
||||
Future<bool> _showConfirmDialog(String message) async {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
final result = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
backgroundColor: colors.surface,
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
title: Text('确认删除', style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: colors.onSurface)),
|
||||
content: Text(message, style: TextStyle(fontSize: 14, color: colors.onSurface.withValues(alpha: 0.6), height: 1.5)),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(ctx, false),
|
||||
style: TextButton.styleFrom(foregroundColor: colors.onSurface.withValues(alpha: 0.6)),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () => Navigator.pop(ctx, true),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: colors.error,
|
||||
foregroundColor: colors.onError,
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
||||
),
|
||||
child: const Text('删除'),
|
||||
),
|
||||
],
|
||||
actionsPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
),
|
||||
);
|
||||
return result ?? false;
|
||||
}
|
||||
|
||||
void _showClearAllDialog() {
|
||||
final pageContext = context;
|
||||
final colors = Theme.of(pageContext).colorScheme;
|
||||
showDialog(
|
||||
context: pageContext,
|
||||
builder: (ctx) => AlertDialog(
|
||||
backgroundColor: colors.surface,
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
title: Row(
|
||||
children: [
|
||||
const Icon(Icons.warning_amber_rounded, color: Colors.red, size: 22),
|
||||
const SizedBox(width: 8),
|
||||
Text('清空回收站', style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: colors.onSurface)),
|
||||
],
|
||||
),
|
||||
content: Text(
|
||||
'确定要清空回收站吗?所有项目将被彻底删除,此操作不可恢复。',
|
||||
style: TextStyle(fontSize: 14, color: colors.onSurface.withValues(alpha: 0.6), height: 1.5),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(ctx),
|
||||
style: TextButton.styleFrom(foregroundColor: colors.onSurface.withValues(alpha: 0.6)),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
Navigator.pop(ctx);
|
||||
await pageContext.read<AppProvider>().clearRecycleBin();
|
||||
_loadDeletedItems();
|
||||
if (mounted) ToastUtil.show(pageContext, '回收站已清空');
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: colors.error,
|
||||
foregroundColor: colors.onError,
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
||||
),
|
||||
child: const Text('清空'),
|
||||
),
|
||||
],
|
||||
actionsPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
986
lib/pages/settings/tag_management_page.dart
Normal file
986
lib/pages/settings/tag_management_page.dart
Normal file
@@ -0,0 +1,986 @@
|
||||
import 'dart:async';
|
||||
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;
|
||||
bool _isSyncing = false;
|
||||
|
||||
static const _tabTypes = ['movie_genre', 'book_genre', 'note_tag'];
|
||||
static const _typeLabels = ['影视类型', '书籍类型', '笔记标签'];
|
||||
static const _typeIcons = [Icons.movie_outlined, Icons.menu_book_outlined, Icons.note_outlined];
|
||||
|
||||
final Map<String, List<Map<String, dynamic>>> _tagCache = {};
|
||||
Map<String, int> _usageCounts = {};
|
||||
String? _newlyAddedTagId;
|
||||
String _searchQuery = '';
|
||||
final _searchController = TextEditingController();
|
||||
bool _showTypePicker = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadTags(_tabTypes[0]);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_searchController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
_updateUsageCounts();
|
||||
}
|
||||
|
||||
void _updateUsageCounts() {
|
||||
final provider = context.read<AppProvider>();
|
||||
final counts = <String, int>{};
|
||||
|
||||
for (final m in provider.movies.where((m) => !m.isDeleted)) {
|
||||
for (final g in m.genres) {
|
||||
counts[g] = (counts[g] ?? 0) + 1;
|
||||
}
|
||||
}
|
||||
for (final b in provider.books.where((b) => !b.isDeleted)) {
|
||||
for (final g in b.genres) {
|
||||
counts[g] = (counts[g] ?? 0) + 1;
|
||||
}
|
||||
}
|
||||
for (final n in provider.notes.where((n) => !n.isDeleted)) {
|
||||
for (final t in n.tags) {
|
||||
counts[t] = (counts[t] ?? 0) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
_usageCounts = counts;
|
||||
}
|
||||
|
||||
Future<void> _loadTags(String type) async {
|
||||
final provider = context.read<AppProvider>();
|
||||
final tags = await provider.getTags(type);
|
||||
if (mounted) setState(() => _tagCache[type] = tags);
|
||||
}
|
||||
|
||||
Future<void> _syncTags() async {
|
||||
setState(() => _isSyncing = true);
|
||||
try {
|
||||
final provider = context.read<AppProvider>();
|
||||
final count = await provider.syncTagsFromData();
|
||||
if (mounted) {
|
||||
ToastUtil.show(context, count > 0 ? '已同步 $count 个新标签' : '标签已是最新');
|
||||
await _loadTags(_currentType);
|
||||
_updateUsageCounts();
|
||||
}
|
||||
} finally {
|
||||
if (mounted) setState(() => _isSyncing = false);
|
||||
}
|
||||
}
|
||||
|
||||
void _onTabChanged(int index) {
|
||||
setState(() => _currentIndex = index);
|
||||
_loadTags(_tabTypes[index]);
|
||||
}
|
||||
|
||||
String get _currentType => _tabTypes[_currentIndex];
|
||||
|
||||
// ─── build ─────────────────────────────────────────────────────────────
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: colors.surfaceContainerHigh,
|
||||
appBar: AppBar(title: const Text('标签管理'), actions: [
|
||||
_isSyncing
|
||||
? Padding(padding: const EdgeInsets.all(16),
|
||||
child: SizedBox(width: 20, height: 20, child: CircularProgressIndicator(strokeWidth: 2, color: colors.primary)))
|
||||
: IconButton(icon: const Icon(Icons.sync, size: 20), tooltip: '从数据中同步标签', onPressed: _syncTags),
|
||||
]),
|
||||
body: AnimatedSwitcher(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
switchInCurve: Curves.easeOut,
|
||||
switchOutCurve: Curves.easeIn,
|
||||
child: _buildTagList(_currentType),
|
||||
),
|
||||
floatingActionButton: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// 弹出的类别胶囊按钮
|
||||
if (_showTypePicker) ...[
|
||||
...[0, 1, 2].where((i) => i != _currentIndex).map((i) => Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
setState(() => _showTypePicker = false);
|
||||
_onTabChanged(i);
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: colors.surface, borderRadius: BorderRadius.circular(24),
|
||||
boxShadow: [BoxShadow(color: Colors.black.withValues(alpha: 0.1), blurRadius: 8, offset: const Offset(0, 2))],
|
||||
),
|
||||
child: Row(mainAxisSize: MainAxisSize.min, children: [
|
||||
Icon(_typeIcons[i], size: 16, color: colors.onSurface.withValues(alpha: 0.6)),
|
||||
const SizedBox(width: 6),
|
||||
Text(_typeLabels[i], style: TextStyle(fontSize: 13, fontWeight: FontWeight.w500, color: colors.onSurface)),
|
||||
]),
|
||||
),
|
||||
),
|
||||
)),
|
||||
const SizedBox(height: 4),
|
||||
],
|
||||
// 底部按钮行
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// 类别切换按钮
|
||||
GestureDetector(
|
||||
onTap: () => setState(() => _showTypePicker = !_showTypePicker),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: colors.surface, borderRadius: BorderRadius.circular(24),
|
||||
boxShadow: [BoxShadow(color: Colors.black.withValues(alpha: 0.1), blurRadius: 8, offset: const Offset(0, 2))],
|
||||
),
|
||||
child: Row(mainAxisSize: MainAxisSize.min, children: [
|
||||
Icon(_typeIcons[_currentIndex], size: 16, color: colors.onSurface.withValues(alpha: 0.6)),
|
||||
const SizedBox(width: 6),
|
||||
Text(_typeLabels[_currentIndex], style: TextStyle(fontSize: 13, fontWeight: FontWeight.w500, color: colors.onSurface)),
|
||||
const SizedBox(width: 4),
|
||||
Icon(_showTypePicker ? Icons.arrow_drop_down : Icons.arrow_drop_up, size: 18, color: colors.onSurface.withValues(alpha: 0.4)),
|
||||
]),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
// 添加按钮
|
||||
GestureDetector(
|
||||
onTap: _showAddDialog,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: colors.primary, 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: [
|
||||
Icon(Icons.add, size: 18, color: colors.onPrimary),
|
||||
const SizedBox(width: 6),
|
||||
Text('添加${_typeLabels[_currentIndex]}', style: TextStyle(fontSize: 14, fontWeight: FontWeight.w500, color: colors.onPrimary)),
|
||||
]),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatChip(IconData icon, String label, int count, ColorScheme colors) {
|
||||
return Expanded(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
decoration: BoxDecoration(color: colors.surface, borderRadius: BorderRadius.circular(8)),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(icon, size: 14, color: colors.onSurface.withValues(alpha: 0.5)),
|
||||
const SizedBox(width: 4),
|
||||
Text('$count', style: TextStyle(fontSize: 13, fontWeight: FontWeight.w600, color: colors.onSurface)),
|
||||
const SizedBox(width: 2),
|
||||
Text(label, style: TextStyle(fontSize: 10, color: colors.onSurface.withValues(alpha: 0.4))),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ─── 标签列表 ──────────────────────────────────────────────────────────
|
||||
|
||||
Widget _buildTagList(String type) {
|
||||
final tags = _tagCache[type] ?? [];
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
final isSearching = _searchQuery.isNotEmpty;
|
||||
|
||||
if (tags.isEmpty && !isSearching) {
|
||||
return SingleChildScrollView(
|
||||
key: ValueKey('empty_$type'),
|
||||
padding: const EdgeInsets.fromLTRB(20, 4, 20, 80),
|
||||
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
_buildSearchBar(colors),
|
||||
const SizedBox(height: 40),
|
||||
_buildEmptyState(type),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
// 搜索模式
|
||||
if (isSearching) {
|
||||
final filtered = tags.where((t) => (t['name'] as String).toLowerCase().contains(_searchQuery.toLowerCase())).toList()
|
||||
..sort((a, b) => (_usageCounts[b['name']] ?? 0).compareTo(_usageCounts[a['name']] ?? 0));
|
||||
return SingleChildScrollView(
|
||||
key: ValueKey('search_$type'),
|
||||
padding: const EdgeInsets.fromLTRB(20, 4, 20, 80),
|
||||
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
_buildSearchBar(colors),
|
||||
const SizedBox(height: 12),
|
||||
if (filtered.isEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 24),
|
||||
child: Center(child: Text('没有找到"$_searchQuery"相关标签', style: TextStyle(fontSize: 13, color: colors.onSurface.withValues(alpha: 0.4)))),
|
||||
)
|
||||
else
|
||||
Wrap(spacing: 8, runSpacing: 6, children: filtered.map(_buildTagChip).toList()),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
// 分组模式
|
||||
final used = <Map<String, dynamic>>[];
|
||||
final unused = <Map<String, dynamic>>[];
|
||||
final hidden = <Map<String, dynamic>>[];
|
||||
for (final t in tags) {
|
||||
if ((t['is_hidden'] as int?) == 1) { hidden.add(t); continue; }
|
||||
if ((_usageCounts[t['name']] ?? 0) > 0) { used.add(t); continue; }
|
||||
unused.add(t);
|
||||
}
|
||||
used.sort((a, b) => (_usageCounts[b['name']] ?? 0).compareTo(_usageCounts[a['name']] ?? 0));
|
||||
|
||||
return SingleChildScrollView(
|
||||
key: ValueKey(type),
|
||||
padding: const EdgeInsets.fromLTRB(20, 4, 20, 80),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildSearchBar(colors),
|
||||
// 统计栏
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8, bottom: 8),
|
||||
child: Row(children: [
|
||||
_buildStatChip(Icons.check_circle_outline, '已使用', used.length, colors),
|
||||
const SizedBox(width: 8),
|
||||
_buildStatChip(Icons.radio_button_unchecked, '未使用', unused.length, colors),
|
||||
const SizedBox(width: 8),
|
||||
_buildStatChip(Icons.visibility_off_outlined, '隐藏', hidden.length, colors),
|
||||
]),
|
||||
),
|
||||
_buildGroupHeader('已使用', used.length, colors),
|
||||
const SizedBox(height: 6),
|
||||
used.isNotEmpty
|
||||
? Wrap(spacing: 8, runSpacing: 6, children: used.map(_buildTagChip).toList())
|
||||
: _buildEmptyGroup('暂无已使用标签', colors),
|
||||
const SizedBox(height: 16),
|
||||
_buildGroupHeader('未使用', unused.length, colors),
|
||||
const SizedBox(height: 6),
|
||||
unused.isNotEmpty
|
||||
? Wrap(spacing: 8, runSpacing: 6, children: unused.map(_buildTagChip).toList())
|
||||
: _buildEmptyGroup('暂无未使用标签', colors),
|
||||
const SizedBox(height: 16),
|
||||
_buildGroupHeader('隐藏', hidden.length, colors),
|
||||
const SizedBox(height: 6),
|
||||
hidden.isNotEmpty
|
||||
? Wrap(spacing: 8, runSpacing: 6, children: hidden.map(_buildTagChip).toList())
|
||||
: _buildEmptyGroup('暂无隐藏标签', colors),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSearchBar(ColorScheme colors) {
|
||||
return Container(
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: colors.surface,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: colors.outlineVariant, width: 0.5),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const SizedBox(width: 12),
|
||||
Icon(Icons.search_rounded, size: 18, color: colors.onSurface.withValues(alpha: 0.35)),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _searchController,
|
||||
style: TextStyle(fontSize: 14, color: colors.onSurface),
|
||||
cursorColor: colors.primary,
|
||||
decoration: InputDecoration(
|
||||
hintText: '搜索标签...',
|
||||
hintStyle: TextStyle(fontSize: 14, color: colors.onSurface.withValues(alpha: 0.3)),
|
||||
isDense: true,
|
||||
contentPadding: const EdgeInsets.symmetric(vertical: 10),
|
||||
border: InputBorder.none,
|
||||
enabledBorder: InputBorder.none,
|
||||
focusedBorder: InputBorder.none,
|
||||
filled: false,
|
||||
),
|
||||
onChanged: (v) => setState(() => _searchQuery = v.trim()),
|
||||
),
|
||||
),
|
||||
if (_searchQuery.isNotEmpty)
|
||||
GestureDetector(
|
||||
onTap: () { _searchController.clear(); setState(() => _searchQuery = ''); FocusManager.instance.primaryFocus?.unfocus(); },
|
||||
child: Container(
|
||||
margin: const EdgeInsets.only(right: 8),
|
||||
padding: const EdgeInsets.all(4),
|
||||
decoration: BoxDecoration(color: colors.surfaceContainerHighest, shape: BoxShape.circle),
|
||||
child: Icon(Icons.close_rounded, size: 14, color: colors.onSurface.withValues(alpha: 0.4)),
|
||||
),
|
||||
)
|
||||
else
|
||||
const SizedBox(width: 12),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildGroupHeader(String label, int count, ColorScheme colors) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 2),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(label, style: TextStyle(fontSize: 13, fontWeight: FontWeight.w600, color: colors.onSurface.withValues(alpha: 0.5))),
|
||||
const SizedBox(width: 6),
|
||||
Text('$count', style: TextStyle(fontSize: 12, color: colors.onSurface.withValues(alpha: 0.3))),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmptyGroup(String text, ColorScheme colors) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
child: Text(text, style: TextStyle(fontSize: 12, color: colors.onSurface.withValues(alpha: 0.3))),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTagChip(Map<String, dynamic> tag) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
final name = tag['name'] as String;
|
||||
final count = _usageCounts[name] ?? 0;
|
||||
final tagId = tag['id'] as String;
|
||||
final isNew = tagId == _newlyAddedTagId;
|
||||
final isHidden = (tag['is_hidden'] as int?) == 1;
|
||||
|
||||
return GestureDetector(
|
||||
key: ValueKey(tagId),
|
||||
onTap: () => _showTagMenu(tag),
|
||||
onLongPress: () => _showTagMenu(tag),
|
||||
child: Opacity(
|
||||
opacity: isHidden ? 0.4 : 1.0,
|
||||
child: isNew
|
||||
? _NewTagHighlight(child: _tagChipContent(name, count, colors, isHidden: isHidden))
|
||||
: _tagChipContent(name, count, colors, isHidden: isHidden),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _tagChipContent(String name, int count, ColorScheme colors, {bool isHidden = false}) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 4),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: colors.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(name, style: TextStyle(
|
||||
fontSize: 12, fontWeight: FontWeight.w500, color: colors.onSurface,
|
||||
decoration: isHidden ? TextDecoration.lineThrough : null,
|
||||
)),
|
||||
if (count > 0) ...[
|
||||
const SizedBox(width: 6),
|
||||
Text('$count', style: TextStyle(fontSize: 10, fontWeight: FontWeight.w600, color: colors.onSurface.withValues(alpha: 0.35))),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ─── 新标签高亮动画 ─────────────────────────────────────────────────────
|
||||
|
||||
Widget _buildEmptyState(String type) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
final idx = _tabTypes.indexOf(type);
|
||||
final icon = _typeIcons[idx];
|
||||
final label = _typeLabels[idx];
|
||||
final hints = ['同步或手动添加影视类型', '同步或手动添加书籍类型', '同步或手动添加笔记标签'];
|
||||
|
||||
return Center(
|
||||
key: ValueKey('empty_$type'),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
width: 64, height: 64,
|
||||
decoration: BoxDecoration(color: colors.outlineVariant, borderRadius: BorderRadius.circular(18)),
|
||||
child: Icon(icon, size: 28, color: colors.onSurface.withValues(alpha: 0.25)),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text('暂无$label',
|
||||
style: TextStyle(fontSize: 14, color: colors.onSurface.withValues(alpha: 0.3), fontWeight: FontWeight.w500)),
|
||||
const SizedBox(height: 6),
|
||||
Text(hints[idx], style: TextStyle(fontSize: 12, color: colors.onSurface.withValues(alpha: 0.15))),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ─── 标签操作菜单 ───────────────────────────────────────────────────────
|
||||
|
||||
void _showTagMenu(Map<String, dynamic> tag) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
final name = tag['name'] as String;
|
||||
final isHidden = (tag['is_hidden'] as int?) == 1;
|
||||
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
backgroundColor: colors.surface,
|
||||
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.vertical(top: Radius.circular(20))),
|
||||
builder: (ctx) {
|
||||
return SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 8, 20, 24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Center(child: Container(
|
||||
width: 40, height: 4, margin: const EdgeInsets.only(bottom: 20),
|
||||
decoration: BoxDecoration(color: colors.onSurface.withValues(alpha: 0.15), borderRadius: BorderRadius.circular(2)),
|
||||
)),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
||||
decoration: BoxDecoration(color: colors.surfaceContainerHighest, borderRadius: BorderRadius.circular(12)),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(child: Text(name, style: TextStyle(fontSize: 15, fontWeight: FontWeight.w600, color: colors.onSurface))),
|
||||
if (isHidden) Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
|
||||
decoration: BoxDecoration(color: colors.outlineVariant, borderRadius: BorderRadius.circular(4)),
|
||||
child: Text('已隐藏', style: TextStyle(fontSize: 11, color: colors.onSurface.withValues(alpha: 0.5))),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_menuAction(
|
||||
isHidden ? Icons.visibility_outlined : Icons.visibility_off_outlined,
|
||||
isHidden ? '取消隐藏' : '隐藏',
|
||||
colors,
|
||||
() async {
|
||||
Navigator.pop(ctx);
|
||||
await context.read<AppProvider>().toggleTagHidden(tag['id'] as String);
|
||||
await _loadTags(_currentType);
|
||||
},
|
||||
),
|
||||
_menuAction(Icons.open_in_new_outlined, '查看相关${_typeLabels[_currentIndex].replaceAll('类型', '').replaceAll('标签', '')}', colors, () {
|
||||
Navigator.pop(ctx);
|
||||
_showTagItems(name);
|
||||
}),
|
||||
_menuAction(Icons.edit_outlined, '重命名', colors, () {
|
||||
Navigator.pop(ctx);
|
||||
_showRenameDialog(tag);
|
||||
}),
|
||||
_menuAction(Icons.delete_outline, '删除', colors, () {
|
||||
Navigator.pop(ctx);
|
||||
_showDeleteDialog(tag);
|
||||
}, isDestructive: true),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _menuAction(IconData icon, String title, ColorScheme colors, VoidCallback onTap, {bool isDestructive = false}) {
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 14, horizontal: 4),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(icon, size: 20, color: isDestructive ? const Color(0xFFE53935) : colors.onSurface.withValues(alpha: 0.7)),
|
||||
const SizedBox(width: 14),
|
||||
Text(title, style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: isDestructive ? const Color(0xFFE53935) : colors.onSurface,
|
||||
)),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showTagItems(String tagName) {
|
||||
final provider = context.read<AppProvider>();
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
|
||||
List<({String title, String? subtitle, String type})> items = [];
|
||||
if (_currentType == 'movie_genre') {
|
||||
for (final m in provider.movies.where((m) => !m.isDeleted && m.genres.contains(tagName))) {
|
||||
items.add((title: m.title, subtitle: m.directors.take(2).join(' / '), type: '影视'));
|
||||
}
|
||||
} else if (_currentType == 'book_genre') {
|
||||
for (final b in provider.books.where((b) => !b.isDeleted && b.genres.contains(tagName))) {
|
||||
items.add((title: b.title, subtitle: b.authors.take(2).join(' / '), type: '书籍'));
|
||||
}
|
||||
} else {
|
||||
for (final n in provider.notes.where((n) => !n.isDeleted && n.tags.contains(tagName))) {
|
||||
items.add((title: n.title.isNotEmpty ? n.title : '随手记', subtitle: null, type: '笔记'));
|
||||
}
|
||||
}
|
||||
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
backgroundColor: colors.surface,
|
||||
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.vertical(top: Radius.circular(16))),
|
||||
builder: (ctx) => SafeArea(
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
padding: const EdgeInsets.only(bottom: 24),
|
||||
children: [
|
||||
Center(child: Container(width: 36, height: 4, margin: const EdgeInsets.only(top: 12, bottom: 16),
|
||||
decoration: BoxDecoration(color: colors.onSurface.withValues(alpha: 0.15), borderRadius: BorderRadius.circular(2)))),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Text('$tagName(${items.length})', style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: colors.onSurface)),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
if (items.isEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 24),
|
||||
child: Center(child: Text('暂无相关内容', style: TextStyle(fontSize: 13, color: colors.onSurface.withValues(alpha: 0.4)))),
|
||||
)
|
||||
else
|
||||
...items.asMap().entries.map((entry) {
|
||||
final item = entry.value;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (entry.key > 0) Divider(height: 0.5, color: colors.outlineVariant),
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Text(item.title, style: TextStyle(fontSize: 14, color: colors.onSurface)),
|
||||
subtitle: item.subtitle != null && item.subtitle!.isNotEmpty
|
||||
? Text(item.subtitle!, style: TextStyle(fontSize: 12, color: colors.onSurface.withValues(alpha: 0.4)))
|
||||
: null,
|
||||
trailing: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
|
||||
decoration: BoxDecoration(color: colors.surfaceContainerHighest, borderRadius: BorderRadius.circular(4)),
|
||||
child: Text(item.type, style: TextStyle(fontSize: 11, color: colors.onSurface.withValues(alpha: 0.5))),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ─── 添加标签 ──────────────────────────────────────────────────────────
|
||||
|
||||
void _showAddDialog() {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
final controller = TextEditingController();
|
||||
final type = _currentType;
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
backgroundColor: colors.surface,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
title: Text('添加${_typeLabels[_currentIndex]}',
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: colors.onSurface)),
|
||||
content: TextField(
|
||||
controller: controller, autofocus: true,
|
||||
style: TextStyle(fontSize: 15, color: colors.onSurface),
|
||||
decoration: InputDecoration(
|
||||
hintText: '输入标签名称',
|
||||
hintStyle: TextStyle(fontSize: 14, color: colors.onSurface.withValues(alpha: 0.35)),
|
||||
filled: true, fillColor: colors.surfaceContainerHigh,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: BorderSide.none),
|
||||
focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: BorderSide(color: colors.primary, width: 1)),
|
||||
),
|
||||
onSubmitted: (value) => _doAddTag(ctx, controller.text.trim(), type),
|
||||
),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(ctx), child: Text('取消', style: TextStyle(color: colors.onSurface.withValues(alpha: 0.4)))),
|
||||
Container(
|
||||
decoration: BoxDecoration(color: colors.primary, borderRadius: BorderRadius.circular(20)),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: () => _doAddTag(ctx, controller.text.trim(), type),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 8),
|
||||
child: Text('添加', style: TextStyle(fontSize: 14, color: colors.onPrimary, fontWeight: FontWeight.w500)),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _doAddTag(BuildContext ctx, String name, String type) async {
|
||||
if (name.isEmpty) return;
|
||||
try {
|
||||
final provider = context.read<AppProvider>();
|
||||
final newId = await provider.addTag(name, type);
|
||||
if (!mounted) return;
|
||||
if (ctx.mounted) {
|
||||
Navigator.pop(ctx);
|
||||
ToastUtil.show(context, '添加成功');
|
||||
}
|
||||
setState(() => _newlyAddedTagId = newId);
|
||||
Timer(const Duration(milliseconds: 1500), () {
|
||||
if (mounted) setState(() => _newlyAddedTagId = null);
|
||||
});
|
||||
await _loadTags(type);
|
||||
} catch (e) {
|
||||
if (ctx.mounted) ToastUtil.show(ctx, '添加失败:该标签已存在');
|
||||
}
|
||||
}
|
||||
|
||||
// ─── 重命名 ────────────────────────────────────────────────────────────
|
||||
|
||||
void _showRenameDialog(Map<String, dynamic> tag) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
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.surface,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
title: Text('重命名标签', style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: colors.onSurface)),
|
||||
content: TextField(
|
||||
controller: controller, autofocus: true,
|
||||
style: TextStyle(fontSize: 15, color: colors.onSurface),
|
||||
decoration: InputDecoration(
|
||||
hintText: '输入新名称',
|
||||
hintStyle: TextStyle(fontSize: 14, color: colors.onSurface.withValues(alpha: 0.35)),
|
||||
filled: true, fillColor: colors.surfaceContainerHigh,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: BorderSide.none),
|
||||
focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: BorderSide(color: colors.primary, width: 1)),
|
||||
),
|
||||
onSubmitted: (value) => _doRenameTag(ctx, tagId, value.trim(), type, oldName),
|
||||
),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(ctx), child: Text('取消', style: TextStyle(color: colors.onSurface.withValues(alpha: 0.4)))),
|
||||
Container(
|
||||
decoration: BoxDecoration(color: colors.primary, 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: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 8),
|
||||
child: Text('确定', style: TextStyle(fontSize: 14, color: colors.onPrimary, 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 = 'deleteOnly';
|
||||
String? selectedReplacement;
|
||||
bool showAdvanced = false;
|
||||
|
||||
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) {
|
||||
final bc = Theme.of(ctx).colorScheme;
|
||||
return AlertDialog(
|
||||
backgroundColor: bc.surface,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
title: Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
|
||||
decoration: BoxDecoration(color: bc.surfaceContainerHighest, borderRadius: BorderRadius.circular(12)),
|
||||
child: Text(name, style: TextStyle(fontSize: 13, fontWeight: FontWeight.w500, color: bc.onSurface.withValues(alpha: 0.6))),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Text('删除标签', style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: bc.onSurface)),
|
||||
],
|
||||
),
|
||||
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),
|
||||
// 默认选项
|
||||
_buildDeleteOption(
|
||||
value: 'deleteOnly',
|
||||
groupValue: selectedAction,
|
||||
onChanged: (v) => setDialogState(() { selectedAction = v; selectedReplacement = null; }),
|
||||
title: '仅删除标签',
|
||||
subtitle: '保留已有条目上的标签名,不影响数据',
|
||||
colors: bc,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
// 展开/收起高级选项
|
||||
GestureDetector(
|
||||
onTap: () => setDialogState(() => showAdvanced = !showAdvanced),
|
||||
child: Row(
|
||||
children: [
|
||||
Text('更多选项', style: TextStyle(fontSize: 12, fontWeight: FontWeight.w500, color: bc.primary)),
|
||||
Icon(showAdvanced ? Icons.expand_less : Icons.expand_more, size: 16, color: bc.primary),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (showAdvanced) ...[
|
||||
const SizedBox(height: 10),
|
||||
_buildDeleteOption(
|
||||
value: 'remove',
|
||||
groupValue: selectedAction,
|
||||
onChanged: (v) => setDialogState(() { selectedAction = v; selectedReplacement = null; }),
|
||||
title: '从所有条目中移除',
|
||||
subtitle: '彻底清除该标签在所有条目中的记录',
|
||||
colors: bc,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
_buildDeleteOption(
|
||||
value: 'replace',
|
||||
groupValue: selectedAction,
|
||||
onChanged: (v) => setDialogState(() { selectedAction = v; selectedReplacement = null; }),
|
||||
title: '替换为其他标签',
|
||||
subtitle: '选择一个已有标签替代',
|
||||
colors: bc,
|
||||
),
|
||||
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 = selectedReplacement == t;
|
||||
return GestureDetector(
|
||||
onTap: () => setDialogState(() => selectedReplacement = isSelected ? null : t),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 7),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected ? bc.primary : bc.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: isSelected ? bc.primary : bc.outlineVariant, width: 0.5),
|
||||
),
|
||||
child: Text(t, style: TextStyle(fontSize: 13, fontWeight: FontWeight.w500, color: isSelected ? bc.onPrimary : bc.onSurface.withValues(alpha: 0.7))),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
)
|
||||
: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 8),
|
||||
decoration: BoxDecoration(color: bc.surfaceContainerHigh, borderRadius: BorderRadius.circular(12)),
|
||||
child: Text('无其他标签可替换', style: TextStyle(fontSize: 13, color: bc.onSurface.withValues(alpha: 0.35))),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
contentPadding: const EdgeInsets.fromLTRB(24, 16, 24, 0),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(ctx), child: Text('取消', style: TextStyle(color: bc.onSurface.withValues(alpha: 0.4)))),
|
||||
Container(
|
||||
decoration: BoxDecoration(color: const Color(0xFFE53935), borderRadius: BorderRadius.circular(20)),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
if (selectedAction == 'replace' && (selectedReplacement == null || selectedReplacement!.isEmpty)) return;
|
||||
Navigator.pop(ctx, {'action': selectedAction, 'replacement': selectedReplacement});
|
||||
},
|
||||
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 action = result['action'] as String;
|
||||
final replacement = result['replacement'] as String?;
|
||||
if (!mounted) return;
|
||||
final provider = context.read<AppProvider>();
|
||||
if (action == 'deleteOnly') {
|
||||
await provider.deleteTagOnly(tagId, type);
|
||||
} else {
|
||||
await provider.deleteTag(tagId, type, replacementName: replacement);
|
||||
}
|
||||
if (!mounted) return;
|
||||
ToastUtil.show(context, '删除成功');
|
||||
await _loadTags(type);
|
||||
});
|
||||
}
|
||||
|
||||
Widget _buildDeleteOption({
|
||||
required String value,
|
||||
required String? groupValue,
|
||||
required ValueChanged<String?> onChanged,
|
||||
required String title,
|
||||
String? subtitle,
|
||||
required ColorScheme colors,
|
||||
}) {
|
||||
final selected = value == groupValue;
|
||||
return GestureDetector(
|
||||
onTap: () => onChanged(value),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: selected ? colors.surfaceContainerHigh : colors.surface,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: selected ? colors.primary : colors.outlineVariant, width: selected ? 1 : 0.5),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 18, height: 18,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(color: selected ? colors.primary : colors.onSurface.withValues(alpha: 0.25), width: selected ? 5 : 1.5),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [
|
||||
Text(title, style: TextStyle(fontSize: 14, fontWeight: selected ? FontWeight.w500 : FontWeight.normal, color: selected ? colors.onSurface : colors.onSurface.withValues(alpha: 0.6))),
|
||||
if (subtitle != null) Padding(padding: const EdgeInsets.only(top: 2), child: Text(subtitle, style: TextStyle(fontSize: 11, color: colors.onSurface.withValues(alpha: 0.35)))),
|
||||
]),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ─── 新标签高亮动画 Widget ─────────────────────────────────────────────────
|
||||
|
||||
class _NewTagHighlight extends StatefulWidget {
|
||||
final Widget child;
|
||||
const _NewTagHighlight({required this.child});
|
||||
|
||||
@override
|
||||
State<_NewTagHighlight> createState() => _NewTagHighlightState();
|
||||
}
|
||||
|
||||
class _NewTagHighlightState extends State<_NewTagHighlight> with SingleTickerProviderStateMixin {
|
||||
late AnimationController _controller;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = AnimationController(vsync: this, duration: const Duration(milliseconds: 1500));
|
||||
_controller.forward();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
return AnimatedBuilder(
|
||||
animation: _controller,
|
||||
builder: (context, child) {
|
||||
final opacity = _controller.value < 0.3
|
||||
? (_controller.value / 0.3).clamp(0.0, 1.0)
|
||||
: (1.0 - (_controller.value - 0.3) / 0.7).clamp(0.0, 1.0);
|
||||
final scale = 1.0 + 0.06 * (1.0 - _controller.value);
|
||||
return Transform.scale(
|
||||
scale: scale,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
color: colors.primary.withValues(alpha: 0.12 * opacity),
|
||||
border: Border.all(color: colors.primary.withValues(alpha: 0.3 * opacity), width: 1),
|
||||
),
|
||||
child: widget.child,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user