我正在使用flutter_secure_storage软件包,并且正在尝试对列表中的项目进行排序。列表如下:List<_SecItems> hi = []
并且定义:
class _SecItem {
_SecItem(this.key, this.value);
final String key;
final String value;
}
未保留列表中项目的顺序。并使用hi.sort()
给出消息type '_SecItem' is not a subtype of type 'Comparable<dynamic>'
那么我将如何排序_Secitem元素列表中的字符串? List <_secitems>内部的元素仍然是字符串。
您可以像这样对对象进行排序
hi.sort((a, b) => b.value.compareTo(a.value));