gpt4 book ai didi

flutter - 如何按日期时间 (String) 对 List> 进行排序

转载 作者:行者123 更新时间:2023-12-05 05:32:16 55 4
gpt4 key购买 nike

如何对声明为 String 的 Map datetime(String) 列表进行降序排序?

  final List<Map<String, dynamic>> _allUsers = [
{"name": "Chan Saw Lin", "phone": "0152131113" ,"Clock-In" : "2020-06-30 16:10:05"},
{"name": "Lee Saw Loy", "phone": "0161231346","Clock-In" : "2020-07-11 15:39:59"},
{"name": "Khaw Tong Lin", "phone": "0158398109","Clock-In" : "2020-08-19 11:10:18"},
{"name": "Lim Kok Lin", "phone": "0168279101","Clock-In" : "2020-08-19 11:11:35"},
{"name": "Low Jun Wei", "phone": "0112731912","Clock-In" : "2020-08-15 13:00:05"},
{"name": "Yong Weng Kai", "phone": "0172332743","Clock-In" : "2020-07-31 18:10:11"},
{"name": "Jayden Lee", "phone": "0191236439","Clock-In" : "2020-08-22 08:10:38"},
{"name": "Kong Kah Yan", "phone": "0111931233","Clock-In" : "2020-07-11 12:00:00"},
{"name": "Jasmine Lau", "phone": "0162879190","Clock-In" : "2020-08-01 12:10:05"},
{"name": "Chan Saw Lin", "phone": "016783239","Clock-In" : "2020-08-23 11:59:05"},
];

最佳答案

使用sort在列表中,是这样的:

_allUsers.sort((a, b) => (b["Clock-In"] as String).compareTo(a["Clock-In"] as String));

交换ab的位置以获得升序。

关于flutter - 如何按日期时间 (String) 对 List<Map<String, dynamic>> 进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74171638/

55 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com