How to make a downloader that would run for some time? #1049
-
|
Assume I have a list of items and I want to download some content to it. I have tried the following: Below is a minimal implementation with some classes that I don't think are important missing. class Item {
final String name;
final List<int>? content;
final DownloadState downloadState; // pending, inProgress, complete
}
final itemListController = StateNotifierProvider<ItemListController, List<Item>>(
(ref) => [
// Dummy data
Item('item1', const DownloadState.pending());
Item('item2', const DownloadState.pending());
Item('item3', const DownloadState.pending());
Item('item4', const DownloadState.pending());
];
);
final downloadController = StateNotifierProvider<DownloadController, DownloadControllerState>(
(ref) {
// Needs items to know which is pending
//
// I would like to update the list to show what is being downloaded
// and what is pending.
//
// But if i update itemList it would destroy downloadController
// as this depends on itemList
return DownloadController(ref.watch(itemListController));
};
);Thanks in advance. |
Beta Was this translation helpful? Give feedback.
Answered by
rrousselGit
Jan 1, 2022
Replies: 1 comment 1 reply
-
|
You probably don't want to use StateNotifierProvider<DownloadController, State>((ref) {
final controller = DownloadController();
ref.listen<List<Item>>(itemListController, (_, itemList) {
// do something with itemList
});
return controller;
}); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
m-haisham
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You probably don't want to use
watchand instead want to uselisten