mirror of
https://github.com/haorendashu/nowser.git
synced 2025-12-18 18:14:21 +01:00
fix download status not update bug
This commit is contained in:
@@ -13,6 +13,10 @@ class DownloadProvider extends ChangeNotifier {
|
|||||||
|
|
||||||
Future<void> reloadData() async {
|
Future<void> reloadData() async {
|
||||||
_allRecords = await fileDownloader.database.allRecords();
|
_allRecords = await fileDownloader.database.allRecords();
|
||||||
|
_allRecords.sort((task1, task2) {
|
||||||
|
return task2.task.creationTime.millisecondsSinceEpoch -
|
||||||
|
task1.task.creationTime.millisecondsSinceEpoch;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> init() async {
|
Future<void> init() async {
|
||||||
@@ -27,24 +31,21 @@ class DownloadProvider extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> pauseDownload(DownloadTask downloadTask) async {
|
Future<void> pauseDownload(DownloadTask downloadTask) async {
|
||||||
fileDownloader.pause(downloadTask);
|
await fileDownloader.pause(downloadTask);
|
||||||
await reloadData();
|
await reloadData();
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> resumeDownload(DownloadTask downloadTask) async {
|
Future<void> resumeDownload(DownloadTask downloadTask) async {
|
||||||
fileDownloader.resume(downloadTask);
|
await fileDownloader.resume(downloadTask);
|
||||||
await reloadData();
|
await reloadData();
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> startDownload(String url, String fileName) async {
|
Future<void> startDownload(String url, String fileName) async {
|
||||||
var downloadDir = await getApplicationDocumentsDirectory();
|
// var downloadDir = await getApplicationDocumentsDirectory();
|
||||||
|
// var downloadDirPath = downloadDir.absolute.path;
|
||||||
var downloadDirPath = downloadDir.absolute.path;
|
|
||||||
|
|
||||||
// print("url $url fileName $fileName downloadDirPath $downloadDirPath");
|
// print("url $url fileName $fileName downloadDirPath $downloadDirPath");
|
||||||
|
|
||||||
final task = DownloadTask(
|
final task = DownloadTask(
|
||||||
url: url,
|
url: url,
|
||||||
filename: fileName,
|
filename: fileName,
|
||||||
@@ -56,7 +57,7 @@ class DownloadProvider extends ChangeNotifier {
|
|||||||
allowPause: true,
|
allowPause: true,
|
||||||
);
|
);
|
||||||
|
|
||||||
fileDownloader.download(
|
await fileDownloader.download(
|
||||||
task,
|
task,
|
||||||
onProgress: (progress) {
|
onProgress: (progress) {
|
||||||
print('Progress: ${progress * 100}%');
|
print('Progress: ${progress * 100}%');
|
||||||
@@ -64,9 +65,7 @@ class DownloadProvider extends ChangeNotifier {
|
|||||||
},
|
},
|
||||||
onStatus: (status) {
|
onStatus: (status) {
|
||||||
print('Status: $status');
|
print('Status: $status');
|
||||||
if (status == TaskStatus.running) {
|
reloadData();
|
||||||
reloadData();
|
|
||||||
}
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user