我想使用颤振计算在 Firebase 上创建的总任务。有没有办法使用颤振来做到这一点我必须使用 java 和 swift 来完成这个功能。这就是我存储任务的方式,它们是由 firebase (ID) 生成的。
在实时数据库中完成
final tasksData = Provider.of<Tasks>(context);
final tasks = tasksData.tasks;
print(tasks.length); // total tasks
Future<void> fetchAndSetProducts() async {
const url = 'https://firebaselink.firebaseio.com/tasks.json';
try {
final response = await http.get(url);
final extractedData = json.decode(response.body) as Map<String, dynamic>;
final List<TodoList> loadedTasks = [];
extractedData.forEach((taskId, taskData) {
loadedTasks.add(TodoList(
id: taskId,
name: taskData['name'],
description: taskData['description'],
date: DateTime.parse(taskData['date']),
filename: taskData['filename'],
location: taskData['location'],
isCompleted: taskData['isCompleted'],
notes: taskData['notes'],
));
});
_tasks = loadedTasks;
notifyListeners();
} catch (error) {
print(error);
throw (error);
}
}
List<TodoList> _tasks = [];
List<TodoList> get tasks {
return [..._tasks];
}
更多问题在文本小部件中显示未来
Future<void> refreshTasks(BuildContext context) async {
await Provider.of<Tasks>(context,listen: false).totalCompletedTask();
}
Text( refreshTasks.toString())
错误:得到这个:关闭:(BuildContext)=>未来