Flutter workManager callbackDispatcher starts and calls the below function. But never finish it.
static Future<List<Map<String, dynamic>>> getItems() async {
debugPrint("In getItems");
final db = await DatabaseHelper.db();
final a = db.query('items', orderBy: "id");
debugPrint("post query, before return");
return a;
}
If I call the function onPressed
it works fine.
If I call the same function from callbackDispatcher
it Start and print "In getItems" but not print "post query, before return".
Getting no error message either.
I have registered it as one off task.
Workmanager().registerOneOffTask("task-identifier", "simpleTask");
Future<void> callbackDispatcher() async {
var sm= SmsSender();
Workmanager().executeTask((task, inputData) {
try {
sm.getAlertBookings();
smsCompleter.complete();
} catch(err) {
print(err.toString());
throw Exception(err);
}
return Future.value(true);
});
await smsCompleter.future;
}
What is causing this issue and how can I fix it?
I tested the same function onPressed
it worked fine. callbackDispatcher Start the function but do not finish it.