flutter finding out the title of the ToDoItem that has the highest price
107
void main(){
List<ToDoItem> _myList = [];
_myList.add(ToDoItem('10',100));
_myList.add(ToDoItem('30',400));
_myList.add(ToDoItem('40',2));
_myList.add(ToDoItem('20',200));
_myList.sort((a,b)=>a.price.compareTo(b.price));
for(ToDoItem items in _myList)
print(items.id + ',' + items.price.toString());
}
class ToDoItem{
final String id;
final int price;
const ToDoItem(
this.id,
this.price,
);
}
This is the code which i used in dart to sort your list . YOu could use the sorting logic from in here . it sorts your list in ascending order acc to price .
Author by
Chad
Updated on December 23, 2022Comments
-
Chad over 1 year
To-Do App
class ToDoItem{ final String id; final String title; final Color color; final int price; final IconData icon; final String todoListId; const ToDoItem({ @required this.color, @required this.id, @required this.todoListId, @required this.price, @required this.title, @required this.icon, });}
I am trying to find the title of the ToDoItem which has the highest price
And the ToDoItem is being added to this:
List<ToDoItem> toDo= [];
-
Shahryar Rafique over 3 yearsYou can make a method of the Todo Class to get the highest price by storing the copy of the List in memory and then get the highest price..
-
Chad over 3 yearsi am already storing the toDoItem to the devices storage
-
Aman Verma over 3 yearsi have answered below , do mark it as an answer if it helps
-
Shahryar Rafique over 3 yearsCheck this stackoverflow.com/questions/53547997/….
-