我有一个提供者,我有一份任务清单,那就是,在某个具体时间之后,我想执行一种方式,把任务从名单上删除。
class TaskProvider extends ChangeNotifier {
final List<TaskModel> _tasks = [];
List<TaskModel> get tasks => _tasks;
final String _tasksKey = "tasks";
Future<void> addTask({
required String task,
required DateTime scheduledTime,
required TaskStatus status,
}) async {
scheduleTaskManager(task, scheduledTime);
_tasks.add(
TaskModel(task: task, limitDateTime: scheduledTime, status: status));
notifyListeners();
}
Future<void> clearTasks() async {
dev.log("Tasks deleted!");
tasks.clear();
notifyListeners();
}
}
通常,我可以通过进口和打电话清楚的Tasks(Task)来从《国际不动产合同》中做到这一点,但我无法与工作管理者一起使用,我的理解是,工作管理程序是分开的。
因此,我要问,如何利用工作管理改变外部价值?
这是退步。 派遣国:
@pragma(
vm:entry-point ) // Mandatory if the App is obfuscated or using Flutter 3.1+
void callbackDispatcher() {
Workmanager().executeTask((task, inputData) {
dev.log(
"Native called background task: $task"); //simpleTask will be emitted here.
dev.log("Time limit, clearing all tasks!");
//Call clearTasks() or find a way to be able to modify the list of tasks of TaskProvider.
return Future.value(true);
});
}
虽然我最初尝试过说清楚的Tasks,但我可以看到任务标志被删除! 我没有看到这项任务被删除。
@pragma(
vm:entry-point ) // Mandatory if the App is obfuscated or using Flutter 3.1+
void callbackDispatcher() {
Workmanager().executeTask((task, inputData) {
dev.log(
"Native called background task: $task"); //simpleTask will be emitted here.
dev.log("Time limit, clearing all tasks!");
TaskProvider taskProvider = TaskProvider();
taskProvider.clearTasks();
return Future.value(true);
});
}
My idea is to modify various things in the task list, such as deleting them, updating the task status, etc. All this data comes from my provider.