skip to Main Content

I’m new to flutter and Isar. I have the following class

@collection
class RootWord {
  Id id = Isar.autoIncrement;

  @Index()
  late int subCategoryId;

  late String name;
  late List<Word> wordList;
  late bool hide;
}

I have a collection of RootWords and I’m trying to find all the RootWords that contain a certain Word in RootWord.wordList. I’m not familiar with quering lists in Isar so obviously my code is all wrong.

List<RootWord> findRootWords({required Isar isar, required String str) {
    return isar.rootWords.filter().wordListElement((q) =>  q.engWordContains(str, caseSensitive: false));
}

Thank you for helping me

2

Answers


  1. Chosen as BEST ANSWER

    This works for me.

    List<RootWord> findRootWords({required Isar isar, required String searchStr}) {
        return(isar.rootWords.filter().wordListElement((q) => q.engWordContains(searchStr, caseSensitive: false)).findAllSync());
    }
    

  2. I also recently started learning Isar. To begin with, make the Word class a separate collection, and then add IsarLink to the RootWord as in the documentation. After that you will be able to make queries

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search