I have created an isar helper class for all my calls to isar. I'm trying to build generic functions. For example:
Future<List<dynamic>> listModel(String pModelType) async {
final isar = await _db;
return isar.${pModelType}.where().findAll();
}
this doesn't work but I'm just trying to illustrate what I'm trying to do. I have it working with the following code expample but I'm wondering if there's a cleaner way to do this?
working code:
Future<IsarCollection> getIsarModel(Isar pIsar, String pModelType) async {
if(pModelType == "mymodel1") {
return pIsar.mymodel1;
} else if (pModelType == "mymodel2"){
return pIsar.mymodel2;
} else {
return pIsar.mymodel3;
}
}
Future<List<dynamic>> listModel(String pModelType) async {
final isar = await _db;
final isarModel = await getIsarModel(isar, pModelType);
return isarModel.where().findAll();
}