Answers for "flutter list order by"

3

order list dart

void main() {
  List<Map<String, dynamic>> myProducts = [
    {"name": "Shoes", "price": 100},
    {"name": "Pants", "price": 50},
    {"name": "Book", "price": 10},
    {"name": "Lamp", "price": 40},
    {"name": "Fan", "price": 200}
  ];

  // Selling price from low to high
  myProducts.sort((a, b) => a["price"].compareTo(b["price"]));
  print('Low to hight in price: $myProducts');

  // Selling price from high to low
  myProducts.sort((a, b) => b["price"].compareTo(a["price"]));
  print('High to low in price: $myProducts');
}
Posted by: Guest on August-26-2021
2

sort a custom list flutter

someObjects.sort((a, b) => a.someProperty.compareTo(b.someProperty));
Posted by: Guest on November-27-2020
7

sort list dart

List<int> nums = [13, 2, -11];
nums.sort();
print(nums);  // [-11, 2, 13]
Posted by: Guest on March-03-2020
0

flutter sort list

someObjects.sort();

// By object property value
someObjects.sort((a, b) => a.someProperty.compareTo(b.someProperty));

// To reverse sort, just swab a and b
someObjects.sort((a, b) => b.someProperty.compareTo(a.someProperty));
Posted by: Guest on October-17-2021

Browse Popular Code Answers by Language