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 :: images with text in it flutter 
Dart :: Flutter Popup Menu Button Example Tutorial 
Dart :: flutter length of string 
Dart :: iterable.every dart 
Dart :: 2d array flutter 
Dart :: DioError (DioError [DioErrorType.DEFAULT]: Converting object to an encodable object failed: Instance of 
Dart :: dart what is a closure 
Dart :: shape property of card in flutter 
Dart :: android studio avd blue screen 
Dart :: consumer flutter 
Dart :: dart convert iterable to list 
Dart :: sort list dart 
Dart :: flutter if else 
Dart :: flutter upgrade pubspec 
Dart :: flutter alert dialog shape 
Dart :: perform async task when build is done flutter 
Dart :: flutter get image file from assets 
Dart :: unable to update dart sdk. retrying 
Dart :: how to put two trailing icons in list tile flutter 
Dart :: getting date from 12am dart 
Dart :: alternate of string class in dart 
Dart :: odd even in dart 
Dart :: flutter radio button 
Dart :: how to check Flutter app comes to foreground 
Dart :: what is pubspec.yaml 
Dart :: android studio not detecting new package in flutter 
Dart :: flutter pre intistate statefulwidget 
Dart :: scrolling to top sliverlist flutter with back button 
Dart :: seach flutter 
Dart :: using email signin or phone number in flutter firebase 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =