android - 如何对具有自定义元素(不是字符串或 int)的列表进行排序?
问题描述
我正在使用 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> 中的元素仍然是字符串。
解决方案
实现 Comparable 并在 compareTo() 中编写逻辑。
class _SecItem implements Comaparable<_SecItem> {
_SecItem(this.key, this.value);
final String key;
final String value;
public int compareTo(Student st){
}
}
推荐阅读
- c# - 刷新页面时 AuthorizeAttribute 不起作用
- python - ASP.NET 定位对象的抓取问题 - Selenium
- python - 如何使用python修改xml文件中嵌套元素的文本?
- python - 如何将文件从 Bamboo 任务发送到我们的 python 微服务
- c# - ASP.NET Web API:通过查询字符串的多个自定义对象
- ruby-on-rails - 如果用户登录?案例 current_user.plan_id ELSE ...?
- groovy - 如何获取 Liferay 6.2 站点的用户列表
- c# - 即使启用了 Thread_UseAllCpuGroups,Environment.ProcessorCount 也没有显示正确的数字
- css - 媒体查询和屏幕方向
- javascript - 传单标记和“onclick”事件的问题