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)?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You can pass a comparison function to List.sort
.
someObjects.sort((a, b) => a.someProperty.compareTo(b.someProperty));
回答2:
If you want to sort the object "objects" by the property "name" do something like this
objects.sort((a, b) {
return a.value['name'].toString().toLowerCase().compareTo(b.value['name'].toString().toLowerCase());
});