I have this class:
class IsarHelperSiniestro {
late Isar isarInstance;
IsarHelperSiniestro() {
isarInstance = IsarService().db as Isar;
}
static IsarHelperSiniestro instance = IsarHelperSiniestro();
}
And this class:
class IsarService{
late Future<Isar> db;
IsarService(){
db = openDb();
}
Future<Isar> openDb() async {
final dir = await getApplicationDocumentsDirectory();
if(Isar.instanceNames.isEmpty){
return await Isar.open([UsuarioSchema, SiniestroSchema, ActaSchema], directory: dir.path, inspector: true);
}
return Future.value(Isar.getInstance());
}
}
But it is sending me the error shown in the screenshot:
My question is how do I make Future be passed to only Isar and pass it to the late Isar variable isarInstance.
Greetings!
You can use
.then
on FutureI prefer creating Future instance for this case,
And when I need to use it
await _db
.