icon优化

This commit is contained in:
Developer
2026-04-02 17:31:53 +08:00
parent 954d173329
commit 09fee0694c
34 changed files with 754 additions and 194 deletions

View File

@@ -27,6 +27,7 @@ class _FavoritesPageState extends State<FavoritesPage>
late TabController _tabController;
final controller = Get.put(FavoritesController());
final themeController = Get.find<ThemeController>();
final GlobalKey<AllListPageState> _allListKey = GlobalKey<AllListPageState>();
@override
void initState() {
@@ -38,6 +39,18 @@ class _FavoritesPageState extends State<FavoritesPage>
_tabController.addListener(() {
controller.setCurrentTabIndex(_tabController.index);
});
// 监听排序变化更新AllListPage
ever(controller.sortByTime, (bool newSortByTime) {
if (_allListKey.currentState != null && mounted) {
_allListKey.currentState!.sortByTime(newSortByTime);
}
});
ever(controller.likesFirst, (bool newLikesFirst) {
if (_allListKey.currentState != null && mounted) {
_allListKey.currentState!.toggleLikesFirst();
}
});
}
@override
@@ -58,22 +71,9 @@ class _FavoritesPageState extends State<FavoritesPage>
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),
),
],
backgroundColor: isDark ? const Color(0xFF1A1A1A) : Colors.white,
foregroundColor: isDark ? Colors.white : Colors.black87,
actions: _buildAppBarActions(controller),
),
body: Column(
children: [
@@ -88,29 +88,44 @@ class _FavoritesPageState extends State<FavoritesPage>
),
],
),
floatingActionButton: _buildFloatingButton(controller),
floatingActionButtonLocation: FloatingActionButtonLocation.miniEndFloat,
);
});
}
Widget _buildFloatingButton(FavoritesController controller) {
// 构建AppBar操作按钮
List<Widget> _buildAppBarActions(FavoritesController controller) {
final currentCategory =
controller.categories[controller.currentTabIndex.value];
final isDark = themeController.isDarkMode;
if (currentCategory != '笔记') {
return const SizedBox.shrink();
List<Widget> 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),
),
];
// 只在笔记页面显示添加笔记按钮
if (currentCategory == '笔记') {
actions.insert(
0,
IconButton(
icon: Icon(Icons.add, color: isDark ? Colors.white70 : null),
onPressed: () {
Get.to(const CollectNotesPage());
},
),
);
}
return FloatingActionButton(
onPressed: () {
Get.to(const CollectNotesPage());
},
child: const Icon(Icons.add),
backgroundColor: AppConstants.primaryColor,
heroTag: 'notes_fab',
elevation: 4,
);
return actions;
}
Widget _buildSearchBar(FavoritesController controller, bool isDark) {
@@ -122,7 +137,7 @@ class _FavoritesPageState extends State<FavoritesPage>
16,
),
decoration: BoxDecoration(
color: isDark ? Colors.grey[850] : Colors.grey[100],
color: isDark ? const Color(0xFF2A2A2A) : Colors.grey[100],
borderRadius: BorderRadius.circular(12),
),
child: TextField(
@@ -138,14 +153,14 @@ class _FavoritesPageState extends State<FavoritesPage>
},
decoration: InputDecoration(
hintText: '点按搜索全站诗词…',
hintStyle: TextStyle(color: isDark ? Colors.grey[500] : Colors.grey),
hintStyle: TextStyle(color: isDark ? Colors.grey[400] : Colors.grey),
prefixIcon: Icon(
Icons.search,
color: isDark ? Colors.grey[500] : Colors.grey,
color: isDark ? Colors.grey[400] : Colors.grey,
),
suffixIcon: Icon(
Icons.chevron_right,
color: isDark ? Colors.grey[500] : Colors.grey[500],
color: isDark ? Colors.grey[400] : Colors.grey[500],
),
border: InputBorder.none,
contentPadding: const EdgeInsets.symmetric(
@@ -158,9 +173,15 @@ class _FavoritesPageState extends State<FavoritesPage>
}
Widget _buildFavoriteList(String category, FavoritesController controller) {
final isDark = themeController.isDarkMode;
// 如果是"全部"标签,显示统一的收藏列表(点赞+笔记)
if (category == '全部') {
return const AllListPage();
return AllListPage(
key: _allListKey,
initialSortByTime: controller.sortByTime.value,
initialLikesFirst: controller.likesFirst.value,
);
}
// 如果是"点赞"标签,显示点赞内容管理器
@@ -176,6 +197,8 @@ class _FavoritesPageState extends State<FavoritesPage>
// 其他标签显示占位内容,但支持下拉刷新
return RefreshIndicator(
onRefresh: controller.refreshContent,
color: AppConstants.primaryColor,
backgroundColor: isDark ? const Color(0xFF2A2A2A) : Colors.white,
child: _buildPlaceholderContent(category),
);
}