feat:增加待办排序UI功能

This commit is contained in:
2025-11-20 11:47:35 +08:00
parent 565b04e65d
commit b2260d139b
4 changed files with 101 additions and 10 deletions

View File

@@ -26,6 +26,7 @@ class TodoPageState extends State<TodoPage> {
late List<Todo> _todos;
TodoTab _currentTab = TodoTab.active;
late TodoSortMode _selectedMode = TodoSortMode.time;
// 获取过滤后的待办事项
List<Todo> get _activeTodos => getActiveTodos(_currentTab, _todos);
@@ -37,7 +38,13 @@ class TodoPageState extends State<TodoPage> {
@override
void initState() {
super.initState();
_todos = todoService.getAllTodos();
_refreshTodos();
}
void _refreshTodos() {
setState(() {
_todos = todoService.getAllTodos(_selectedMode);
});
}
@override
@@ -45,6 +52,7 @@ class TodoPageState extends State<TodoPage> {
return Column(
children: [
_buildTodoTabs(),
_buildTodoSegment(),
Expanded(child: _buildActiveTodoList(context)),
],
);
@@ -62,6 +70,36 @@ class TodoPageState extends State<TodoPage> {
);
}
Widget _buildTodoSegment() {
final colors = Theme.of(context).colorScheme;
return SegmentedButton<TodoSortMode>(
showSelectedIcon: false,
emptySelectionAllowed: false,
multiSelectionEnabled: false,
segments: [
ButtonSegment<TodoSortMode>(
value: TodoSortMode.time,
icon: Icon(Icons.access_time_filled, size: 16),
label: const Text('时间', style: TextStyle(fontSize: 12)),
),
ButtonSegment<TodoSortMode>(
value: TodoSortMode.priority,
icon: Icon(Icons.flag_outlined, size: 16,),
label: const Text('优先级', style: TextStyle(fontSize: 12)),
),
],
selected: {_selectedMode},
onSelectionChanged: (Set<TodoSortMode> newSelection) {
setState(() {
_selectedMode = newSelection.first;
});
_refreshTodos();
},
style: buildSegmentStyle(colors),
);
}
Widget _buildActiveTodoList(BuildContext context) {
return _activeTodos.isEmpty
? buildEmptyState(context, _currentTab)
@@ -142,9 +180,7 @@ class TodoPageState extends State<TodoPage> {
);
}
setState(() {
_todos = todoService.getAllTodos();
});
_refreshTodos();
if (isSuccess) {
showSuccessDialog(context, isEditing ? '更新成功' : '添加成功');
@@ -157,9 +193,7 @@ class TodoPageState extends State<TodoPage> {
await notifyService.cancelNotification(todo.id);
bool isSuccess = await todoService.deleteTodo(todo);
setState(() {
_todos = todoService.getAllTodos();
});
_refreshTodos();
if (isSuccess) {
showSuccessDialog(context, '删除成功');