“Urutkan daftar DART” Kode Jawaban

Daftar Pesanan 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');
}
askMe!

Daftar Sort Objects Garut Dart

objects.sort((a, b) {
  return a.value['name'].toString().toLowerCase().compareTo(b.value['name'].toString().toLowerCase());
});
To reverse it you could do b.someProperty.compareTo(a.someProperty). Or sort it and then use .reversed
Hilarious Hedgehog

daftar sortir flutter

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));
Lonely Louse

Urutkan daftar DART

List<int> nums = [13, 2, -11];
nums.sort();
print(nums);  // [-11, 2, 13]
Expensive Elk

Daftar Dart Sorts berdasarkan Nilai

someObjects.sort((a, b) => a.someProperty.compareTo(b.someProperty));
BlackDragonBE

Jawaban yang mirip dengan “Urutkan daftar DART”

Pertanyaan yang mirip dengan “Urutkan daftar DART”

Lebih banyak jawaban terkait untuk “Urutkan daftar DART” di Dart

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya