1

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();       
  }  

J-L
  • 189
  • 1
  • 8
  • try using `getCollectionByNameInternal` – Md. Yeasin Sheikh Mar 24 '23 at 19:11
  • I saw that one but it doesn't work. dart invalid_use_of_protected_member] [I] The member 'getCollectionByNameInternal' can only be used within instance members of subclasses of 'package:isar/src/isar.dart'. – J-L Mar 24 '23 at 19:21

0 Answers0