In the init state, I add an if statement to check to see if a custom widget exists on the list that I will pass to the Listview.builder, called an AddItemButtonTile. If it doesn't exist, I want to add it to the list.

 @override
void initState() {
if (!displayedList.listContent.contains(AddItemButtonTile)) {
  displayedList.listContent.add(AddItemButtonTile(openTextField));
}
super.initState();
}

This code results in a new AddItemButtonTile being added every time I navigate away and return to the page. Why is this If statement returning true?


Solution 1: Dix20

Try:

@override
void initState() {
   if (!displayedList.listContent.any((item) => item is AddItemButtonTile)) {
      displayedList.listContent.add(AddItemButtonTile(openTextField));
   }
   super.initState();
}