How to know the end of Hero animation in flutter? How to know the end of Hero animation in flutter? dart dart

How to know the end of Hero animation in flutter?


The interface you want to achieve doesn't necessarily use Hero widgets. It can be done with other animations. But, if you wan't to use Hero, you can try a rather hacky solution:

On your Screen 1, set these two properties in your Hero's TextField:

Hero(  tag: 'search',  child: Material(    type: MaterialType.transparency,    child: TextField(      readOnly: true,      showCursor: true,      onTap: () {        Navigator.push() //to SearchScreen()      }    ),  ),),

Then, on Screen 2:

Hero(  tag: 'search',  child: Material(    type: MaterialType.transparency,    child: TextField(      autofocus: true,    ),  ),),

You'll have to avoid using the same SearchTextField on both screens; they each need their own as I showed. Also, you can probably remove all of that FocusNode code if you use this method.

Disclaimer: I haven't tested this code. It's just something to try