mirror of
https://github.com/wger-project/flutter.git
synced 2026-11-29 01:18:35 +01:00
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) <noreply@anthropic.com>
65 lines
1.8 KiB
Dart
65 lines
1.8 KiB
Dart
import 'package:drift/drift.dart';
|
|
import 'package:drift_flutter/drift_flutter.dart';
|
|
import 'package:logging/logging.dart';
|
|
|
|
part 'ingredients_database.g.dart';
|
|
|
|
@DataClassName('IngredientTable')
|
|
class Ingredients extends Table {
|
|
const Ingredients();
|
|
|
|
IntColumn get id => integer()();
|
|
|
|
TextColumn get data => text()();
|
|
|
|
/// The date when the ingredient was last fetched from the server
|
|
DateTimeColumn get lastFetched => dateTime()();
|
|
}
|
|
|
|
@DriftDatabase(tables: [Ingredients])
|
|
class IngredientDatabase extends _$IngredientDatabase {
|
|
final _logger = Logger('IngredientDatabase');
|
|
|
|
IngredientDatabase() : super(_openConnection());
|
|
|
|
// Named constructor for creating in-memory database
|
|
IngredientDatabase.inMemory(super.e);
|
|
|
|
/// Note that this needs to be bumped if the JSON response from the server changes
|
|
@override
|
|
int get schemaVersion => 2;
|
|
|
|
/// There is not really a migration strategy. If we bump the version
|
|
/// number, delete everything and recreate the new tables. The nutrition provider
|
|
/// will fetch everything as needed from the server
|
|
@override
|
|
MigrationStrategy get migration => MigrationStrategy(
|
|
onUpgrade: (m, from, to) async {
|
|
// no-op, but needs to be defined
|
|
return;
|
|
},
|
|
beforeOpen: (openingDetails) async {
|
|
if (openingDetails.hadUpgrade) {
|
|
final m = createMigrator();
|
|
for (final table in allTables) {
|
|
await m.deleteTable(table.actualTableName);
|
|
await m.createTable(table);
|
|
}
|
|
}
|
|
},
|
|
);
|
|
|
|
Future<void> deleteEverything() {
|
|
return transaction(() async {
|
|
for (final table in allTables) {
|
|
_logger.info('Deleting db cache table ${table.actualTableName}');
|
|
await delete(table).go();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
QueryExecutor _openConnection() {
|
|
return driftDatabase(name: 'ingredients');
|
|
}
|