On the first page there is a list of products, each of them can be added to the array of objects (selected), which is higher in the hierarchy, from there, setState is simply called, and it is called when the product is added, that is, we update the state of the selected products. The entire array of these selected products is transferred to the second page, where they are all displayed one by one in the form of a ListView. But there is a button "Remove from favorites" that calls the setState passed from above to remove the object from the array of favorites, redraw the ListView and show that there is now one less product in the list. The problem is that when I delete NOT the last element from the list, the state of the element below it is reset Products in favorites Click on the heart of the first tile, remove it from the list
The heart will glow red if this product is in the favorites array, this is a separate custom widget that accepts the favorites array and the product itself as a parameter, and in initState checks whether the product is in the array, if true then it glows red, if false it glows black