From 7760efc9e3893c9ee0a8871f68a3f65ce996f5a2 Mon Sep 17 00:00:00 2001 From: John Weidner Date: Fri, 27 Mar 2026 15:56:37 -0500 Subject: [PATCH] fix: replace EOL sqlite3_flutter_libs with drift_flutter sqlite3_flutter_libs 0.6.0+eol no longer bundles the native SQLite library correctly on newer Android toolchains, causing a DriftRemoteException on startup (dlopen failed: libsqlite3.so not found). Replace it with drift_flutter which is the current recommended package for providing native SQLite to drift databases. Also suppress the StackFrame assertion error from the stack_trace package that was masking the real error. Co-Authored-By: Claude Opus 4.6 (1M context) --- lib/database/exercises/exercise_database.dart | 14 +++----------- lib/database/ingredients/ingredients_database.dart | 14 +++----------- lib/main.dart | 8 ++++++++ pubspec.yaml | 2 +- 4 files changed, 15 insertions(+), 23 deletions(-) diff --git a/lib/database/exercises/exercise_database.dart b/lib/database/exercises/exercise_database.dart index e7c36a6e7..826935ff4 100644 --- a/lib/database/exercises/exercise_database.dart +++ b/lib/database/exercises/exercise_database.dart @@ -1,10 +1,6 @@ -import 'dart:io'; - import 'package:drift/drift.dart'; -import 'package:drift/native.dart'; +import 'package:drift_flutter/drift_flutter.dart'; import 'package:logging/logging.dart'; -import 'package:path/path.dart' as p; -import 'package:path_provider/path_provider.dart'; import 'package:wger/database/exercises/type_converters.dart'; import 'package:wger/models/exercises/category.dart'; import 'package:wger/models/exercises/equipment.dart'; @@ -110,10 +106,6 @@ class ExerciseDatabase extends _$ExerciseDatabase { } } -LazyDatabase _openConnection() { - return LazyDatabase(() async { - final dbFolder = await getApplicationCacheDirectory(); - final file = File(p.join(dbFolder.path, 'exercises.sqlite')); - return NativeDatabase.createInBackground(file); - }); +QueryExecutor _openConnection() { + return driftDatabase(name: 'exercises'); } diff --git a/lib/database/ingredients/ingredients_database.dart b/lib/database/ingredients/ingredients_database.dart index 28f839ed1..0f325e62e 100644 --- a/lib/database/ingredients/ingredients_database.dart +++ b/lib/database/ingredients/ingredients_database.dart @@ -1,10 +1,6 @@ -import 'dart:io'; - import 'package:drift/drift.dart'; -import 'package:drift/native.dart'; +import 'package:drift_flutter/drift_flutter.dart'; import 'package:logging/logging.dart'; -import 'package:path/path.dart' as p; -import 'package:path_provider/path_provider.dart'; part 'ingredients_database.g.dart'; @@ -63,10 +59,6 @@ class IngredientDatabase extends _$IngredientDatabase { } } -LazyDatabase _openConnection() { - return LazyDatabase(() async { - final dbFolder = await getApplicationCacheDirectory(); - final file = File(p.join(dbFolder.path, 'ingredients.sqlite')); - return NativeDatabase.createInBackground(file); - }); +QueryExecutor _openConnection() { + return driftDatabase(name: 'ingredients'); } diff --git a/lib/main.dart b/lib/main.dart index a13d7afb1..1cc80bcc9 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -119,6 +119,14 @@ void main() async { // Catch errors that happen outside of the Flutter framework (e.g., in async operations) PlatformDispatcher.instance.onError = (error, stack) { + // Skip the StackFrame assertion error from the stack_trace package. + // This is a known Flutter framework issue where async gap markers in stack + // traces cause an assertion failure in StackFrame.fromStackTraceLine. + if (error is AssertionError && error.toString().contains('asynchronous gap')) { + logger.warning('Suppressed StackFrame assertion error (known Flutter issue)'); + return true; + } + logger.severe('Error caught by PlatformDispatcher.instance.onError: $error'); logger.severe('Stack trace: $stack'); diff --git a/pubspec.yaml b/pubspec.yaml index 036307e83..9a4316347 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -63,7 +63,7 @@ dependencies: rive: ^0.13.20 riverpod_annotation: ^4.0.0 shared_preferences: ^2.5.3 - sqlite3_flutter_libs: ^0.6.0+eol + drift_flutter: ^0.2.8 table_calendar: ^3.0.8 url_launcher: ^6.3.2 version: ^3.0.2