fix: première arme invisible (race init DB) + recentrage des champs sous le clavier dans la modale d'édition d'arme
This commit is contained in:
@@ -10,6 +10,12 @@ import '../../core/constants/app_constants.dart';
|
||||
class DatabaseHelper {
|
||||
static DatabaseHelper? _instance;
|
||||
static Database? _database;
|
||||
// On met en cache le Future d'initialisation (et non la Database résolue)
|
||||
// pour éviter qu'un démarrage concurrent (les 4 onglets de l'IndexedStack
|
||||
// interrogent la base en même temps) ne lance plusieurs _initDatabase() en
|
||||
// parallèle. Sur une base fraîche, cela dédoublait onCreate et rendait la
|
||||
// toute première écriture peu fiable.
|
||||
static Future<Database>? _initFuture;
|
||||
|
||||
DatabaseHelper._internal();
|
||||
|
||||
@@ -19,7 +25,9 @@ class DatabaseHelper {
|
||||
}
|
||||
|
||||
Future<Database> get database async {
|
||||
_database ??= await _initDatabase();
|
||||
if (_database != null) return _database!;
|
||||
_initFuture ??= _initDatabase();
|
||||
_database = await _initFuture!;
|
||||
return _database!;
|
||||
}
|
||||
|
||||
@@ -552,5 +560,6 @@ class DatabaseHelper {
|
||||
final db = await database;
|
||||
await db.close();
|
||||
_database = null;
|
||||
_initFuture = null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user