Closed Nico04 closed 5 months ago
If I understand you correctly, I think you can accomplish that relatively easily by creating a global object containing a map of String (taskId) and ValueNotifier
If you want a more conventional polling approach you can use the database (see docs).
Thanks for your quick answer. That's exactly what I have done (Map<String, Status>), it works quite well while app is running. But after a cold start, because no updates are emited right away (for instance, progress can be long at a certain state), widget status is incorrect (there is a notification running, but map is empty). Any idea how to handle that case ?
Take a look at the docs on tracking tasks in a database. On startup, call trackTasks
and make sure to also call resumeFromBackground
to fetch pending updates. Once they have completed, your database
will be an accurate reflection of current state, and you can set your Map to align with that, then update your map based on incoming status updates as you already do.
You're right, that was the solution. I managed to restore full tasks statuses with theses methods, thanks. I knew database existed, but I thought it was useful only when needed to keep track of completed tasks, whereas it's also needed for running tasks. I think the text "even after they have completed" lost me here. Anyway : thanks again, your lib is awesome !
Currently we can listen to updates using the updates stream or using callbacks, that great. I trying to manage download progression & status that is displayed on a list of widgets. But because updates stream emits TaskUpdate objects for all tasks, it's currently not direct to get the status of all actives Task, or of a specific Task (using id ?), so widgets can display current download status, while being stateless (stateless is important so status is hanlded globally and works even after app restarts).
So it could be very handy to get a TaskUpdate object of a specific Task (or a list for all active tasks), that works even after a cold app start, don't you think ?
(Meanwhile I'll try to develop a system to keep updates in memory for all tasks, so it can be read anytime)