Search code examples
databasesqliteflutterdartsqflite

Import or export database by user in Flutter


I used SQFLite to create a database. Now I want the user to be able to import/export their own database to the application


Solution

  • A SQLite database is a file in the file system identified by a path. If relative, this path is relative to the path obtained by getDatabasesPath(), which is the default database directory on Android and the documents directory on iOS.

    So, as long as you close all database connections, you should be able to copy this file to somewhere and take an existing file from somewhere and overwrite your database. That is the easiest way to import/export the data completely.

    If you want to actually merge data on import instead of overwriting, I think you will have to write that logic yourself.