objectboxflutter-objectbox

Query with order, places accented value at the end


In my flutter project, I use box.query(myquery)..order(Kategoriak_.cikkcsoportnev).build(), but my Áramfejlesztők, szivattyúk category is at the end of the list.

How can I order it correctly, so Á would come after A, not at the end?

enter image description here

I am using objectbox: ^1.7.0


Solution

  • I ended up implementing a short function using a Hungarian string array. It doesn't handle double and triple letters, but it's fine in most cases.

    I didn't want to double my fileds, because I have a big database.

    My solution:

      const List<String> hunABC = [
        "A", "a", "Á", "á", "B", "b", "C", "c", "D", "d",
        "E", "e", "É", "é", "F", "f", "G", "g", "H", "h", "I","i", "Í", "í", 
        "J", "j", "K", "k", "L", "l", 
        "M", "m", "N", "n", "O", "o", "Ó", "ó", "Ö", "ö", "Ő", "ő",
        "P", "p", "Q", "q", "R", "r", "S", "s", "T", "t", "U", "u", 
        "Ú", "ú", "Ü", "ü", "Ű", "ű", 
        "V", "v", "W", "w", "X", "x", "Y", "y", "Z", "z"
      ];
      
    
      int hunCompare(int num, int i, String input, int charNum) {
        if (num == -1)
        {
          if (input[charNum] == hunABC[i][0]) {
            return i;
          }
    
          return -1;
        }
        
        return num;  
      }
    

    And my Comparable implementation for my class:

      @override
      int compareTo(Kategoriak other) {
        int otherNum = -1;
        int inputNum = -1;
        int charNum = 0;
    
        for (int i = 0; i < hunABC.length; i++)
        {
          inputNum = hunCompare(inputNum, i, cikkcsoportnev, charNum);
          otherNum = hunCompare(otherNum, i, other.cikkcsoportnev, charNum);
    
          if (i == hunABC.length) {
            if (inputNum == -1) inputNum = hunABC.length+1;
            if (otherNum == -1) otherNum = hunABC.length+1;
          }
    
          if (inputNum > -1 && otherNum > -1) {
            if (inputNum < otherNum) return -1;
            if (inputNum > otherNum) return 1;
            if (inputNum == otherNum) {
              if (cikkcsoportnev.length > charNum+1
              && other.cikkcsoportnev.length > charNum+1) {
                charNum += 1;
                inputNum = -1;
                otherNum = -1;
                i = -1;
              } else { return 0; }
            }
          }
        }
    
        return 0;
      }