feat:合并待办和提醒功能
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'package:flisp_app/provider/todo_provider.dart';
|
||||
import 'package:flisp_app/service/todo_service.dart';
|
||||
import 'package:flisp_app/utils/notify_utils.dart';
|
||||
import 'package:flisp_app/widgets/awesome_dialog.dart';
|
||||
import 'package:flisp_app/widgets/todo_widget.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -21,6 +22,7 @@ class TodoPage extends StatefulWidget {
|
||||
|
||||
class TodoPageState extends State<TodoPage> {
|
||||
final TodoService todoService = TodoService();
|
||||
final NotifyService notifyService = NotifyService();
|
||||
|
||||
late List<Todo> _todos;
|
||||
TodoTab _currentTab = TodoTab.active;
|
||||
@@ -78,9 +80,13 @@ class TodoPageState extends State<TodoPage> {
|
||||
}
|
||||
|
||||
// 切换待办事项完成状态
|
||||
void _toggleTodo(Todo todo) {
|
||||
void _toggleTodo(Todo todo) async {
|
||||
await notifyService.cancelNotification(todo.id);
|
||||
|
||||
setState(() {
|
||||
todoService.updateTodoCompletion(todo, !todo.isCompleted);
|
||||
todo.isCompleted = !todo.isCompleted;
|
||||
todo.scheduledTime = null;
|
||||
todoService.updateTodo(todo);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -115,9 +121,22 @@ class TodoPageState extends State<TodoPage> {
|
||||
void _saveTodo(bool isEditing, Todo todo) async {
|
||||
late bool isSuccess;
|
||||
if (isEditing) {
|
||||
isSuccess = await todoService.updateTodo(todo);
|
||||
} else {
|
||||
isSuccess = await todoService.addTodo(todo);
|
||||
// 先删除
|
||||
await notifyService.cancelNotification(todo.id);
|
||||
await todoService.deleteTodo(todo);
|
||||
// 在重新新建
|
||||
todo.id = DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||
}
|
||||
|
||||
isSuccess = await todoService.addTodo(todo);
|
||||
|
||||
if (todo.scheduledTime != null) {
|
||||
await notifyService.scheduleNotification(
|
||||
id: todo.id,
|
||||
title: todo.title,
|
||||
body: todo.content,
|
||||
scheduledTime: todo.scheduledTime!,
|
||||
);
|
||||
}
|
||||
|
||||
setState(() {
|
||||
|
||||
Reference in New Issue
Block a user