首页 > 解决方案 > 如何在飞镖中使用正则表达式对字符串列表进行排序?

问题描述

我本质上是在寻找除 .sort() 之外的另一种对字符串列表进行排序的方法,出于我的目的,type '_SecItem' is not a subtype of type 'Comparable<dynamic>' 我正在尝试通过字符串前面的数字对字符串列表进行排序。就像是:

List<String> hi = ['05stack', '03overflow', '01cool','04is', '02uToo'];

对此:

['01cool', '02uToo', '03overflow', '04is', '05stack']

标签: androidflutterdartcomparable

解决方案


我可以使用 sort() 轻松排序。

var List<String> hi = ['05stack', '03overflow', '01cool', '04is', '02uToo'];
  hi.sort();
  hi.forEach((element) {
    print(element);
  });

它打印:

01cool
02uToo
03overflow
04is
05stack

我没有收到任何错误

type '_SecItem' is not a subtype of type 'Comparable<dynamic>'

推荐阅读