按属性值对Flutter(Dart)中的对象列表进行排序 [英] Sort a list of objects in Flutter (Dart) by property value
本文介绍了按属性值对Flutter(Dart)中的对象列表进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何按照属性之一的字母顺序对对象列表进行排序(不是名称而是属性所拥有的实际值)?
How to sort a list of objects by the alphabetical order of one of its properties (Not the name but the actual value the property holds)?
推荐答案
您可以将比较函数传递给 List.sort
。
You can pass a comparison function to List.sort
.
someObjects.sort((a, b) => a.someProperty.compareTo(b.someProperty));
这篇关于按属性值对Flutter(Dart)中的对象列表进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文