Debugger throws pause in a runtime
AdamRiedl opened this issue · 4 comments
Hello I'am having a problem with the downloader package and I don't know if it is error in my configuration or if it is a bug in the package, so I'am looking for help in here.
This code snipet is how I'am using the package. I am using it in Service so the User is not calling it manually with some sort of button but it is called automatically upon the first boot of the application.
Future<bool> _fetchDatabaseFromHttp() async {
try {
bool _newVersion = await _isAvailableNewerDatabaseVersion();
// if there is new version of data fetch it
if (_newVersion) {
final saveDir =
dirname(await DatabaseHelper.instance.getDatabasePath());
// If database exists than erase it
final databaseFile = File(saveDir);
if (await databaseFile.exists()) {
await databaseFile.delete();
}
try {
final task = DownloadTask(
url: '*url*',
filename: '*file.db*',
requiresWiFi: true,
retries: 2,
);
//here it gets stuck
await FileDownloader().download(task);
} catch (e) {
print('Error fetching database: $e');
}
} else {
return false;
}
} catch (e) {
print('Error fetching database: $e');
return false; // Signal that the process failed
}
return true;
}
The app will return this in debug window and than it gets Paused by Debuger:
"I/WM-WorkerWrapper(19335): Worker result SUCCESS for Work [ id=48440236-4c09-43ba-a778-448e9e4c69f3, tags={ com.bbflight.background_downloader.DownloadTaskWorker, BackgroundDownloader, taskId=1383361945, group=default } ]"
If I resume the App manually or by F5, the Downloader works like a charm and even if the new version function gets triggered the Downloader downloads the new version and works just fine. So it is just matter of fresh boot with no data.
After i resume the Debugger the Downloader throws:
"I/BackgroundDownloader(19335): Flutter method not implemented
D/TaskWorker(19335): Could not post status update -> storing locally
I/BackgroundDownloader(19335): Flutter method not implemented
D/TaskWorker(19335): Could not post status update -> storing locally"
and than works as normal.
Any help or information on how to solve this issue will help.
Thank you.
It's because a service can run without the app being active, and as a result the downloader cannot post its updates to the app. That's what the message says. Instead, it will store the message locally (i.e. without the need for the app) and you are expected to pick up those messages when your app restarts (i.e. moves to the foreground) using resumeFromBackground
. See here.
The download will complete as normal, but you are not getting the status update until you call resumeFromBackground
. You should therefore use a listener or callback instead of the simple await
approach - that won't work properly for your situation.
Hi, thanks for the info i tried to rework the fetch function, even tried to move the fetch logic in the main for testing if I can get it running. But it just wont start even with the added listener.
try {
final subscription = FileDownloader().updates.listen((update) {
if (update is TaskStatusUpdate) {
print(
'Status update for ${update.task} with status ${update.status}');
} else if (update is TaskProgressUpdate) {
print(
'Progress update for ${update.task} with progress ${update.progress}');
}
});
await FileDownloader().resumeFromBackground();
// Define your download task
final task = DownloadTask(
url: '**',
filename: '**',
requiresWiFi: true,
retries: 2,
updates: Updates.statusAndProgress,
);
// Ensure the task is enqueued
final successFullyEnqueued = await FileDownloader().enqueue(task);
if (successFullyEnqueued) {
print('Download task enqueued successfully');
} else {
print('Failed to enqueue the download task');
}
} catch (e) {
// Catch any errors that happen during the download process
print('Error during download: $e');
}
as you can see i have implement it the enqueue with the resumeFromBackground but the downloader is still pausing. Maybe I dont get what exactly the listener should do. I mean is this enough to just have him there ? or does he needs something else or do I need to handle the subscription with some other Class. I dont have trackTasks and MyPersistentStorage there because i think that I dont need it because I am not saving the tasks in DB or anything similar.
Again any help is welcomed thank you so much.
This issue is stale because it has been open for 14 days with no activity.