-2

i want sort list bellow by price low to high

i want sort list bellow by price low to high i want sort list bellow by price low to high i want sort list bellow by price low to high i want sort list bellow by price low to high

getProductsList() {
    List list = [];
    list.add({
      "id": "1",
      "name": "sssss",
      "imageUrl": "assets/images/Frozen Food.jpg",
      "description": "qwerfghjhgfdsaasdfghnjmhgfdsa",
      "price": "11",
      "quantity": "1",
      "isLiked": "false",
      "max": "5"
    });
    list.add({
      "id": "2",
      "name": "sssss",
      "imageUrl": "assets/images/Frozen Food.jpg",
      "description": "qwerfghjhgfdsaasdfghnjmhgfdsa",
      "price": "112",
      "quantity": "1",
      "isLiked": "true",
      "max": "5"
    });
    list.add({
      "id": "3",
      "name": "sssss",
      "imageUrl": "assets/images/Frozen Food.jpg",
      "description": "qwerfghjhgfdsaasdfghnjmhgfdsa",
      "price": "114",
      "quantity": "1",
      "isLiked": "true",
      "max": "10"
    });
    list.add({
      "id": "4",
      "name": "sssssssssssssssssssssssssssssssssssssssssssssssssssssssszzzzz",
      "imageUrl": "assets/images/Frozen Food.jpg",
      "description": "qwerfghjhgfdsaasdfghnjmhgfdsa",
      "price": "11",
      "quantity": "1",
      "isLiked": "false",
      "max": "1"
    });
    list.add({
      "id": "5",
      "name": "sssss",
      "imageUrl": "assets/images/Frozen Food.jpg",
      "description": "qwerfghjhgfdsaasdfghnjmhgfdsa",
      "price": "110",
      "quantity": "1",
      "isLiked": "false",
      "max": "15"
    });
    return list;
  }
1
  • Please provide some code that you tried not a sample of the list want to sort Commented Oct 14, 2019 at 9:16

2 Answers 2

2

You could do this:

list.sort((a, b) => a['price'].compareTo(b['price']));
Sign up to request clarification or add additional context in comments.

Comments

0

you can try this-:

 list.sort((ListModel a,ListModel b)=>a.getprice().compareTo(b.getprice())); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.