The list doesn't update after an item removed. It only removes the last row. I simplified the code as much as possible since I can't see anything wrong elsewhere. Either this is weird or I was missing something.
class ListState extends State<ListWidget>{
...
List<Item> list = [];
@override
Widget build(BuildContext context) {
print([for(Item item in list) item.name]); //The list is updated so nothing wrong here
List<Tile> children = [];
for(Item item in list) children.add(Tile(item) .. parent = this);
return ListView(children : children, controller : controller);
}
void remove(Item item) => setState((){
list.remove(item);
});
...
}
class Tile extends StatefulWidget{
Item item;
ListState parent;
Tile(this.item);
@override
State<StatefulWidget> createState() => TileState() .. item = item;
}
class TileState extends State<Tile>{
Item item;
@override
Widget build(BuildContext context) => ListTile(
key: ValueKey(item.name),
title: Text(item.name),
onTap: () => widget.parent.remove(item),
);
}