0
votes

Basic setup:

  1. I have a ListView builder that generates a list based on a List.
  2. Each element of the list is wrapped with a Hero() widget and had a unique tag.
  3. List renders just fine, GestureDetector initiates a 'Details' page on tap, with same widget wrapped in Hero() widget with same tag, and animates just fine, as does the 'return' animation on Navigator.pop();

The problem is...

I allow the user to delete the list element on the details page, if they do this, when I close the page with .pop(), the Hero animation basically animates a blank box of the original size back over the top of the newly rendered (and shorter list) making it look like there are 'blanks' in the list.

I originally thought it was an issue with the state of the list and the list not updating, but lots of checking proves the list is being updated, and the widgets are being re-rendered exactly as they should, it's just that there's a blank box sitting on top of them because of the Hero animation caused by the deletion.

  • Remove the Hero() widget wrapper and it works fine.
  • Break the 'tag' so it no longer matches between the two pages and it's fine (but obviously doesn't animate when navigating to the Details page).

Obviously I can stop deletion and move to the main page to avoid the animation at all or remove the animation, but is there a 'correct' way yo do this?

Anyone else hitting the same?

2
Did you use a List of herotag to uniquely identify each element?Son of Stackoverflow
Each element is tagged based on a value from the list itself so it unique (car registration number as it happens). Everything works as expected other than the deletion so I'm comfortable the the list is built correctly etc.David

2 Answers

0
votes

What a quite interesting case you got there. Is your details page statefull? One thing i imagine you could do is to setState after the deletion, so in the rebuild the deleted hero widget wouldn't exists anymore, and when poping navigation the hero navigation won't be fired because it doesn't exist anymore.

0
votes

What if instead of deleting the item from the list on the pop-up up page, when the user clicks delete on the pop-up page you send a flag/parameter back to the parent page to delete the record. That way the animation will play fine as the pop-up closes, and then you can animate out the deleted record.