ラッパハングル昇順ソート
// sortedList는 List<ProfileModle>이다.
sortedList
..sort((a, b) {
if (a.name!.substring(0, 1).codeUnits[0] !=
b.name!.substring(0, 1).codeUnits[0]) {
return a.name!
.substring(0, 1)
.codeUnits[0]
.compareTo(b.name!.substring(0, 1).codeUnits[0]);
} else if (a.name!.substring(1, 2).codeUnits[0] !=
b.name!.substring(1, 2).codeUnits[0]) {
return a.name!
.substring(1, 2)
.codeUnits[0]
.compareTo(b.name!.substring(1, 2).codeUnits[0]);
} else {
return a.name!
.substring(2, 3)
.codeUnits[0]
.compareTo(b.name!.substring(2, 3).codeUnits[0]);
}
});
3文字目に並ぶもっと並べ替えたい場合は、elseの代わりにelse if+substring(3,4)を使用します.続行すればいいです.
降順は、前の(a,b)部分を(b,a)に変更できます.
Reference
この問題について(ラッパハングル昇順ソート), 我々は、より多くの情報をここで見つけました https://velog.io/@geebab/플러터-한글-오름차순-정렬テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol