generated from dellevin/template
优化标签页,侧边栏,我的界面
This commit is contained in:
@@ -28,8 +28,8 @@ class _HomePageState extends State<HomePage> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
drawer: context.watch<AppProvider>().bottomNavIndex == 0
|
drawer: context.watch<AppProvider>().bottomNavIndex != 1
|
||||||
? CustomDrawer()
|
? const CustomDrawer()
|
||||||
: null,
|
: null,
|
||||||
|
|
||||||
body: Consumer<AppProvider>(
|
body: Consumer<AppProvider>(
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -16,6 +16,7 @@ class _TagManagementPageState extends State<TagManagementPage> {
|
|||||||
|
|
||||||
static const _tabTypes = ['movie_genre', 'book_genre', 'note_tag'];
|
static const _tabTypes = ['movie_genre', 'book_genre', 'note_tag'];
|
||||||
static const _typeLabels = ['影视类型', '书籍类型', '笔记标签'];
|
static const _typeLabels = ['影视类型', '书籍类型', '笔记标签'];
|
||||||
|
static const _typeIcons = [Icons.movie_outlined, Icons.menu_book_outlined, Icons.note_outlined];
|
||||||
|
|
||||||
final Map<String, List<Map<String, dynamic>>> _tagCache = {};
|
final Map<String, List<Map<String, dynamic>>> _tagCache = {};
|
||||||
|
|
||||||
@@ -28,9 +29,7 @@ class _TagManagementPageState extends State<TagManagementPage> {
|
|||||||
Future<void> _loadTags(String type) async {
|
Future<void> _loadTags(String type) async {
|
||||||
final provider = context.read<AppProvider>();
|
final provider = context.read<AppProvider>();
|
||||||
final tags = await provider.getTags(type);
|
final tags = await provider.getTags(type);
|
||||||
if (mounted) {
|
if (mounted) setState(() => _tagCache[type] = tags);
|
||||||
setState(() => _tagCache[type] = tags);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _syncTags() async {
|
Future<void> _syncTags() async {
|
||||||
@@ -49,24 +48,49 @@ class _TagManagementPageState extends State<TagManagementPage> {
|
|||||||
|
|
||||||
String get _currentType => _tabTypes[_currentIndex];
|
String get _currentType => _tabTypes[_currentIndex];
|
||||||
|
|
||||||
|
/// 计算标签使用次数
|
||||||
|
Map<String, int> _getTagUsageCounts(String type) {
|
||||||
|
final provider = context.read<AppProvider>();
|
||||||
|
final counts = <String, int>{};
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case 'movie_genre':
|
||||||
|
for (final m in provider.movies.where((m) => !m.isDeleted)) {
|
||||||
|
for (final g in m.genres) {
|
||||||
|
counts[g] = (counts[g] ?? 0) + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'book_genre':
|
||||||
|
for (final b in provider.books) {
|
||||||
|
for (final g in b.genres) {
|
||||||
|
counts[g] = (counts[g] ?? 0) + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'note_tag':
|
||||||
|
for (final n in provider.notes.where((n) => !n.isDeleted)) {
|
||||||
|
for (final t in n.tags) {
|
||||||
|
counts[t] = (counts[t] ?? 0) + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return counts;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: const Color(0xFFF8F8F8),
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Text('标签管理'),
|
title: const Text('标签管理'),
|
||||||
actions: [
|
actions: [
|
||||||
_isSyncing
|
_isSyncing
|
||||||
? const Padding(
|
? const Padding(
|
||||||
padding: EdgeInsets.all(16),
|
padding: EdgeInsets.all(16),
|
||||||
child: SizedBox(
|
child: SizedBox(width: 20, height: 20,
|
||||||
width: 20,
|
child: CircularProgressIndicator(strokeWidth: 2, color: Color(0xFF1A1A1A))),
|
||||||
height: 20,
|
|
||||||
child: CircularProgressIndicator(
|
|
||||||
strokeWidth: 2,
|
|
||||||
color: Color(0xFF1A1A1A),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
: IconButton(
|
: IconButton(
|
||||||
icon: const Icon(Icons.sync, size: 20),
|
icon: const Icon(Icons.sync, size: 20),
|
||||||
@@ -77,12 +101,10 @@ class _TagManagementPageState extends State<TagManagementPage> {
|
|||||||
),
|
),
|
||||||
body: Column(
|
body: Column(
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 12),
|
||||||
_buildTabSelector(),
|
_buildTabSelector(),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 16),
|
||||||
Expanded(
|
Expanded(child: _buildTagList(_currentType)),
|
||||||
child: _buildTagList(_currentType),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
floatingActionButton: GestureDetector(
|
floatingActionButton: GestureDetector(
|
||||||
@@ -93,11 +115,7 @@ class _TagManagementPageState extends State<TagManagementPage> {
|
|||||||
color: const Color(0xFF1A1A1A),
|
color: const Color(0xFF1A1A1A),
|
||||||
borderRadius: BorderRadius.circular(24),
|
borderRadius: BorderRadius.circular(24),
|
||||||
boxShadow: [
|
boxShadow: [
|
||||||
BoxShadow(
|
BoxShadow(color: Colors.black.withValues(alpha: 0.12), blurRadius: 12, offset: const Offset(0, 4)),
|
||||||
color: Colors.black.withValues(alpha: 0.12),
|
|
||||||
blurRadius: 12,
|
|
||||||
offset: const Offset(0, 4),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
@@ -105,14 +123,8 @@ class _TagManagementPageState extends State<TagManagementPage> {
|
|||||||
children: [
|
children: [
|
||||||
const Icon(Icons.add, size: 18, color: Colors.white),
|
const Icon(Icons.add, size: 18, color: Colors.white),
|
||||||
const SizedBox(width: 6),
|
const SizedBox(width: 6),
|
||||||
Text(
|
Text('添加${_typeLabels[_currentIndex]}',
|
||||||
'添加${_typeLabels[_currentIndex]}',
|
style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500, color: Colors.white)),
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
color: Colors.white,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -120,13 +132,14 @@ class _TagManagementPageState extends State<TagManagementPage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 胶囊式 Tab 选择器(水滴滑动动画)
|
// ─── Tab 选择器 ──────────────────────────────────────────────────────
|
||||||
|
|
||||||
Widget _buildTabSelector() {
|
Widget _buildTabSelector() {
|
||||||
return Container(
|
return Container(
|
||||||
margin: const EdgeInsets.symmetric(horizontal: 24),
|
margin: const EdgeInsets.symmetric(horizontal: 24),
|
||||||
padding: const EdgeInsets.all(4),
|
padding: const EdgeInsets.all(4),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: const Color(0xFFF0F0F0),
|
color: const Color(0xFFEBEBEB),
|
||||||
borderRadius: BorderRadius.circular(24),
|
borderRadius: BorderRadius.circular(24),
|
||||||
),
|
),
|
||||||
child: LayoutBuilder(
|
child: LayoutBuilder(
|
||||||
@@ -136,14 +149,11 @@ class _TagManagementPageState extends State<TagManagementPage> {
|
|||||||
height: 42,
|
height: 42,
|
||||||
child: Stack(
|
child: Stack(
|
||||||
children: [
|
children: [
|
||||||
// 水滴指示器
|
|
||||||
AnimatedPositioned(
|
AnimatedPositioned(
|
||||||
duration: const Duration(milliseconds: 450),
|
duration: const Duration(milliseconds: 600),
|
||||||
curve: Curves.elasticOut,
|
curve: Curves.elasticOut,
|
||||||
left: _currentIndex * tabWidth,
|
left: _currentIndex * tabWidth,
|
||||||
top: 0,
|
top: 0, bottom: 0, width: tabWidth,
|
||||||
bottom: 0,
|
|
||||||
width: tabWidth,
|
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(3),
|
padding: const EdgeInsets.all(3),
|
||||||
child: Container(
|
child: Container(
|
||||||
@@ -151,43 +161,29 @@ class _TagManagementPageState extends State<TagManagementPage> {
|
|||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
borderRadius: BorderRadius.circular(22),
|
borderRadius: BorderRadius.circular(22),
|
||||||
boxShadow: [
|
boxShadow: [
|
||||||
BoxShadow(
|
BoxShadow(color: Colors.black.withValues(alpha: 0.08), blurRadius: 8, offset: const Offset(0, 2)),
|
||||||
color: Colors.black.withValues(alpha: 0.08),
|
BoxShadow(color: Colors.black.withValues(alpha: 0.04), blurRadius: 2, offset: const Offset(0, 1)),
|
||||||
blurRadius: 8,
|
|
||||||
offset: const Offset(0, 2),
|
|
||||||
),
|
|
||||||
BoxShadow(
|
|
||||||
color: Colors.black.withValues(alpha: 0.04),
|
|
||||||
blurRadius: 2,
|
|
||||||
offset: const Offset(0, 1),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
// 标签文字
|
|
||||||
Row(
|
Row(
|
||||||
children: List.generate(3, (i) {
|
children: List.generate(3, (i) {
|
||||||
final selected = _currentIndex == i;
|
final selected = _currentIndex == i;
|
||||||
return Expanded(
|
return Expanded(
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
|
behavior: HitTestBehavior.opaque,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
setState(() => _currentIndex = i);
|
setState(() => _currentIndex = i);
|
||||||
_loadTags(_tabTypes[i]);
|
_loadTags(_tabTypes[i]);
|
||||||
},
|
},
|
||||||
child: Center(
|
child: Container(
|
||||||
child: Text(
|
height: double.infinity,
|
||||||
_typeLabels[i],
|
alignment: Alignment.center,
|
||||||
style: TextStyle(
|
child: Text(_typeLabels[i],
|
||||||
fontSize: 14,
|
style: TextStyle(fontSize: 13, fontWeight: selected ? FontWeight.w600 : FontWeight.w500,
|
||||||
fontWeight:
|
color: selected ? const Color(0xFF1A1A1A) : const Color(0xFF999999))),
|
||||||
selected ? FontWeight.w600 : FontWeight.w500,
|
|
||||||
color: selected
|
|
||||||
? const Color(0xFF1A1A1A)
|
|
||||||
: const Color(0xFF999999),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -201,88 +197,126 @@ class _TagManagementPageState extends State<TagManagementPage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ─── 标签列表 ────────────────────────────────────────────────────────
|
||||||
|
|
||||||
Widget _buildTagList(String type) {
|
Widget _buildTagList(String type) {
|
||||||
final tags = _tagCache[type] ?? [];
|
final tags = _tagCache[type] ?? [];
|
||||||
|
final usageCounts = _getTagUsageCounts(type);
|
||||||
|
|
||||||
if (tags.isEmpty) {
|
if (tags.isEmpty) {
|
||||||
|
return _buildEmptyState(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 按使用次数降序排序
|
||||||
|
final sorted = List<Map<String, dynamic>>.from(tags)
|
||||||
|
..sort((a, b) {
|
||||||
|
final ca = usageCounts[a['name']] ?? 0;
|
||||||
|
final cb = usageCounts[b['name']] ?? 0;
|
||||||
|
return cb.compareTo(ca);
|
||||||
|
});
|
||||||
|
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
// 统计行
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: 12),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Text('共 ${tags.length} 个标签', style: const TextStyle(fontSize: 12, color: Color(0xFFBBBBBB))),
|
||||||
|
const Spacer(),
|
||||||
|
Text('已使用 ${usageCounts.length} 个', style: const TextStyle(fontSize: 12, color: Color(0xFFD0D0D0))),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
// 标签列表
|
||||||
|
Expanded(
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
padding: const EdgeInsets.only(bottom: 80),
|
||||||
|
child: Wrap(
|
||||||
|
spacing: 10,
|
||||||
|
runSpacing: 10,
|
||||||
|
children: sorted.map((tag) => _buildTagChip(tag, usageCounts)).toList(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildTagChip(Map<String, dynamic> tag, Map<String, int> usageCounts) {
|
||||||
|
final name = tag['name'] as String;
|
||||||
|
final count = usageCounts[name] ?? 0;
|
||||||
|
|
||||||
|
return Container(
|
||||||
|
padding: const EdgeInsets.only(left: 14, right: 6, top: 8, bottom: 8),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.white,
|
||||||
|
borderRadius: BorderRadius.circular(20),
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(color: Colors.black.withValues(alpha: 0.03), blurRadius: 4, offset: const Offset(0, 2)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
// 标签名区域 — 点击改名
|
||||||
|
GestureDetector(
|
||||||
|
onTap: () => _showRenameDialog(tag),
|
||||||
|
child: Text(name, style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500, color: Color(0xFF1A1A1A))),
|
||||||
|
),
|
||||||
|
if (count > 0) ...[
|
||||||
|
const SizedBox(width: 6),
|
||||||
|
Container(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||||
|
decoration: BoxDecoration(color: const Color(0xFFF0F0F0), borderRadius: BorderRadius.circular(8)),
|
||||||
|
child: Text('$count', style: const TextStyle(fontSize: 10, fontWeight: FontWeight.w600, color: Color(0xFF999999))),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
const SizedBox(width: 4),
|
||||||
|
// X 按钮 — 点击删除
|
||||||
|
GestureDetector(
|
||||||
|
onTap: () => _showDeleteDialog(tag),
|
||||||
|
child: Container(
|
||||||
|
width: 22, height: 22,
|
||||||
|
decoration: BoxDecoration(color: const Color(0xFFF0F0F0), borderRadius: BorderRadius.circular(11)),
|
||||||
|
child: const Icon(Icons.close, size: 12, color: Color(0xFF999999)),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildEmptyState(String type) {
|
||||||
|
final idx = _tabTypes.indexOf(type);
|
||||||
|
final icon = _typeIcons[idx];
|
||||||
|
final label = _typeLabels[idx];
|
||||||
|
final hints = ['同步或手动添加影视类型', '同步或手动添加书籍类型', '同步或手动添加笔记标签'];
|
||||||
|
|
||||||
return Center(
|
return Center(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Container(
|
Container(
|
||||||
width: 56,
|
width: 64, height: 64,
|
||||||
height: 56,
|
decoration: BoxDecoration(color: const Color(0xFFECECEC), borderRadius: BorderRadius.circular(18)),
|
||||||
decoration: BoxDecoration(
|
child: Icon(icon, size: 28, color: const Color(0xFFCCCCCC)),
|
||||||
color: const Color(0xFFF5F5F5),
|
|
||||||
borderRadius: BorderRadius.circular(16),
|
|
||||||
),
|
|
||||||
child: const Icon(Icons.label_outline,
|
|
||||||
size: 24, color: Color(0xFFCCCCCC)),
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
const Text('暂无标签',
|
Text('暂无$label',
|
||||||
style: TextStyle(
|
style: const TextStyle(fontSize: 14, color: Color(0xFFBBBBBB), fontWeight: FontWeight.w500)),
|
||||||
fontSize: 14,
|
|
||||||
color: Color(0xFFBBBBBB),
|
|
||||||
fontWeight: FontWeight.w500)),
|
|
||||||
const SizedBox(height: 6),
|
const SizedBox(height: 6),
|
||||||
const Text('点击下方按钮添加',
|
Text(hints[idx], style: const TextStyle(fontSize: 12, color: Color(0xFFD5D5D5))),
|
||||||
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() {
|
void _showAddDialog() {
|
||||||
final controller = TextEditingController();
|
final controller = TextEditingController();
|
||||||
@@ -293,63 +327,33 @@ class _TagManagementPageState extends State<TagManagementPage> {
|
|||||||
builder: (ctx) => AlertDialog(
|
builder: (ctx) => AlertDialog(
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||||
title: Text(
|
title: Text('添加${_typeLabels[_currentIndex]}',
|
||||||
'添加${_typeLabels[_currentIndex]}',
|
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A))),
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 18,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
color: Color(0xFF1A1A1A)),
|
|
||||||
),
|
|
||||||
content: TextField(
|
content: TextField(
|
||||||
controller: controller,
|
controller: controller, autofocus: true,
|
||||||
autofocus: true,
|
|
||||||
style: const TextStyle(fontSize: 15, color: Color(0xFF1A1A1A)),
|
style: const TextStyle(fontSize: 15, color: Color(0xFF1A1A1A)),
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
hintText: '输入标签名称',
|
hintText: '输入标签名称',
|
||||||
hintStyle:
|
hintStyle: const TextStyle(fontSize: 14, color: Color(0xFFAAAAAA)),
|
||||||
const TextStyle(fontSize: 14, color: Color(0xFFAAAAAA)),
|
filled: true, fillColor: const Color(0xFFFAFAFA),
|
||||||
filled: true,
|
contentPadding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
|
||||||
fillColor: const Color(0xFFFAFAFA),
|
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: BorderSide.none),
|
||||||
contentPadding:
|
focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: const BorderSide(color: Color(0xFF1A1A1A), width: 1)),
|
||||||
const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
|
|
||||||
border: OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
borderSide: BorderSide.none,
|
|
||||||
),
|
),
|
||||||
focusedBorder: OutlineInputBorder(
|
onSubmitted: (value) => _doAddTag(ctx, controller.text.trim(), type),
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
borderSide:
|
|
||||||
const BorderSide(color: Color(0xFF1A1A1A), width: 1),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onSubmitted: (value) =>
|
|
||||||
_doAddTag(ctx, controller.text.trim(), type),
|
|
||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(onPressed: () => Navigator.pop(ctx), child: const Text('取消', style: TextStyle(color: Color(0xFF999999)))),
|
||||||
onPressed: () => Navigator.pop(ctx),
|
|
||||||
child: const Text('取消',
|
|
||||||
style: TextStyle(color: Color(0xFF999999))),
|
|
||||||
),
|
|
||||||
Container(
|
Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(color: const Color(0xFF1A1A1A), borderRadius: BorderRadius.circular(20)),
|
||||||
color: const Color(0xFF1A1A1A),
|
|
||||||
borderRadius: BorderRadius.circular(20),
|
|
||||||
),
|
|
||||||
child: Material(
|
child: Material(
|
||||||
color: Colors.transparent,
|
color: Colors.transparent,
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () =>
|
onTap: () => _doAddTag(ctx, controller.text.trim(), type),
|
||||||
_doAddTag(ctx, controller.text.trim(), type),
|
|
||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(20),
|
||||||
child: const Padding(
|
child: const Padding(
|
||||||
padding:
|
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 8),
|
||||||
EdgeInsets.symmetric(horizontal: 20, vertical: 8),
|
child: Text('添加', style: TextStyle(fontSize: 14, color: Colors.white, fontWeight: FontWeight.w500)),
|
||||||
child: Text('添加',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
color: Colors.white,
|
|
||||||
fontWeight: FontWeight.w500)),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -359,15 +363,12 @@ class _TagManagementPageState extends State<TagManagementPage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _doAddTag(
|
Future<void> _doAddTag(BuildContext ctx, String name, String type) async {
|
||||||
BuildContext ctx, String name, String type) async {
|
|
||||||
if (name.isEmpty) return;
|
if (name.isEmpty) return;
|
||||||
try {
|
try {
|
||||||
await context.read<AppProvider>().addTag(name, type);
|
await context.read<AppProvider>().addTag(name, type);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (ctx.mounted) {
|
if (ctx.mounted) ToastUtil.show(ctx, '添加失败:该标签已存在');
|
||||||
ToastUtil.show(ctx, '添加失败:该标签已存在');
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (ctx.mounted) {
|
if (ctx.mounted) {
|
||||||
@@ -377,6 +378,8 @@ class _TagManagementPageState extends State<TagManagementPage> {
|
|||||||
await _loadTags(type);
|
await _loadTags(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ─── 重命名 ──────────────────────────────────────────────────────────
|
||||||
|
|
||||||
void _showRenameDialog(Map<String, dynamic> tag) {
|
void _showRenameDialog(Map<String, dynamic> tag) {
|
||||||
final controller = TextEditingController(text: tag['name'] as String);
|
final controller = TextEditingController(text: tag['name'] as String);
|
||||||
final tagId = tag['id'] as String;
|
final tagId = tag['id'] as String;
|
||||||
@@ -388,63 +391,32 @@ class _TagManagementPageState extends State<TagManagementPage> {
|
|||||||
builder: (ctx) => AlertDialog(
|
builder: (ctx) => AlertDialog(
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||||
title: const Text(
|
title: const Text('重命名标签', style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A))),
|
||||||
'重命名标签',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 18,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
color: Color(0xFF1A1A1A)),
|
|
||||||
),
|
|
||||||
content: TextField(
|
content: TextField(
|
||||||
controller: controller,
|
controller: controller, autofocus: true,
|
||||||
autofocus: true,
|
|
||||||
style: const TextStyle(fontSize: 15, color: Color(0xFF1A1A1A)),
|
style: const TextStyle(fontSize: 15, color: Color(0xFF1A1A1A)),
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
hintText: '输入新名称',
|
hintText: '输入新名称',
|
||||||
hintStyle:
|
hintStyle: const TextStyle(fontSize: 14, color: Color(0xFFAAAAAA)),
|
||||||
const TextStyle(fontSize: 14, color: Color(0xFFAAAAAA)),
|
filled: true, fillColor: const Color(0xFFFAFAFA),
|
||||||
filled: true,
|
contentPadding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
|
||||||
fillColor: const Color(0xFFFAFAFA),
|
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: BorderSide.none),
|
||||||
contentPadding:
|
focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: const BorderSide(color: Color(0xFF1A1A1A), width: 1)),
|
||||||
const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
|
|
||||||
border: OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
borderSide: BorderSide.none,
|
|
||||||
),
|
),
|
||||||
focusedBorder: OutlineInputBorder(
|
onSubmitted: (value) => _doRenameTag(ctx, tagId, value.trim(), type, oldName),
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
borderSide:
|
|
||||||
const BorderSide(color: Color(0xFF1A1A1A), width: 1),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onSubmitted: (value) =>
|
|
||||||
_doRenameTag(ctx, tagId, value.trim(), type, oldName),
|
|
||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(onPressed: () => Navigator.pop(ctx), child: const Text('取消', style: TextStyle(color: Color(0xFF999999)))),
|
||||||
onPressed: () => Navigator.pop(ctx),
|
|
||||||
child: const Text('取消',
|
|
||||||
style: TextStyle(color: Color(0xFF999999))),
|
|
||||||
),
|
|
||||||
Container(
|
Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(color: const Color(0xFF1A1A1A), borderRadius: BorderRadius.circular(20)),
|
||||||
color: const Color(0xFF1A1A1A),
|
|
||||||
borderRadius: BorderRadius.circular(20),
|
|
||||||
),
|
|
||||||
child: Material(
|
child: Material(
|
||||||
color: Colors.transparent,
|
color: Colors.transparent,
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () =>
|
onTap: () => _doRenameTag(ctx, tagId, controller.text.trim(), type, oldName),
|
||||||
_doRenameTag(ctx, tagId, controller.text.trim(), type, oldName),
|
|
||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(20),
|
||||||
child: const Padding(
|
child: const Padding(
|
||||||
padding:
|
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 8),
|
||||||
EdgeInsets.symmetric(horizontal: 20, vertical: 8),
|
child: Text('确定', style: TextStyle(fontSize: 14, color: Colors.white, fontWeight: FontWeight.w500)),
|
||||||
child: Text('确定',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
color: Colors.white,
|
|
||||||
fontWeight: FontWeight.w500)),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -454,22 +426,21 @@ class _TagManagementPageState extends State<TagManagementPage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _doRenameTag(BuildContext ctx, String tagId, String newName,
|
Future<void> _doRenameTag(BuildContext ctx, String tagId, String newName, String type, String oldName) async {
|
||||||
String type, String oldName) async {
|
|
||||||
if (newName.isEmpty || newName == oldName) {
|
if (newName.isEmpty || newName == oldName) {
|
||||||
if (ctx.mounted) Navigator.pop(ctx);
|
if (ctx.mounted) Navigator.pop(ctx);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final success =
|
final success = await context.read<AppProvider>().renameTag(tagId, newName, type);
|
||||||
await context.read<AppProvider>().renameTag(tagId, newName, type);
|
|
||||||
if (ctx.mounted) {
|
if (ctx.mounted) {
|
||||||
Navigator.pop(ctx);
|
Navigator.pop(ctx);
|
||||||
ToastUtil.show(
|
ToastUtil.show(context, success ? '重命名成功' : '重命名失败:标签名已存在');
|
||||||
context, success ? '重命名成功' : '重命名失败:标签名已存在');
|
|
||||||
}
|
}
|
||||||
if (success) await _loadTags(type);
|
if (success) await _loadTags(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ─── 删除(长按触发)──────────────────────────────────────────────────
|
||||||
|
|
||||||
void _showDeleteDialog(Map<String, dynamic> tag) {
|
void _showDeleteDialog(Map<String, dynamic> tag) {
|
||||||
final tagId = tag['id'] as String;
|
final tagId = tag['id'] as String;
|
||||||
final type = tag['type'] as String;
|
final type = tag['type'] as String;
|
||||||
@@ -487,131 +458,65 @@ class _TagManagementPageState extends State<TagManagementPage> {
|
|||||||
builder: (ctx) => StatefulBuilder(
|
builder: (ctx) => StatefulBuilder(
|
||||||
builder: (ctx, setDialogState) => AlertDialog(
|
builder: (ctx, setDialogState) => AlertDialog(
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
shape:
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||||
RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
|
||||||
title: Row(
|
title: Row(
|
||||||
children: [
|
children: [
|
||||||
Container(
|
Container(
|
||||||
padding:
|
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
|
||||||
const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
|
decoration: BoxDecoration(color: const Color(0xFFF5F5F5), borderRadius: BorderRadius.circular(12)),
|
||||||
decoration: BoxDecoration(
|
child: Text(name, style: const TextStyle(fontSize: 13, fontWeight: FontWeight.w500, color: Color(0xFF666666))),
|
||||||
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 SizedBox(width: 10),
|
||||||
const Text(
|
const Text('删除标签', style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A))),
|
||||||
'删除标签',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 18,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
color: Color(0xFF1A1A1A)),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
titlePadding: const EdgeInsets.fromLTRB(24, 24, 24, 0),
|
titlePadding: const EdgeInsets.fromLTRB(24, 24, 24, 0),
|
||||||
content: SizedBox(
|
content: SizedBox(
|
||||||
width: double.maxFinite,
|
width: double.maxFinite,
|
||||||
child: ConstrainedBox(
|
child: ConstrainedBox(
|
||||||
constraints: BoxConstraints(
|
constraints: BoxConstraints(maxHeight: MediaQuery.of(ctx).size.height * 0.45),
|
||||||
maxHeight: MediaQuery.of(ctx).size.height * 0.45,
|
|
||||||
),
|
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(height: 4),
|
const SizedBox(height: 4),
|
||||||
const Text(
|
const Text('删除后对已有条目的影响:', style: TextStyle(fontSize: 13, color: Color(0xFF999999))),
|
||||||
'删除后对已有条目的影响:',
|
|
||||||
style: TextStyle(fontSize: 13, color: Color(0xFF999999)),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
_buildDeleteOption(
|
_buildDeleteOption(value: 'remove', groupValue: selectedAction, onChanged: (v) => setDialogState(() => selectedAction = v), title: '从所有条目中移除该标签', subtitle: '标签将从影视/书籍/笔记中清除'),
|
||||||
value: 'remove',
|
|
||||||
groupValue: selectedAction,
|
|
||||||
onChanged: (v) => setDialogState(() => selectedAction = v),
|
|
||||||
title: '从所有条目中移除该标签',
|
|
||||||
subtitle: '标签将从影视/书籍/笔记中清除',
|
|
||||||
),
|
|
||||||
const SizedBox(height: 4),
|
const SizedBox(height: 4),
|
||||||
_buildDeleteOption(
|
_buildDeleteOption(value: 'deleteOnly', groupValue: selectedAction, onChanged: (v) => setDialogState(() => selectedAction = v), title: '仅删除标签', subtitle: '保留已有条目上的标签名'),
|
||||||
value: 'deleteOnly',
|
|
||||||
groupValue: selectedAction,
|
|
||||||
onChanged: (v) => setDialogState(() => selectedAction = v),
|
|
||||||
title: '仅删除标签',
|
|
||||||
subtitle: '保留已有条目上的标签名',
|
|
||||||
),
|
|
||||||
const SizedBox(height: 4),
|
const SizedBox(height: 4),
|
||||||
_buildDeleteOption(
|
_buildDeleteOption(value: 'replace', groupValue: selectedAction, onChanged: (v) => setDialogState(() => selectedAction = v), title: '替换为其他标签'),
|
||||||
value: 'replace',
|
|
||||||
groupValue: selectedAction,
|
|
||||||
onChanged: (v) => setDialogState(() => selectedAction = v),
|
|
||||||
title: '替换为其他标签',
|
|
||||||
),
|
|
||||||
if (selectedAction == 'replace')
|
if (selectedAction == 'replace')
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(left: 40, top: 10),
|
padding: const EdgeInsets.only(left: 40, top: 10),
|
||||||
child: otherTags.isNotEmpty
|
child: otherTags.isNotEmpty
|
||||||
? Wrap(
|
? Wrap(
|
||||||
spacing: 8,
|
spacing: 8, runSpacing: 8,
|
||||||
runSpacing: 8,
|
|
||||||
children: otherTags.map((t) {
|
children: otherTags.map((t) {
|
||||||
final isSelected =
|
final isSelected = replacementController.text == t;
|
||||||
replacementController.text == t;
|
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
replacementController.text =
|
replacementController.text = isSelected ? '' : t;
|
||||||
isSelected ? '' : t;
|
|
||||||
setDialogState(() {});
|
setDialogState(() {});
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
padding: const EdgeInsets.symmetric(
|
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 7),
|
||||||
horizontal: 14, vertical: 7),
|
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: isSelected
|
color: isSelected ? const Color(0xFF1A1A1A) : const Color(0xFFF5F5F5),
|
||||||
? const Color(0xFF1A1A1A)
|
|
||||||
: const Color(0xFFF5F5F5),
|
|
||||||
borderRadius: BorderRadius.circular(16),
|
borderRadius: BorderRadius.circular(16),
|
||||||
border: Border.all(
|
border: Border.all(color: isSelected ? const Color(0xFF1A1A1A) : const Color(0xFFE8E8E8), width: 0.5),
|
||||||
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),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
|
child: Text(t, style: TextStyle(fontSize: 13, fontWeight: FontWeight.w500, color: isSelected ? Colors.white : const Color(0xFF555555))),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}).toList(),
|
}).toList(),
|
||||||
)
|
)
|
||||||
: Container(
|
: Container(
|
||||||
padding: const EdgeInsets.symmetric(
|
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 8),
|
||||||
horizontal: 14, vertical: 8),
|
decoration: BoxDecoration(color: const Color(0xFFFAFAFA), borderRadius: BorderRadius.circular(12)),
|
||||||
decoration: BoxDecoration(
|
child: const Text('无其他标签可替换', style: TextStyle(fontSize: 13, color: Color(0xFFAAAAAA))),
|
||||||
color: const Color(0xFFFAFAFA),
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
),
|
|
||||||
child: const Text('无其他标签可替换',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 13,
|
|
||||||
color: Color(0xFFAAAAAA))),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -621,42 +526,24 @@ class _TagManagementPageState extends State<TagManagementPage> {
|
|||||||
),
|
),
|
||||||
contentPadding: const EdgeInsets.fromLTRB(24, 16, 24, 0),
|
contentPadding: const EdgeInsets.fromLTRB(24, 16, 24, 0),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(onPressed: () => Navigator.pop(ctx), child: const Text('取消', style: TextStyle(color: Color(0xFF999999)))),
|
||||||
onPressed: () => Navigator.pop(ctx),
|
|
||||||
child: const Text('取消',
|
|
||||||
style: TextStyle(color: Color(0xFF999999))),
|
|
||||||
),
|
|
||||||
Container(
|
Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(color: const Color(0xFFE53935), borderRadius: BorderRadius.circular(20)),
|
||||||
color: const Color(0xFFE53935),
|
|
||||||
borderRadius: BorderRadius.circular(20),
|
|
||||||
),
|
|
||||||
child: Material(
|
child: Material(
|
||||||
color: Colors.transparent,
|
color: Colors.transparent,
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
String? replacement;
|
String? replacement;
|
||||||
if (selectedAction == 'replace') {
|
if (selectedAction == 'replace') {
|
||||||
replacement =
|
replacement = replacementController.text.trim().isNotEmpty ? replacementController.text.trim() : null;
|
||||||
replacementController.text.trim().isNotEmpty
|
|
||||||
? replacementController.text.trim()
|
|
||||||
: null;
|
|
||||||
if (replacement == null) return;
|
if (replacement == null) return;
|
||||||
}
|
}
|
||||||
Navigator.pop(ctx, {
|
Navigator.pop(ctx, {'action': selectedAction, 'replacement': replacement});
|
||||||
'action': selectedAction,
|
|
||||||
'replacement': replacement,
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(20),
|
||||||
child: const Padding(
|
child: const Padding(
|
||||||
padding:
|
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 8),
|
||||||
EdgeInsets.symmetric(horizontal: 20, vertical: 8),
|
child: Text('删除', style: TextStyle(fontSize: 14, color: Colors.white, fontWeight: FontWeight.w500)),
|
||||||
child: Text('删除',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
color: Colors.white,
|
|
||||||
fontWeight: FontWeight.w500)),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -669,19 +556,12 @@ class _TagManagementPageState extends State<TagManagementPage> {
|
|||||||
if (result == null) return;
|
if (result == null) return;
|
||||||
final action = result['action'] as String;
|
final action = result['action'] as String;
|
||||||
final replacement = result['replacement'] as String?;
|
final replacement = result['replacement'] as String?;
|
||||||
|
|
||||||
if (action == 'deleteOnly') {
|
if (action == 'deleteOnly') {
|
||||||
await context
|
await context.read<AppProvider>().deleteTagOnly(tagId, type);
|
||||||
.read<AppProvider>()
|
|
||||||
.deleteTagOnly(tagId, type);
|
|
||||||
} else {
|
} else {
|
||||||
await context
|
await context.read<AppProvider>().deleteTag(tagId, type, replacementName: replacement);
|
||||||
.read<AppProvider>()
|
|
||||||
.deleteTag(tagId, type, replacementName: replacement);
|
|
||||||
}
|
|
||||||
if (mounted) {
|
|
||||||
ToastUtil.show(context, '删除成功');
|
|
||||||
}
|
}
|
||||||
|
if (mounted) ToastUtil.show(context, '删除成功');
|
||||||
await _loadTags(type);
|
await _loadTags(type);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -701,54 +581,23 @@ class _TagManagementPageState extends State<TagManagementPage> {
|
|||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: selected ? const Color(0xFFFAFAFA) : Colors.white,
|
color: selected ? const Color(0xFFFAFAFA) : Colors.white,
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
border: Border.all(
|
border: Border.all(color: selected ? const Color(0xFF1A1A1A) : const Color(0xFFEEEEEE), width: selected ? 1 : 0.5),
|
||||||
color: selected ? const Color(0xFF1A1A1A) : const Color(0xFFEEEEEE),
|
|
||||||
width: selected ? 1 : 0.5,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Container(
|
Container(
|
||||||
width: 18,
|
width: 18, height: 18,
|
||||||
height: 18,
|
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
shape: BoxShape.circle,
|
shape: BoxShape.circle,
|
||||||
border: Border.all(
|
border: Border.all(color: selected ? const Color(0xFF1A1A1A) : const Color(0xFFCCCCCC), width: selected ? 5 : 1.5),
|
||||||
color: selected
|
|
||||||
? const Color(0xFF1A1A1A)
|
|
||||||
: const Color(0xFFCCCCCC),
|
|
||||||
width: selected ? 5 : 1.5,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 12),
|
const SizedBox(width: 12),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Column(
|
child: Column(crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
Text(title, style: TextStyle(fontSize: 14, fontWeight: selected ? FontWeight.w500 : FontWeight.normal, color: selected ? const Color(0xFF1A1A1A) : const Color(0xFF666666))),
|
||||||
mainAxisSize: MainAxisSize.min,
|
if (subtitle != null) Padding(padding: const EdgeInsets.only(top: 2), child: Text(subtitle, style: const TextStyle(fontSize: 11, color: Color(0xFFAAAAAA)))),
|
||||||
children: [
|
]),
|
||||||
Text(
|
|
||||||
title,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
fontWeight: selected ? FontWeight.w500 : FontWeight.normal,
|
|
||||||
color:
|
|
||||||
selected ? const Color(0xFF1A1A1A) : const Color(0xFF666666),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (subtitle != null)
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(top: 2),
|
|
||||||
child: Text(
|
|
||||||
subtitle,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 11,
|
|
||||||
color: Color(0xFFAAAAAA),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'dart:math';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:package_info_plus/package_info_plus.dart';
|
import 'package:package_info_plus/package_info_plus.dart';
|
||||||
import '../providers/app_provider.dart';
|
import '../providers/app_provider.dart';
|
||||||
import '../utils/user_prefs.dart';
|
import '../utils/user_prefs.dart';
|
||||||
import '../models/data_models.dart';
|
|
||||||
import '../pages/stroll_page.dart';
|
import '../pages/stroll_page.dart';
|
||||||
import '../pages/markdown_reader/md_reader_tab_page.dart';
|
import '../pages/markdown_reader/md_reader_tab_page.dart';
|
||||||
import '../pages/tag_management_page.dart';
|
import '../pages/tag_management_page.dart';
|
||||||
|
import '../pages/profile_page.dart';
|
||||||
|
|
||||||
/// 自定义左侧弹出菜单 - 极简主义设计
|
/// 自定义侧边栏
|
||||||
class CustomDrawer extends StatefulWidget {
|
class CustomDrawer extends StatefulWidget {
|
||||||
const CustomDrawer({super.key});
|
const CustomDrawer({super.key});
|
||||||
|
|
||||||
@@ -29,55 +28,41 @@ class _CustomDrawerState extends State<CustomDrawer> {
|
|||||||
|
|
||||||
Future<void> _loadVersionInfo() async {
|
Future<void> _loadVersionInfo() async {
|
||||||
final packageInfo = await PackageInfo.fromPlatform();
|
final packageInfo = await PackageInfo.fromPlatform();
|
||||||
setState(() {
|
if (mounted) setState(() => _version = packageInfo.version);
|
||||||
_version = packageInfo.version;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Drawer(
|
return Drawer(
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: const Color(0xFFF8F8F8),
|
||||||
child: SafeArea(
|
child: SafeArea(
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
physics: const AlwaysScrollableScrollPhysics(),
|
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
// 1. 顶部用户信息(头像左,名称/座右铭右)
|
// 头像 + 统计(独立卡片区域)
|
||||||
_buildHeader(context),
|
_buildProfileCard(context),
|
||||||
|
|
||||||
const Divider(
|
const SizedBox(height: 16),
|
||||||
height: 0.5, thickness: 0.5, color: Color(0xFFE5E5E5)),
|
|
||||||
|
|
||||||
// 2. 统计数据
|
// 热力图
|
||||||
_buildStatsSection(context),
|
|
||||||
|
|
||||||
const Divider(
|
|
||||||
height: 0.5, thickness: 0.5, color: Color(0xFFE5E5E5)),
|
|
||||||
|
|
||||||
// 3. 热力图
|
|
||||||
_buildCalendarSection(context),
|
_buildCalendarSection(context),
|
||||||
|
|
||||||
const Divider(
|
const SizedBox(height: 16),
|
||||||
height: 0.5, thickness: 0.5, color: Color(0xFFE5E5E5)),
|
|
||||||
|
|
||||||
// 4. 回顾信息
|
// 最近添加
|
||||||
_buildMemorySection(context),
|
_buildRecentSection(context),
|
||||||
|
|
||||||
const Divider(
|
const SizedBox(height: 16),
|
||||||
height: 0.5, thickness: 0.5, color: Color(0xFFE5E5E5)),
|
|
||||||
|
|
||||||
// 5. 功能模块:漫步 / Markdown 阅读
|
// 功能入口
|
||||||
_buildToolsSection(context),
|
_buildToolsCard(context),
|
||||||
|
|
||||||
// 底部版本号
|
// 底部版本号
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.all(20),
|
padding: const EdgeInsets.fromLTRB(20, 20, 20, 32),
|
||||||
child: Text(
|
child: Center(
|
||||||
'MookNote v$_version',
|
child: Text('v$_version', style: const TextStyle(fontSize: 11, color: Color(0xFFD0D0D0))),
|
||||||
style:
|
|
||||||
const TextStyle(fontSize: 12, color: Color(0xFFBBBBBB)),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -87,301 +72,204 @@ class _CustomDrawerState extends State<CustomDrawer> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 1. 构建头部 - 头像左侧,名称/座右铭右侧
|
// ─── 头像 + 统计卡片 ─────────────────────────────────────────────────
|
||||||
Widget _buildHeader(BuildContext context) {
|
|
||||||
|
Widget _buildProfileCard(BuildContext context) {
|
||||||
return Consumer<AppProvider>(
|
return Consumer<AppProvider>(
|
||||||
builder: (context, provider, child) {
|
builder: (context, provider, child) {
|
||||||
final userPrefs = UserPrefs();
|
final userPrefs = UserPrefs();
|
||||||
final nickname = userPrefs.nickname;
|
final nickname = userPrefs.nickname;
|
||||||
final motto = userPrefs.motto;
|
final motto = userPrefs.motto;
|
||||||
final avatarPath = userPrefs.avatarPath;
|
final avatarPath = userPrefs.avatarPath;
|
||||||
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.fromLTRB(24, 40, 24, 24),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
// 左侧:头像
|
|
||||||
Container(
|
|
||||||
width: 56,
|
|
||||||
height: 56,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
shape: BoxShape.circle,
|
|
||||||
color: const Color(0xFFF5F5F5),
|
|
||||||
border:
|
|
||||||
Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
|
|
||||||
),
|
|
||||||
clipBehavior: Clip.antiAlias,
|
|
||||||
child: avatarPath != null && avatarPath.isNotEmpty
|
|
||||||
? Image.file(
|
|
||||||
File(avatarPath),
|
|
||||||
fit: BoxFit.cover,
|
|
||||||
errorBuilder: (_, __, ___) => _buildAvatarPlaceholder(),
|
|
||||||
)
|
|
||||||
: _buildAvatarPlaceholder(),
|
|
||||||
),
|
|
||||||
|
|
||||||
const SizedBox(width: 16),
|
|
||||||
|
|
||||||
// 右侧:名称 + 座右铭
|
|
||||||
Expanded(
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
nickname,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 18,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
color: Color(0xFF1A1A1A),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 4),
|
|
||||||
Text(
|
|
||||||
motto,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 13,
|
|
||||||
color: Color(0xFF999999),
|
|
||||||
),
|
|
||||||
maxLines: 1,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildAvatarPlaceholder() {
|
|
||||||
return const Center(
|
|
||||||
child: Icon(Icons.person_outline, size: 28, color: Color(0xFFAAAAAA)),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 2. 统计数据:观影xxx 阅读xxx 笔记xxx
|
|
||||||
Widget _buildStatsSection(BuildContext context) {
|
|
||||||
return Consumer<AppProvider>(
|
|
||||||
builder: (context, provider, child) {
|
|
||||||
final movieCount = provider.movies.where((m) => !m.isDeleted).length;
|
final movieCount = provider.movies.where((m) => !m.isDeleted).length;
|
||||||
final bookCount = provider.books.length;
|
final bookCount = provider.books.length;
|
||||||
final noteCount = provider.notes.length;
|
final noteCount = provider.notes.length;
|
||||||
|
|
||||||
return Padding(
|
return Container(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 20),
|
margin: const EdgeInsets.fromLTRB(16, 16, 16, 0),
|
||||||
child: Row(
|
padding: const EdgeInsets.all(20),
|
||||||
children: [
|
|
||||||
_buildStatItem('观影', movieCount),
|
|
||||||
const SizedBox(width: 32),
|
|
||||||
_buildStatItem('阅读', bookCount),
|
|
||||||
const SizedBox(width: 32),
|
|
||||||
_buildStatItem('笔记', noteCount),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildStatItem(String label, int count) {
|
|
||||||
return Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
'$count',
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 22,
|
|
||||||
fontWeight: FontWeight.w700,
|
|
||||||
color: Color(0xFF1A1A1A),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 2),
|
|
||||||
Text(
|
|
||||||
label,
|
|
||||||
style: const TextStyle(fontSize: 12, color: Color(0xFF999999)),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 5. 功能模块:漫步 / Markdown 阅读
|
|
||||||
Widget _buildToolsSection(BuildContext context) {
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
|
|
||||||
child: Container(
|
|
||||||
width: double.infinity,
|
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: const Color(0xFFFAFAFA),
|
color: Colors.white,
|
||||||
borderRadius: BorderRadius.circular(10),
|
borderRadius: BorderRadius.circular(16),
|
||||||
border: Border.all(color: const Color(0xFFEEEEEE), width: 0.5),
|
|
||||||
),
|
),
|
||||||
child: Column(
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
// 头像 + 名称/座右铭 + 统计
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
// 头像
|
||||||
|
Container(
|
||||||
|
width: 52,
|
||||||
|
height: 52,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
color: const Color(0xFFF5F5F5),
|
||||||
|
border: Border.all(color: const Color(0xFFEEEEEE), width: 0.5),
|
||||||
|
),
|
||||||
|
clipBehavior: Clip.antiAlias,
|
||||||
|
child: avatarPath != null && avatarPath.isNotEmpty
|
||||||
|
? Image.file(File(avatarPath), fit: BoxFit.cover,
|
||||||
|
errorBuilder: (_, __, ___) =>
|
||||||
|
const Icon(Icons.person_outline, size: 26, color: Color(0xFFBBBBBB)))
|
||||||
|
: const Icon(Icons.person_outline, size: 26, color: Color(0xFFBBBBBB)),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 14),
|
||||||
|
// 名称 + 座右铭
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
// 漫步
|
Text(nickname, style: const TextStyle(fontSize: 17, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A))),
|
||||||
|
const SizedBox(height: 2),
|
||||||
|
Text(motto, maxLines: 1, overflow: TextOverflow.ellipsis,
|
||||||
|
style: const TextStyle(fontSize: 12, color: Color(0xFFAAAAAA))),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
const Divider(height: 1, color: Color(0xFFF0F0F0)),
|
||||||
|
const SizedBox(height: 14),
|
||||||
|
|
||||||
|
// 统计数字
|
||||||
|
_buildProfileStatRow(Icons.movie_outlined, movieCount, '观影'),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
_buildProfileStatRow(Icons.menu_book_outlined, bookCount, '阅读'),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
_buildProfileStatRow(Icons.note_outlined, noteCount, '笔记'),
|
||||||
|
|
||||||
|
// 设置入口
|
||||||
|
const SizedBox(height: 14),
|
||||||
|
const Divider(height: 1, color: Color(0xFFF0F0F0)),
|
||||||
InkWell(
|
InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
Navigator.push(
|
Navigator.push(context, MaterialPageRoute(builder: (_) => const SettingsPage()));
|
||||||
context,
|
|
||||||
MaterialPageRoute(builder: (_) => const StrollPage()),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
borderRadius:
|
borderRadius: BorderRadius.circular(8),
|
||||||
const BorderRadius.vertical(top: Radius.circular(10)),
|
|
||||||
child: const Padding(
|
child: const Padding(
|
||||||
padding: EdgeInsets.symmetric(vertical: 13, horizontal: 16),
|
padding: EdgeInsets.only(top: 14),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Icon(Icons.explore_outlined,
|
Icon(Icons.settings_outlined, size: 16, color: Color(0xFF999999)),
|
||||||
size: 18, color: Color(0xFF666666)),
|
SizedBox(width: 8),
|
||||||
SizedBox(width: 10),
|
Text('设置', style: TextStyle(fontSize: 13, color: Color(0xFF888888))),
|
||||||
Expanded(
|
Spacer(),
|
||||||
child: Text(
|
Icon(Icons.chevron_right, size: 14, color: Color(0xFFD0D0D0)),
|
||||||
'漫步',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
color: Color(0xFF1A1A1A)),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
'随机发现一条内容',
|
|
||||||
style: TextStyle(fontSize: 11, color: Color(0xFFBBBBBB)),
|
|
||||||
),
|
|
||||||
SizedBox(width: 6),
|
|
||||||
Icon(Icons.chevron_right,
|
|
||||||
size: 16, color: Color(0xFFCCCCCC)),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
// 分隔线
|
|
||||||
const Divider(
|
|
||||||
height: 0.5, thickness: 0.5, color: Color(0xFFEEEEEE)),
|
|
||||||
|
|
||||||
// 标签管理
|
|
||||||
InkWell(
|
|
||||||
onTap: () {
|
|
||||||
Navigator.pop(context);
|
|
||||||
Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(builder: (_) => const TagManagementPage()),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
borderRadius: BorderRadius.zero,
|
|
||||||
child: const Padding(
|
|
||||||
padding: EdgeInsets.symmetric(vertical: 13, horizontal: 16),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Icon(Icons.label_outline,
|
|
||||||
size: 18, color: Color(0xFF666666)),
|
|
||||||
SizedBox(width: 10),
|
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
'标签管理',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
color: Color(0xFF1A1A1A)),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
'管理标签',
|
|
||||||
style: TextStyle(fontSize: 11, color: Color(0xFFBBBBBB)),
|
|
||||||
),
|
|
||||||
SizedBox(width: 6),
|
|
||||||
Icon(Icons.chevron_right,
|
|
||||||
size: 16, color: Color(0xFFCCCCCC)),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
|
||||||
),
|
|
||||||
|
|
||||||
// 分隔线
|
|
||||||
const Divider(
|
|
||||||
height: 0.5, thickness: 0.5, color: Color(0xFFEEEEEE)),
|
|
||||||
|
|
||||||
// Markdown 阅读
|
|
||||||
InkWell(
|
|
||||||
onTap: () {
|
|
||||||
Navigator.pop(context);
|
|
||||||
Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(builder: (_) => const MdReaderTabPage()),
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
borderRadius:
|
);
|
||||||
const BorderRadius.vertical(bottom: Radius.circular(10)),
|
}
|
||||||
child: const Padding(
|
|
||||||
padding: EdgeInsets.symmetric(vertical: 13, horizontal: 16),
|
Widget _buildProfileStatRow(IconData icon, int count, String label) {
|
||||||
child: Row(
|
return Row(
|
||||||
children: [
|
children: [
|
||||||
Icon(Icons.description_outlined,
|
Icon(icon, size: 16, color: const Color(0xFF888888)),
|
||||||
size: 18, color: Color(0xFF666666)),
|
const SizedBox(width: 10),
|
||||||
SizedBox(width: 10),
|
Text(label, style: const TextStyle(fontSize: 13, color: Color(0xFF888888))),
|
||||||
Expanded(
|
const Spacer(),
|
||||||
child: Text(
|
Text(_formatCount(count), style: const TextStyle(fontSize: 15, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A))),
|
||||||
'MD阅读',
|
],
|
||||||
style: TextStyle(
|
);
|
||||||
fontSize: 14,
|
}
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
color: Color(0xFF1A1A1A)),
|
String _formatCount(int count) {
|
||||||
|
if (count >= 10000) return '${(count / 10000).toStringAsFixed(1)}万';
|
||||||
|
if (count >= 1000) return '${(count / 1000).toStringAsFixed(1)}k';
|
||||||
|
return count.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── 功能入口卡片 ────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
Widget _buildToolsCard(BuildContext context) {
|
||||||
|
return Container(
|
||||||
|
margin: const EdgeInsets.symmetric(horizontal: 16),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.white,
|
||||||
|
borderRadius: BorderRadius.circular(16),
|
||||||
),
|
),
|
||||||
),
|
child: Column(
|
||||||
Text(
|
children: [
|
||||||
'浏览本地 md 文件',
|
_buildToolItem(Icons.explore_outlined, '漫步', () {
|
||||||
style: TextStyle(fontSize: 11, color: Color(0xFFBBBBBB)),
|
Navigator.pop(context);
|
||||||
),
|
Navigator.push(context, MaterialPageRoute(builder: (_) => const StrollPage()));
|
||||||
SizedBox(width: 6),
|
}, topRounded: true),
|
||||||
Icon(Icons.chevron_right,
|
const Divider(height: 1, indent: 52, endIndent: 20, color: Color(0xFFF0F0F0)),
|
||||||
size: 16, color: Color(0xFFCCCCCC)),
|
_buildToolItem(Icons.label_outline, '标签管理', () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
Navigator.push(context, MaterialPageRoute(builder: (_) => const TagManagementPage()));
|
||||||
|
}),
|
||||||
|
const Divider(height: 1, indent: 52, endIndent: 20, color: Color(0xFFF0F0F0)),
|
||||||
|
_buildToolItem(Icons.description_outlined, 'MD阅读', () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
Navigator.push(context, MaterialPageRoute(builder: (_) => const MdReaderTabPage()));
|
||||||
|
}, bottomRounded: true),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildToolItem(IconData icon, String title, VoidCallback onTap, {bool topRounded = false, bool bottomRounded = false}) {
|
||||||
|
return InkWell(
|
||||||
|
onTap: onTap,
|
||||||
|
borderRadius: BorderRadius.only(
|
||||||
|
topLeft: topRounded ? const Radius.circular(16) : Radius.zero,
|
||||||
|
topRight: topRounded ? const Radius.circular(16) : Radius.zero,
|
||||||
|
bottomLeft: bottomRounded ? const Radius.circular(16) : Radius.zero,
|
||||||
|
bottomRight: bottomRounded ? const Radius.circular(16) : Radius.zero,
|
||||||
),
|
),
|
||||||
),
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 14, horizontal: 20),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Icon(icon, size: 20, color: const Color(0xFF555555)),
|
||||||
|
const SizedBox(width: 12),
|
||||||
|
Expanded(child: Text(title, style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500, color: Color(0xFF1A1A1A)))),
|
||||||
|
const Icon(Icons.chevron_right, size: 16, color: Color(0xFFD0D0D0)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ─── 热力图(保持现状) ──────────────────────────────────────────────
|
||||||
|
|
||||||
Widget _buildCalendarSection(BuildContext context) {
|
Widget _buildCalendarSection(BuildContext context) {
|
||||||
return Consumer<AppProvider>(
|
return Consumer<AppProvider>(
|
||||||
builder: (context, provider, child) {
|
builder: (context, provider, child) {
|
||||||
final Map<DateTime, int> dailyCounts = {};
|
final Map<DateTime, int> dailyCounts = {};
|
||||||
|
|
||||||
for (final movie in provider.movies.where((m) => !m.isDeleted)) {
|
for (final movie in provider.movies.where((m) => !m.isDeleted)) {
|
||||||
final date = DateTime(
|
final date = DateTime(movie.createdAt.year, movie.createdAt.month, movie.createdAt.day);
|
||||||
movie.createdAt.year, movie.createdAt.month, movie.createdAt.day);
|
|
||||||
dailyCounts[date] = (dailyCounts[date] ?? 0) + 1;
|
dailyCounts[date] = (dailyCounts[date] ?? 0) + 1;
|
||||||
}
|
}
|
||||||
for (final book in provider.books.where((b) => !b.isDeleted)) {
|
for (final book in provider.books.where((b) => !b.isDeleted)) {
|
||||||
final date = DateTime(
|
final date = DateTime(book.createdAt.year, book.createdAt.month, book.createdAt.day);
|
||||||
book.createdAt.year, book.createdAt.month, book.createdAt.day);
|
|
||||||
dailyCounts[date] = (dailyCounts[date] ?? 0) + 1;
|
dailyCounts[date] = (dailyCounts[date] ?? 0) + 1;
|
||||||
}
|
}
|
||||||
for (final note in provider.notes.where((n) => !n.isDeleted)) {
|
for (final note in provider.notes.where((n) => !n.isDeleted)) {
|
||||||
final date = DateTime(
|
final date = DateTime(note.createdAt.year, note.createdAt.month, note.createdAt.day);
|
||||||
note.createdAt.year, note.createdAt.month, note.createdAt.day);
|
|
||||||
dailyCounts[date] = (dailyCounts[date] ?? 0) + 1;
|
dailyCounts[date] = (dailyCounts[date] ?? 0) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算最大计数用于颜色映射
|
|
||||||
int maxCount = 0;
|
int maxCount = 0;
|
||||||
for (final c in dailyCounts.values) {
|
for (final c in dailyCounts.values) {
|
||||||
if (c > maxCount) maxCount = c;
|
if (c > maxCount) maxCount = c;
|
||||||
}
|
}
|
||||||
if (maxCount == 0) maxCount = 1;
|
if (maxCount == 0) maxCount = 1;
|
||||||
|
|
||||||
// 从上周日开始,往前推 N 周
|
|
||||||
final now = DateTime.now();
|
final now = DateTime.now();
|
||||||
final today = DateTime(now.year, now.month, now.day);
|
final today = DateTime(now.year, now.month, now.day);
|
||||||
final daysSinceSunday = today.weekday % 7; // Sunday=0
|
final daysSinceSunday = today.weekday % 7;
|
||||||
final lastSunday = today.subtract(Duration(days: daysSinceSunday));
|
final lastSunday = today.subtract(Duration(days: daysSinceSunday));
|
||||||
|
|
||||||
const totalWeeks = 20;
|
const totalWeeks = 20;
|
||||||
@@ -389,119 +277,77 @@ class _CustomDrawerState extends State<CustomDrawer> {
|
|||||||
const cellSize = 13.0;
|
const cellSize = 13.0;
|
||||||
const cellGap = 3.0;
|
const cellGap = 3.0;
|
||||||
|
|
||||||
// 构建网格:行=星期几(0=日..6=六),列=周(0=最旧..19=最新)
|
final cells = List.generate(weekDays, (_) => List.generate(totalWeeks, (_) => 0));
|
||||||
final cells =
|
|
||||||
List.generate(weekDays, (_) => List.generate(totalWeeks, (_) => 0));
|
|
||||||
|
|
||||||
for (int week = 0; week < totalWeeks; week++) {
|
for (int week = 0; week < totalWeeks; week++) {
|
||||||
for (int day = 0; day < weekDays; day++) {
|
for (int day = 0; day < weekDays; day++) {
|
||||||
final date = lastSunday.subtract(
|
final date = lastSunday.subtract(Duration(days: (totalWeeks - 1 - week) * 7 + (6 - day)));
|
||||||
Duration(days: (totalWeeks - 1 - week) * 7 + (6 - day)));
|
|
||||||
cells[day][week] = dailyCounts[date] ?? 0;
|
cells[day][week] = dailyCounts[date] ?? 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 月份标签:找出每个月第一天所在的列
|
|
||||||
final monthLabels = <int, String>{};
|
final monthLabels = <int, String>{};
|
||||||
for (int week = 0; week < totalWeeks; week++) {
|
for (int week = 0; week < totalWeeks; week++) {
|
||||||
final date =
|
final date = lastSunday.subtract(Duration(days: (totalWeeks - 1 - week) * 7));
|
||||||
lastSunday.subtract(Duration(days: (totalWeeks - 1 - week) * 7));
|
|
||||||
final key = date.month;
|
final key = date.month;
|
||||||
if (!monthLabels.containsKey(key) || date.day <= 7) {
|
if (!monthLabels.containsKey(key) || date.day <= 7) {
|
||||||
monthLabels[week] = '${date.month}月';
|
monthLabels[week] = '${date.month}月';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 只保留首、中间、尾三个月份标签
|
|
||||||
final sortedWeeks = monthLabels.keys.toList()..sort();
|
final sortedWeeks = monthLabels.keys.toList()..sort();
|
||||||
final keepWeeks = <int>{
|
final keepWeeks = {sortedWeeks.first, sortedWeeks[sortedWeeks.length ~/ 2], sortedWeeks.last};
|
||||||
sortedWeeks.first,
|
|
||||||
sortedWeeks[sortedWeeks.length ~/ 2],
|
|
||||||
sortedWeeks.last,
|
|
||||||
};
|
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
width: double.infinity,
|
margin: const EdgeInsets.symmetric(horizontal: 16),
|
||||||
padding: const EdgeInsets.all(20),
|
padding: const EdgeInsets.all(18),
|
||||||
|
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(16)),
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
const Row(
|
const Row(
|
||||||
children: [
|
children: [
|
||||||
Icon(Icons.calendar_today,
|
Icon(Icons.calendar_today, size: 14, color: Color(0xFF999999)),
|
||||||
size: 14, color: Color(0xFF999999)),
|
|
||||||
SizedBox(width: 8),
|
SizedBox(width: 8),
|
||||||
Text(
|
Text('热力图', style: TextStyle(fontSize: 13, fontWeight: FontWeight.w500, color: Color(0xFF666666))),
|
||||||
'热力图',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 13,
|
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
color: Color(0xFF666666)),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 14),
|
||||||
|
|
||||||
// 热力图主体
|
|
||||||
SingleChildScrollView(
|
SingleChildScrollView(
|
||||||
scrollDirection: Axis.horizontal,
|
scrollDirection: Axis.horizontal,
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
// 月份标签行
|
|
||||||
SizedBox(
|
SizedBox(
|
||||||
height: 16,
|
height: 16,
|
||||||
child: Row(
|
child: Row(
|
||||||
children: List.generate(totalWeeks, (week) {
|
children: List.generate(totalWeeks, (week) {
|
||||||
final label = keepWeeks.contains(week)
|
final label = keepWeeks.contains(week) ? monthLabels[week] : null;
|
||||||
? monthLabels[week]
|
|
||||||
: null;
|
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
width: cellSize + cellGap,
|
width: cellSize + cellGap,
|
||||||
child: label != null
|
child: label != null ? Text(label, style: const TextStyle(fontSize: 9, color: Color(0xFFBBBBBB))) : null,
|
||||||
? Text(label,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 9, color: Color(0xFFBBBBBB)))
|
|
||||||
: null,
|
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 2),
|
const SizedBox(height: 2),
|
||||||
|
...List.generate(weekDays, (day) => Row(
|
||||||
// 日期网格行
|
|
||||||
...List.generate(weekDays, (day) {
|
|
||||||
return Row(
|
|
||||||
children: List.generate(totalWeeks, (week) {
|
children: List.generate(totalWeeks, (week) {
|
||||||
final count = cells[day][week];
|
final count = cells[day][week];
|
||||||
final color = _heatmapColor(count, maxCount);
|
|
||||||
return Container(
|
return Container(
|
||||||
width: cellSize,
|
width: cellSize, height: cellSize,
|
||||||
height: cellSize,
|
margin: EdgeInsets.only(right: week < totalWeeks - 1 ? cellGap : 0, bottom: day < weekDays - 1 ? cellGap : 0),
|
||||||
margin: EdgeInsets.only(
|
decoration: BoxDecoration(color: _heatmapColor(count, maxCount), borderRadius: BorderRadius.circular(2)),
|
||||||
right: week < totalWeeks - 1 ? cellGap : 0,
|
|
||||||
bottom: day < weekDays - 1 ? cellGap : 0,
|
|
||||||
),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: color,
|
|
||||||
borderRadius: BorderRadius.circular(2),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
|
)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
// 图例
|
|
||||||
const SizedBox(height: 10),
|
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.end,
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
children: [
|
children: [
|
||||||
const Text('少',
|
const Text('少', style: TextStyle(fontSize: 9, color: Color(0xFFBBBBBB))),
|
||||||
style: TextStyle(fontSize: 9, color: Color(0xFFBBBBBB))),
|
|
||||||
const SizedBox(width: 3),
|
const SizedBox(width: 3),
|
||||||
_legendCell(const Color(0xFFF0F0F0)),
|
_legendCell(const Color(0xFFF0F0F0)),
|
||||||
_legendCell(const Color(0xFFC8E6C9)),
|
_legendCell(const Color(0xFFC8E6C9)),
|
||||||
@@ -509,8 +355,7 @@ class _CustomDrawerState extends State<CustomDrawer> {
|
|||||||
_legendCell(const Color(0xFF2E7D32)),
|
_legendCell(const Color(0xFF2E7D32)),
|
||||||
_legendCell(const Color(0xFF1B5E20)),
|
_legendCell(const Color(0xFF1B5E20)),
|
||||||
const SizedBox(width: 3),
|
const SizedBox(width: 3),
|
||||||
const Text('多',
|
const Text('多', style: TextStyle(fontSize: 9, color: Color(0xFFBBBBBB))),
|
||||||
style: TextStyle(fontSize: 9, color: Color(0xFFBBBBBB))),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -530,126 +375,51 @@ class _CustomDrawerState extends State<CustomDrawer> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _legendCell(Color color) {
|
Widget _legendCell(Color color) {
|
||||||
return Container(
|
return Container(width: 10, height: 10, margin: const EdgeInsets.symmetric(horizontal: 1),
|
||||||
width: 10,
|
decoration: BoxDecoration(color: color, borderRadius: BorderRadius.circular(2)));
|
||||||
height: 10,
|
|
||||||
margin: const EdgeInsets.symmetric(horizontal: 1),
|
|
||||||
decoration:
|
|
||||||
BoxDecoration(color: color, borderRadius: BorderRadius.circular(2)),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 4. 回顾信息
|
// ─── 最近添加 ────────────────────────────────────────────────────────
|
||||||
Widget _buildMemorySection(BuildContext context) {
|
|
||||||
|
Widget _buildRecentSection(BuildContext context) {
|
||||||
return Consumer<AppProvider>(
|
return Consumer<AppProvider>(
|
||||||
builder: (context, provider, child) {
|
builder: (context, provider, child) {
|
||||||
final memoryItem = _getRandomMemoryItem(provider);
|
final recent = _getRecentItems(provider);
|
||||||
|
if (recent.isEmpty) return const SizedBox.shrink();
|
||||||
if (memoryItem == null) {
|
|
||||||
return const SizedBox.shrink();
|
|
||||||
}
|
|
||||||
|
|
||||||
final memoryText = _buildMemoryText(memoryItem);
|
|
||||||
final timeAgo = _getTimeAgoText(memoryItem.date);
|
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
width: double.infinity,
|
margin: const EdgeInsets.symmetric(horizontal: 16),
|
||||||
padding: const EdgeInsets.all(20),
|
padding: const EdgeInsets.all(18),
|
||||||
|
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(16)),
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
// 标题
|
const Row(
|
||||||
Row(
|
|
||||||
children: [
|
children: [
|
||||||
const Icon(Icons.history, size: 14, color: Color(0xFF999999)),
|
Icon(Icons.schedule, size: 14, color: Color(0xFF999999)),
|
||||||
const SizedBox(width: 8),
|
SizedBox(width: 8),
|
||||||
const Text(
|
Text('最近添加', style: TextStyle(fontSize: 13, fontWeight: FontWeight.w500, color: Color(0xFF666666))),
|
||||||
'回顾',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 13,
|
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
color: Color(0xFF666666)),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 14),
|
||||||
|
...recent.take(4).map((item) => Padding(
|
||||||
// 内容卡片
|
padding: const EdgeInsets.only(bottom: 10),
|
||||||
Row(
|
child: Row(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
children: [
|
||||||
// 头图
|
Icon(
|
||||||
if (memoryItem.imagePath != null &&
|
item.type == 'movie' ? Icons.movie_outlined : item.type == 'book' ? Icons.menu_book_outlined : Icons.note_outlined,
|
||||||
memoryItem.imagePath!.isNotEmpty)
|
size: 14, color: const Color(0xFFBBBBBB),
|
||||||
Container(
|
|
||||||
width: 56,
|
|
||||||
height: 72,
|
|
||||||
margin: const EdgeInsets.only(right: 12),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: const Color(0xFFF5F5F5),
|
|
||||||
borderRadius: BorderRadius.circular(4),
|
|
||||||
),
|
),
|
||||||
child: ClipRRect(
|
const SizedBox(width: 10),
|
||||||
borderRadius: BorderRadius.circular(4),
|
|
||||||
child: Image.file(
|
|
||||||
File(memoryItem.imagePath!),
|
|
||||||
fit: BoxFit.cover,
|
|
||||||
errorBuilder: (_, __, ___) =>
|
|
||||||
const Icon(Icons.image, color: Color(0xFFCCCCCC)),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
else if (memoryItem.type != 'note')
|
|
||||||
Container(
|
|
||||||
width: 56,
|
|
||||||
height: 72,
|
|
||||||
margin: const EdgeInsets.only(right: 12),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: const Color(0xFFF5F5F5),
|
|
||||||
borderRadius: BorderRadius.circular(4),
|
|
||||||
),
|
|
||||||
child: Icon(
|
|
||||||
memoryItem.type == 'movie'
|
|
||||||
? Icons.movie
|
|
||||||
: Icons.menu_book,
|
|
||||||
color: const Color(0xFFCCCCCC),
|
|
||||||
size: 22,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
|
|
||||||
// 文字
|
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Column(
|
child: Text(item.title, maxLines: 1, overflow: TextOverflow.ellipsis,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
style: const TextStyle(fontSize: 13, color: Color(0xFF444444))),
|
||||||
children: [
|
|
||||||
Container(
|
|
||||||
padding: const EdgeInsets.symmetric(
|
|
||||||
horizontal: 8, vertical: 3),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: const Color(0xFFF5F5F5),
|
|
||||||
borderRadius: BorderRadius.circular(4),
|
|
||||||
),
|
|
||||||
child: Text(
|
|
||||||
timeAgo,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 10, color: Color(0xFF999999)),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
Text(
|
|
||||||
memoryText,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 13,
|
|
||||||
color: Color(0xFF1A1A1A),
|
|
||||||
height: 1.5),
|
|
||||||
maxLines: 3,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Text(_recentTimeAgo(item.date), style: const TextStyle(fontSize: 10, color: Color(0xFFCCCCCC))),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -657,85 +427,34 @@ class _CustomDrawerState extends State<CustomDrawer> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
_MemoryItem? _getRandomMemoryItem(AppProvider provider) {
|
List<_RecentItem> _getRecentItems(AppProvider provider) {
|
||||||
final now = DateTime.now();
|
final items = <_RecentItem>[];
|
||||||
final candidates = <_MemoryItem>[];
|
for (final m in provider.movies.where((m) => !m.isDeleted)) {
|
||||||
|
items.add(_RecentItem(type: 'movie', title: m.title, date: m.createdAt));
|
||||||
for (final movie in provider.movies.where((m) => !m.isDeleted)) {
|
}
|
||||||
candidates.add(_MemoryItem(
|
for (final b in provider.books.where((b) => !b.isDeleted)) {
|
||||||
type: 'movie',
|
items.add(_RecentItem(type: 'book', title: b.title, date: b.createdAt));
|
||||||
title: movie.title,
|
}
|
||||||
date: movie.createdAt,
|
for (final n in provider.notes.where((n) => !n.isDeleted)) {
|
||||||
imagePath: movie.posterPath,
|
items.add(_RecentItem(type: 'note', title: n.title.isNotEmpty ? n.title : '随手记', date: n.createdAt));
|
||||||
));
|
}
|
||||||
|
items.sort((a, b) => b.date.compareTo(a.date));
|
||||||
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final book in provider.books.where((b) => !b.isDeleted)) {
|
String _recentTimeAgo(DateTime date) {
|
||||||
candidates.add(_MemoryItem(
|
final diff = DateTime.now().difference(date);
|
||||||
type: 'book',
|
if (diff.inDays >= 365) return '${(diff.inDays / 365).floor()}年前';
|
||||||
title: book.title,
|
if (diff.inDays >= 30) return '${(diff.inDays / 30).floor()}月前';
|
||||||
date: book.createdAt,
|
if (diff.inDays > 0) return '${diff.inDays}天前';
|
||||||
imagePath: book.coverPath,
|
if (diff.inHours > 0) return '${diff.inHours}小时前';
|
||||||
));
|
return '刚刚';
|
||||||
}
|
|
||||||
|
|
||||||
if (candidates.isEmpty) return null;
|
|
||||||
|
|
||||||
final oneMonthAgo = now.subtract(const Duration(days: 30));
|
|
||||||
final threeMonthsAgo = now.subtract(const Duration(days: 90));
|
|
||||||
final sixMonthsAgo = now.subtract(const Duration(days: 180));
|
|
||||||
final oneYearAgo = now.subtract(const Duration(days: 365));
|
|
||||||
|
|
||||||
final memoryCandidates = candidates.where((item) {
|
|
||||||
return _isInTimeRange(
|
|
||||||
item.date, oneMonthAgo, threeMonthsAgo, sixMonthsAgo, oneYearAgo);
|
|
||||||
}).toList();
|
|
||||||
|
|
||||||
final random = Random();
|
|
||||||
final selectedList =
|
|
||||||
memoryCandidates.isNotEmpty ? memoryCandidates : candidates;
|
|
||||||
return selectedList[random.nextInt(selectedList.length)];
|
|
||||||
}
|
|
||||||
|
|
||||||
bool _isInTimeRange(DateTime date, DateTime oneMonth, DateTime threeMonths,
|
|
||||||
DateTime sixMonths, DateTime oneYear) {
|
|
||||||
if (_isCloseTo(date, oneMonth)) return true;
|
|
||||||
if (_isCloseTo(date, threeMonths, days: 14)) return true;
|
|
||||||
if (_isCloseTo(date, sixMonths, days: 30)) return true;
|
|
||||||
if (_isCloseTo(date, oneYear, days: 30)) return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool _isCloseTo(DateTime date, DateTime target, {int days = 7}) {
|
|
||||||
final diff = date.difference(target).inDays.abs();
|
|
||||||
return diff <= days;
|
|
||||||
}
|
|
||||||
|
|
||||||
String _buildMemoryText(_MemoryItem item) {
|
|
||||||
return '《${item.title}》';
|
|
||||||
}
|
|
||||||
|
|
||||||
String _getTimeAgoText(DateTime date) {
|
|
||||||
final now = DateTime.now();
|
|
||||||
final diff = 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}天前';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _MemoryItem {
|
class _RecentItem {
|
||||||
final String type;
|
final String type;
|
||||||
final String title;
|
final String title;
|
||||||
final DateTime date;
|
final DateTime date;
|
||||||
final String? imagePath;
|
_RecentItem({required this.type, required this.title, required this.date});
|
||||||
|
|
||||||
_MemoryItem({
|
|
||||||
required this.type,
|
|
||||||
required this.title,
|
|
||||||
required this.date,
|
|
||||||
this.imagePath,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user