fluttercommunity / fluttercommunity/flutter_downloader
Clean up api
- Dominant language
- Kotlin
- Stars
- 940
- Forks
- 561
- Avg merge
- 1h 18m
- Merged PRs (30d)
- 1
Description
While the flutter_downloader works fine, its API doesn't conform to idiomatic Dart standards in some cases.
That's why I'm currently [rewriting the Dart side of the plugin](https://github.com/marcelgarus/flutter_downloader/tree/master/lib/src) to make it more intuitive.
If implemented, this will be a breaking change and thus require a new major version update.
Especially the `DownloadTask`s are currently merely a wrapper around some data and not really actionable. I'm looking forward to rewriting the API so that something like the following is possible:
```dart
final task = await DownloadTask.create(
url: 'https://...',
downloadDirectory: getApplicationDirectory(),
);
task.updates.forEach(print);
task.onCompleted(() => task.openFile());
await Future.delayed(Duration(seconds: 3));
if (!task.isCompleted) {
print('Download takes longer than three seconds.');
}
await task.waitUntilCompleted();
```
By using `Stream`s rather than callbacks, it's possible to leverage Dart's strengths of async/await, applying stream transformations and support from the ecosystem. For example, one could easily build a Flutter widget like the following:
```dart
// inside a widget's State
DownloadTask task;
void _startDownload() {
setState(() => task = DownloadTask.create(…));
}
Widget build(BuildContext context) {
return Column(
children: [
RaisedButton(onPressed: _startDownload, child: Text('Start download')),
StreamBuilder(
stream: task?.updates ?? Stream.empty(),
builder: (context, _) => Text('Progress: ${task?.progress}'),
),
],
);
}
```
What do you think about this API?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.