What am i trying to do is to sort my list by price .I am getting this error.
How can i fix this.Thanks in advanced
sortAll(List<BookModel> books) {
books.sort((a, b) {
a.price.compareTo(b.price);
},);
print((books));
}
}
CodePudding user response:
The compareTo
is not returning anything. Try this instead:
books.sort((a, b) {
return a.price.compareTo(b.price); // note the RETURN
},);
Or this:
books.sort((a, b) => a.price.compareTo(b.price) ); // implicit RETURN