215 lines
6.3 KiB
Dart
215 lines
6.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:get/get.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';
|
|
import '../services/get/favorites_controller.dart';
|
|
import '../services/get/theme_controller.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 controller = Get.put(FavoritesController());
|
|
final themeController = Get.find<ThemeController>();
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_tabController = TabController(
|
|
length: controller.categories.length,
|
|
vsync: this,
|
|
);
|
|
_tabController.addListener(() {
|
|
controller.setCurrentTabIndex(_tabController.index);
|
|
});
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_tabController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Obx(() {
|
|
final isDark = themeController.isDarkMode;
|
|
return Scaffold(
|
|
backgroundColor: isDark ? const Color(0xFF1A1A1A) : null,
|
|
appBar: TabbedNavAppBar.build(
|
|
title: '足迹',
|
|
tabLabels: controller.categories,
|
|
tabController: _tabController,
|
|
tabBarScrollable: true,
|
|
tabLabelPadding: const EdgeInsets.symmetric(horizontal: 10),
|
|
actions: [
|
|
IconButton(
|
|
icon: Icon(
|
|
controller.isGridView.value ? Icons.view_list : Icons.grid_view,
|
|
color: isDark ? Colors.white70 : null,
|
|
),
|
|
onPressed: controller.toggleViewMode,
|
|
),
|
|
IconButton(
|
|
icon: Icon(
|
|
Icons.filter_list,
|
|
color: isDark ? Colors.white70 : null,
|
|
),
|
|
onPressed: () => controller.showFilterOptions(context),
|
|
),
|
|
],
|
|
),
|
|
body: Column(
|
|
children: [
|
|
_buildSearchBar(controller, isDark),
|
|
Expanded(
|
|
child: TabBarView(
|
|
controller: _tabController,
|
|
children: controller.categories
|
|
.map((category) => _buildFavoriteList(category, controller))
|
|
.toList(),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
floatingActionButton: _buildFloatingButton(controller),
|
|
floatingActionButtonLocation: FloatingActionButtonLocation.miniEndFloat,
|
|
);
|
|
});
|
|
}
|
|
|
|
Widget _buildFloatingButton(FavoritesController controller) {
|
|
final currentCategory =
|
|
controller.categories[controller.currentTabIndex.value];
|
|
|
|
if (currentCategory != '笔记') {
|
|
return const SizedBox.shrink();
|
|
}
|
|
|
|
return FloatingActionButton(
|
|
onPressed: () {
|
|
Get.to(const CollectNotesPage());
|
|
},
|
|
child: const Icon(Icons.add),
|
|
backgroundColor: AppConstants.primaryColor,
|
|
heroTag: 'notes_fab',
|
|
elevation: 4,
|
|
);
|
|
}
|
|
|
|
Widget _buildSearchBar(FavoritesController controller, bool isDark) {
|
|
return Container(
|
|
margin: EdgeInsets.fromLTRB(
|
|
AppConstants.pageHorizontalPadding,
|
|
0,
|
|
AppConstants.pageHorizontalPadding,
|
|
16,
|
|
),
|
|
decoration: BoxDecoration(
|
|
color: isDark ? Colors.grey[850] : Colors.grey[100],
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
child: TextField(
|
|
readOnly: true,
|
|
onTap: () {
|
|
Get.to(
|
|
ActiveSearchPage(
|
|
initialQuery: controller.searchQuery.value.isEmpty
|
|
? null
|
|
: controller.searchQuery.value,
|
|
),
|
|
);
|
|
},
|
|
decoration: InputDecoration(
|
|
hintText: '点按搜索全站诗词…',
|
|
hintStyle: TextStyle(color: isDark ? Colors.grey[500] : Colors.grey),
|
|
prefixIcon: Icon(
|
|
Icons.search,
|
|
color: isDark ? Colors.grey[500] : Colors.grey,
|
|
),
|
|
suffixIcon: Icon(
|
|
Icons.chevron_right,
|
|
color: isDark ? Colors.grey[500] : Colors.grey[500],
|
|
),
|
|
border: InputBorder.none,
|
|
contentPadding: const EdgeInsets.symmetric(
|
|
horizontal: 16,
|
|
vertical: 12,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildFavoriteList(String category, FavoritesController controller) {
|
|
// 如果是"全部"标签,显示统一的收藏列表(点赞+笔记)
|
|
if (category == '全部') {
|
|
return const AllListPage();
|
|
}
|
|
|
|
// 如果是"点赞"标签,显示点赞内容管理器
|
|
if (category == '点赞') {
|
|
return const LikedPoetryManager();
|
|
}
|
|
|
|
// 如果是"笔记"标签,显示笔记列表
|
|
if (category == '笔记') {
|
|
return const LocalNotesList();
|
|
}
|
|
|
|
// 其他标签显示占位内容,但支持下拉刷新
|
|
return RefreshIndicator(
|
|
onRefresh: controller.refreshContent,
|
|
child: _buildPlaceholderContent(category),
|
|
);
|
|
}
|
|
|
|
Widget _buildPlaceholderContent(String category) {
|
|
final isDark = themeController.isDarkMode;
|
|
return Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(
|
|
Icons.category_outlined,
|
|
size: 64,
|
|
color: isDark ? Colors.grey[600] : Colors.grey[400],
|
|
),
|
|
const SizedBox(height: 16),
|
|
Text(
|
|
'$category功能暂未开放',
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
color: isDark ? Colors.grey[400] : Colors.grey[600],
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
Text(
|
|
'敬请期待后续更新',
|
|
style: TextStyle(
|
|
fontSize: 14,
|
|
color: isDark ? Colors.grey[500] : Colors.grey[500],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|