I'd like to implement a hero animation for an image on my main screen while presenting an AlertDialog widget with the same image in the dialog's content.
I'd like the presentation to appear as in the screenshot below. When I tap the image in the bottom left, I'd like the hero animation and an inset preview of the image along with a transparent overlay that can be tapped to dismiss.
The below code doesn't perform the hero animation.
class AlertDialogTest extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Material(
child: new InkWell(
child: new Hero(
tag: "preview",
child: new Container(
alignment: FractionalOffset.bottomLeft,
child: new Image(
image: new AssetImage('assets/images/theater.png'),
),
),
),
onTap: () {
showDialog(
context: context,
child: new AlertDialog(
content: new Hero(
tag: "preview",
child: new Image(
image: new AssetImage('assets/images/theater.png'),
),
),
),
);
},
),
);
}
}
You can you PageRouteBuilder.
Replace your onTap() code with below code
Navigator.of(context).push(
new PageRouteBuilder(
opaque: false,
barrierDismissible:true,
pageBuilder: (BuildContext context, _, __) {
return Container(
child: Hero(
tag: "preview",
child: new Image(
image: new AssetImage('assets/images/theater.png'),
),
),
);
}
)
)
Demo here the sample code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With