How to add delete function to remove dynamically generated widget in flutter

convert your foreach loop to a for loop with index

for (XFile img in _imageList!) { ...}

to

for (int index=0; _imageList.length; index++)   

now you have an index for your remove call

_tiles.removeAt(index);