Initial commit: Flutter 无书应用项目
This commit is contained in:
306
lib/views/favorites_page.dart
Normal file
306
lib/views/favorites_page.dart
Normal file
@@ -0,0 +1,306 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import '../constants/app_constants.dart';
|
||||
import '../views/footprint/liked_poetry_manager.dart';
|
||||
import '../widgets/tabbed_nav_app_bar.dart';
|
||||
import 'active/active_search_page.dart';
|
||||
import 'footprint/all_list.dart';
|
||||
import 'footprint/collect_notes.dart';
|
||||
import 'footprint/local_jilu.dart';
|
||||
|
||||
/// 时间: 2026-03-22
|
||||
/// 功能: 收藏页面
|
||||
/// 介绍: 展示用户收藏的内容,支持分类管理和搜索
|
||||
/// 最新变化: 笔记列表组件独立到 local_jilu.dart
|
||||
|
||||
class FavoritesPage extends StatefulWidget {
|
||||
const FavoritesPage({super.key});
|
||||
|
||||
@override
|
||||
State<FavoritesPage> createState() => _FavoritesPageState();
|
||||
}
|
||||
|
||||
class _FavoritesPageState extends State<FavoritesPage>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late TabController _tabController;
|
||||
final List<String> _categories = ['全部', '点赞', '笔记', '推送', '关注进度'];
|
||||
final TextEditingController _searchBarController = TextEditingController();
|
||||
bool _isGridView = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_tabController = TabController(length: _categories.length, vsync: this);
|
||||
_tabController.addListener(() {
|
||||
setState(() {});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_tabController.dispose();
|
||||
_searchBarController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: TabbedNavAppBar.build(
|
||||
title: '收藏',
|
||||
tabController: _tabController,
|
||||
tabLabels: _categories,
|
||||
tabBarScrollable: true,
|
||||
tabLabelPadding: const EdgeInsets.symmetric(horizontal: 10),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: Icon(_isGridView ? Icons.view_list : Icons.grid_view),
|
||||
onPressed: _toggleViewMode,
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.filter_list),
|
||||
onPressed: _showFilterOptions,
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
_buildSearchBar(),
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
controller: _tabController,
|
||||
children: _categories
|
||||
.map((category) => _buildFavoriteList(category))
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
floatingActionButton: _buildFloatingButton(),
|
||||
floatingActionButtonLocation: FloatingActionButtonLocation.miniEndFloat,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFloatingButton() {
|
||||
final currentIndex = _tabController.index;
|
||||
final currentCategory = _categories[currentIndex];
|
||||
|
||||
if (currentCategory != '笔记') {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
return FloatingActionButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute<void>(builder: (_) => const CollectNotesPage()),
|
||||
);
|
||||
},
|
||||
child: const Icon(Icons.add),
|
||||
backgroundColor: AppConstants.primaryColor,
|
||||
heroTag: 'notes_fab',
|
||||
elevation: 4,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSearchBar() {
|
||||
return Container(
|
||||
margin: EdgeInsets.fromLTRB(
|
||||
AppConstants.pageHorizontalPadding,
|
||||
0,
|
||||
AppConstants.pageHorizontalPadding,
|
||||
16,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[100],
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: TextField(
|
||||
controller: _searchBarController,
|
||||
readOnly: true,
|
||||
onTap: () {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute<void>(
|
||||
builder: (_) => ActiveSearchPage(
|
||||
initialQuery: _searchBarController.text.trim().isEmpty
|
||||
? null
|
||||
: _searchBarController.text.trim(),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
hintText: '点按搜索全站诗词…',
|
||||
prefixIcon: const Icon(Icons.search, color: Colors.grey),
|
||||
suffixIcon: Icon(Icons.chevron_right, color: Colors.grey[500]),
|
||||
border: InputBorder.none,
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 12,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFavoriteList(String category) {
|
||||
// 如果是"全部"标签,显示统一的收藏列表(点赞+笔记)
|
||||
if (category == '全部') {
|
||||
return const AllListPage();
|
||||
}
|
||||
|
||||
// 如果是"点赞"标签,显示点赞内容管理器
|
||||
if (category == '点赞') {
|
||||
return const LikedPoetryManager();
|
||||
}
|
||||
|
||||
// 如果是"笔记"标签,显示笔记列表
|
||||
if (category == '笔记') {
|
||||
return const LocalNotesList();
|
||||
}
|
||||
|
||||
// 其他标签显示占位内容,但支持下拉刷新
|
||||
return RefreshIndicator(
|
||||
onRefresh: () async {
|
||||
// 模拟刷新其他分类数据
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
},
|
||||
child: _buildPlaceholderContent(category),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPlaceholderContent(String category) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.category_outlined, size: 64, color: Colors.grey[400]),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'$category功能暂未开放',
|
||||
style: TextStyle(fontSize: 16, color: Colors.grey[600]),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'敬请期待后续更新',
|
||||
style: TextStyle(fontSize: 14, color: Colors.grey[500]),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _toggleViewMode() {
|
||||
setState(() {
|
||||
_isGridView = !_isGridView;
|
||||
});
|
||||
}
|
||||
|
||||
void _showFilterOptions() {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (context) => Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text(
|
||||
'筛选选项',
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.date_range),
|
||||
title: const Text('按时间排序'),
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(const SnackBar(content: Text('按时间排序')));
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.title),
|
||||
title: const Text('按标题排序'),
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(const SnackBar(content: Text('按标题排序')));
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showFavoriteDetails(BuildContext context, int index, String category) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text('$category详情'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('分类: $category'),
|
||||
const SizedBox(height: 8),
|
||||
Text('收藏时间: ${(index + 1) * 2}天前'),
|
||||
const SizedBox(height: 8),
|
||||
const Text('这是收藏内容的详细信息。'),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('关闭'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _handleFavoriteAction(String action, int index) {
|
||||
switch (action) {
|
||||
case 'share':
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text('分享了收藏${index + 1}')));
|
||||
break;
|
||||
case 'edit':
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text('编辑了收藏${index + 1}')));
|
||||
break;
|
||||
case 'delete':
|
||||
_showDeleteConfirm(index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void _showDeleteConfirm(int index) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('确认删除'),
|
||||
content: Text('确定要删除收藏${index + 1}吗?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text('已删除收藏${index + 1}')));
|
||||
},
|
||||
child: const Text('删除', style: TextStyle(color: Colors.red)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user