I have tried this on dartpad,
void main() {
final List<String> dates=["24-06-2021","27-05-2021","21-04-2021","29-07-2021","15-12-2021"];
var sorted = dates..sort((a,b) => a.compareTo(b));
print(sorted);
}
Output : [15-12-2021, 21-04-2021, 24-06-2021, 27-05-2021, 29-07-2021]
Desired : [21-04-2021, 27-05-2021, 24-06-2021, 29-07-2021, 15-12-2021]
Any help is appreciated.
DateTimeobjectsDateTimeobjects first means that you don't need to reparse the same strings when performing multiple comparisons of the same element.