您好,我正在尝试在flutter中对地图进行排序,我遇到了几种方法,但迄今为止都没有任何帮助。
{ 11-Mittwoch: 07:20:58-07:21:03-23:44:37-00:00:00, 15-Sonntag: 11:11:02-11:11:32-00:00:29-00:00:00, 10-Dienstag: 07:36:20-07:20:53-23:44:32-00:00:00, 28-Samstag: 15:32:18-15:32:21-00:00:01-00:00:01, 30-Montag: 08:25:50-16:28:57-08:03:06-00:00:00, 1-Sonntag: 20:39:11-20:39:33-00:00:15-00:00:06, 3-Dienstag: 17:30:14-17:30:19-00:00:04-00:00:00, 18-Mittwoch: 07:54:51-17:38:01-09:43:09-00:00:00, 5-Donnerstag: 08:17:11-22:07:50-03:45:09-10:05:28, 17-Dienstag: 07:00M-15:20M-7:00M-1:00M, 9-Montag: 18:10:28-18:10:32-00:00:04-00:00:00, 6-Freitag: 07:36:54-14:56:13-07:19:19-00:00:00, 2-Montag: 08:28:39-15:44:11-04:21:33-01:05:34}
从上面的代码可以看出,键是日期和日期的组合,以(-)分隔。我需要的方法是如何以升序排列这类地图,而不是从每月的第十一天开始。
我尝试使用此代码:
var mapEntries = allData.entries.toList()
..sort((a, b) => a.key.replaceAll(" ", "").split("-")[0].compareTo(b.key.replaceAll(" ", "").split("-")[0])),
allData
..clear()
..addEntries(mapEntries),
但这是我得到的结果:
{ 1-Sonntag: 20:39:11-20:39:33-00:00:15-00:00:06, 10-Dienstag: 07:36:20-07:20:53-23:44:32-00:00:00, 11-Mittwoch: 07:20:58-07:21:03-23:44:37-00:00:00, 15-Sonntag: 11:11:02-11:11:32-00:00:29-00:00:00, 17-Dienstag: 07:00M-15:20M-7:00M-1:00M, 18-Mittwoch: 07:54:51-17:38:01-09:43:09-00:00:00, 2-Montag: 08:28:39-15:44:11-04:21:33-01:05:34, 28-Samstag: 15:32:18-15:32:21-00:00:01-00:00:01, 3-Dienstag: 17:30:14-17:30:19-00:00:04-00:00:00, 30-Montag: 08:25:50-16:28:57-08:03:06-00:00:00, 5-Donnerstag: 08:17:11-22:07:50-03:45:09-10:05:28, 6-Freitag: 07:36:54-14:56:13-07:19:19-00:00:00, 9-Montag: 18:10:28-18:10:32-00:00:04-00:00:00}
它对所有的一个进行排序,然后是两个,依此类推。
如果能就我做错了什么给出好的建议,我将不胜感激,提前谢谢