moboldi
moboldi

Reputation: 59

How to order a List of Objects by an int value in Flutter?

I've got a List of Objects (Orders) in my Flutter App and I need to order them by one value called tourPos. Is there a way to accomplish this with flutter?

This it the Entity I need to sort. As already mentioned, it should be ordered by tourId. I will change these values after a calculation and need to display them the right way.

{
        "kundenId": 0,
        "kundenbezeichnung": "string",
        "kundenNr": "string",
        "tourHinweis": "string",
        "nachname": "string",
        "vorname": "string",
        "strasse": "string",
        "plz": "string",
        "ort": "string",
        "telefon1": "string",
        "telefon2": "string",
        "hatLieferAdresse": true,
        "schluesselVorhanden": true,
        "schluesselInfo": "string",
        "zahlungsart": "string",
        "bruttoSumme": 0,
        "menge": 0,
        "tourPos": 0,
        "positionen": [
          {
            "kundenId": 0,
            "belposId": 0,
            "artikelId": 0,
            "menge": 0,
            "artikelbezeichnung": "string",
            "artikelNr": "string",
            "warengruppe": "string",
            "bestellTypInfo": "string",
            "bruttopreis": 0
          }
        ]
      }

Upvotes: 0

Views: 41

Answers (1)

Hazar Belge
Hazar Belge

Reputation: 1089

Let's call your list "myList". Then you can do:

myList.sort((Object a, Object b) => a.tourId.compareTo(b.tourId))

Upvotes: 1

Related Questions