Search
 
SCRIPT & CODE EXAMPLE
 

DART

dart sort list by date

products.sort((a,b) {
    return a.compareTo(b);
});
 
products.sort((a,b) => a.compareTo(b));
Comment

how to sort and order a list by date in flutter

import 'package:intl/intl.dart';

void main() {
  List products = [
    "2019-11-25 00:00:00.000",
    "2019-11-22 00:00:00.000",
    "2019-11-22 00:00:00.000",
    "2019-11-24 00:00:00.000",
    "2019-11-23 00:00:00.000"
  ];
  List<DateTime> newProducts = [];
  DateFormat format = DateFormat("yyyy-MM-dd");

  for (int i = 0; i < 5; i++) {
    newProducts.add(format.parse(products[i]));
  }
  newProducts.sort((a,b) => a.compareTo(b));

  for (int i = 0; i < 5; i++) {
    print(newProducts[i]);
  }
}
Comment

PREVIOUS NEXT
Code Example
Dart :: flutter print http response 
Dart :: flutter container image overlay 
Dart :: flutter auto size text 
Dart :: srring reverse dart 
Dart :: how to refresh a listview in flutter 
Dart :: uinstall php server on ubuntu 
Dart :: dart key value pair list 
Dart :: ClipRRect for flutter 
Dart :: dart inheritance 
Dart :: using flutter google places 
Dart :: how to rename file in flutter 
Dart :: dart list equality 
Dart :: dart map.foreach 
Dart :: flutter check if null 
Dart :: special characters flutter 
Dart :: flutter gray screen 
Dart :: flutter logo size 
Dart :: dart async stream 
Dart :: widget capture in flutter 
Dart :: access blocprovider inside a dispose method in flutter 
Dart :: crossaxisalignment.stretch row in column flutter 
Dart :: Flutter local asset run time path 
Dart :: flutter toast not working 
Dart :: how to stop listening to location change listener on dispose in flutter 
Dart :: convert string date in Format yyyyMMddHHmmss to DateTime dart 
Dart :: flutter container rounded corners 
Swift :: declaring vs initializing variables 
Swift :: swift enum all cases 
Swift :: detect binding valu change swiftui 
Swift :: round down swift 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =