Skip to content

Commit 74e0f52

Browse files
committed
fix: correctly sort books with a half-star rating.
When sorting by rating, books with a rating of a half-star aren't sorted correctly. This was due to the ratings being converted to strings and those strings used for sorting. A half-star is stored as 5, which means that the string gets sorted as being above anything starting with 4 or less. I.e. anything but a full five stars. This has been fixed by doing the comparison on the int directly.
1 parent 68a0f21 commit 74e0f52

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

lib/ui/books_screen/books_screen.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,7 @@ class _BooksScreenState extends State<BooksScreen>
396396
}
397397

398398
booksRated.sort((a, b) {
399-
int ratingSorting = removeDiacritics(a.rating!.toString().toLowerCase())
400-
.compareTo(removeDiacritics(b.rating!.toString().toLowerCase()));
399+
int ratingSorting = a.rating!.compareTo(b.rating!);
401400
if (!isAsc) {
402401
ratingSorting *= -1;
403402
} // descending

0 commit comments

Comments
 (0)