From db4eb0963797e40ba8a339963171bb5dd6a96e26 Mon Sep 17 00:00:00 2001 From: clragon Date: Tue, 12 Nov 2024 20:18:27 +0100 Subject: [PATCH] fixed background db init --- lib/app/data/background.dart | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/app/data/background.dart b/lib/app/data/background.dart index 45041eb7..b222fba7 100644 --- a/lib/app/data/background.dart +++ b/lib/app/data/background.dart @@ -16,9 +16,11 @@ void executeBackgroundTasks() => Workmanager().executeTask( final logger = Logger('BackgroundTasks'); logger.info('Executing Task $task'); - AppStorage storage = await initializeAppStorage(cache: false); + AppStorage? storage; try { + storage = await initializeAppStorage(cache: false); + final cancelToken = createBackgroundCancelToken(task); cancelToken.whenCancel.then((e) { logger.info('Task $task was cancelled: ${e.error}'); @@ -43,7 +45,7 @@ void executeBackgroundTasks() => Workmanager().executeTask( logger.severe('Failed executing Task $task', e, stack); rethrow; } finally { - await storage.close(); + await storage?.close(); logger.info('Task $task completed'); } },