feat: add external path support
Add support for Floor to set a external path to load/save database. App need to have storage permission managed by Permissions Manager.
Future<AppDatabase> get appDatabase async {
String externalPath = await ExternalPath.getExternalStoragePublicDirectory(
ExternalPath.DIRECTORY_DOCUMENTS,
);
var dir = Directory(p.join(externalPath, 'My App'));
if (!dir.existsSync()) {
dir.create(recursive: true);
}
return $FloorAppDatabase.databaseBuilder(p.join(dir.path, DATABASE_NAME)).build();
}
I like this PR. For most apps, the database should probably not be stored where this package wants to store it - path_provider.getApplicationSupportDirectory() would be better in most cases. The sqflite documentation says as much, and suggests not using getDatabasesPath() in favour of using path_provider directly, and constructing your own database path to pass into the API.
@stephanmantel Seems good to enough to merge. What do you think?
Actually, you can just do this:
sqfliteDatabaseFactory.setDatabasesPath(...);