import 'package:flutter/material.dart'; import 'package:get/get.dart'; import '../../constants/app_constants.dart'; class FavoritesController extends GetxController { var categories = ['全部', '点赞', '笔记', '推送', '每日一句'].obs; var isGridView = true.obs; var currentTabIndex = 0.obs; var searchQuery = ''.obs; var sortByTime = true.obs; // true: 按时间排序, false: 按分类排序 var likesFirst = true.obs; // true: 点赞在前, false: 笔记在前 void toggleViewMode() { isGridView.value = !isGridView.value; } void setCurrentTabIndex(int index) { currentTabIndex.value = index; } void setSearchQuery(String query) { searchQuery.value = query; } Future refreshContent() async { await Future.delayed(const Duration(milliseconds: 500)); Get.snackbar('提示', '内容已刷新'); } void showFilterOptions(BuildContext context) { 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('按时间排序'), trailing: Obx( () => Icon( sortByTime.value ? Icons.radio_button_checked : Icons.radio_button_unchecked, color: AppConstants.primaryColor, ), ), onTap: () { Navigator.pop(context); sortByTime.value = true; Get.snackbar('提示', '已按时间排序'); // 触发排序更新 update(); }, ), ListTile( leading: const Icon(Icons.title), title: const Text('按分类排序'), trailing: Obx( () => Icon( !sortByTime.value ? Icons.radio_button_checked : Icons.radio_button_unchecked, color: AppConstants.primaryColor, ), ), onTap: () { Navigator.pop(context); sortByTime.value = false; Get.snackbar('提示', '已按分类排序'); // 触发排序更新 update(); }, ), const Divider(), ListTile( leading: const Icon(Icons.swap_vert), title: Text(likesFirst.value ? '点赞在前' : '笔记在前'), trailing: Obx( () => Icon(Icons.swap_vert, color: AppConstants.primaryColor), ), onTap: () { Navigator.pop(context); likesFirst.value = !likesFirst.value; Get.snackbar('提示', likesFirst.value ? '点赞在前' : '笔记在前'); // 触发顺序更新 update(); }, ), ], ), ), ); } void navigateToSearch() { Get.toNamed( '/search', arguments: searchQuery.value.isEmpty ? null : searchQuery.value, ); } void navigateToCollectNotes() { Get.toNamed('/collect-notes'); } }