I've been struggling for a while to set up a sqlite database with sqflite in flutter. Code is producing a new instance of the database every time I call the getter method for a database. Here is the code:
class DatabaseProvider {
DatabaseProvider._();
static final DatabaseProvider dbProvider = DatabaseProvider._();
static Database? _database;
Future<Database> get database async => _database ??= await _createDatabase();
}
...
_createDatabase()do in your code? Does it initialize the_database?await openDatabase()and returningFuture<Database>_database?, something like:_database = await openDatabase()?_databasebecause_databaseis assigned to_createDatabase()and that function is returningDatabaseobject. I tried to change getter method toif (_database != null) return _database!and_database = await _createDatabase(). But still same. Every time I try to insert to database I get new database instance with only one entry.Future<Database> get database async { if (_database == null) { _database = await _createDatabase(); } return _database; }?