I'm making an app on flutter in which the items such as price in products List must be arranged in increasing order. After searching on the internet I came up with the solution of using compareTo and sort function but unfortunately, I'm having an error on sort() i.e: The expression here has a type void and therefore can't be used. The whole proper code is on Github https://github.com/MaidaFarooqi9/Application/blob/master/lib/ProductScreen.dart And the code part which I'm trying to modify is
return Container(
child:ListView.separated(
itemBuilder: (context, index){
return ListTile(
title:Text(products[index].name),
leading:products[index].i,
subtitle:Column(
children:<Widget>[
if (!ProductScreen.name) Text("\$${products[index].price}",
style: TextStyle(color: Colors.redAccent, fontSize: 20, fontWeight: FontWeight.w500),)
else
Text(products.sort((a,b)=>a.price.compareTo(b.price))) ,
The if-else condition is showing at if() the unsorted list and after else the price will be in ascending order