fluttercommunity / fluttercommunity/flutter_downloader

Task filename and savedDir isn't updated when using saveInPublicStorage (Android)

Open
#941 12 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Kotlin
Stars
940
Forks
561
Avg merge
1h 18m
Merged PRs (30d)
1

Description

**Describe the bug**
When downloading a file to the public downloads folder using the saveInPublicStorage= true, the task properties aren't updated.
So when the finished callback comes back and I wan't to open the file, FlutterDownloader.open(taskId) won't work.

**To Reproduce**

Steps to reproduce the behavior:
1. Download a file

```
final taskId = await FlutterDownloader.enqueue(
url: urlString,
savedDir: path!,
headers: {'Cookie': cookies},
showNotification: true,
openFileFromNotification: true,
saveInPublicStorage: Platform.isAndroid ? true : false,
);
```

2. Try to open fhe file from within portListener from callback
```
IsolateNameServer.registerPortWithName(_port.sendPort, 'downloader_send_port');
_port.listen((message) {
String id = message[0];

Future.delayed(const Duration(seconds: 1), () {
FlutterDownloader.loadTasksWithRawQuery(query: "SELECT * FROM task WHERE task_id='$id'").then((tasks) {
if (tasks == null || tasks.isEmpty) return;

final task = tasks.first;
final taskFilename = task.filename;
final taskSavedDir = task.savedDir;

// here filename and savedDir are not correct
FlutterDownloader.open(taskId: id).then((value) => {debugPrint('Open file: $value')});
});
});
});
```

**Expected behavior**

The task should (like the notification) have the correct filename and saved dir to let FlutterDownloader.open work

In [DownloadWorker.kt](https://github.com/fluttercommunity/flutter_downloader/blob/master/android/src/main/kotlin/vn/hunghd/flutterdownloader/DownloadWorker.kt) line 387ff. the taskDao.update isn't run with the new filename

**Device information:**

- Device: Android
- OS: Android v13
- plugin version v1.11.6

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.