'How to delete local database while uninstalling the flutter windows application?
I am using the DRIFT package (formerly known as MOOR) for local database and I want to delete the database file which is saved in local machine (Windows) as db.sqlite. How can I achieve this?
For testing I have created installation files for every new feature and while running each time the old database still exists in the local machine, giving me unwanted results.
Drift package for database. Drift documentation. Drift code :
// These imports are only needed to open the database
import 'dart:io';
import 'package:drift/drift.dart';
import 'package:drift/native.dart';
import 'package:path_provider/path_provider.dart';
import 'package:path/path.dart' as path;
import 'package:summa_app/database/program_location/program_location_dao.dart';
import 'package:summa_app/database/program_location/program_location_table.dart';
import 'package:summa_app/database/programs/program_dao.dart';
import 'package:summa_app/database/programs/program_table.dart';
part 'summa_database.g.dart';
@DriftDatabase(tables: [ProgramLocation, DbPrograms], daos: [ProgramLocationDao, ProgramsDao])
class SummaDatabase extends _$SummaDatabase {
// we tell the database where to store the data with this constructor
SummaDatabase() : super(_openConnection());
// you should bump this number whenever you change or add a table definition.
// Migrations are covered later in the documentation.
@override
int get schemaVersion => 1;
@override
Future<void> close() async{
await _openConnection().close();
return super.close();
}
}
LazyDatabase _openConnection() {
// the LazyDatabase util lets us find the right location for the file async.
return LazyDatabase(() async {
// put the database file, called db.sqlite here, into the documents folder
// for your app.
final dbFolder = await getApplicationDocumentsDirectory();
final file = File(path.join(dbFolder.path, 'db.sqlite'));
return NativeDatabase(file);
});
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|