Want to change speed of a hero animation in flutter? If you already have your own transition or want to create one you can use the PageRouteBuilder to easily build own. Simply adjust the transitionDuration.
Here’s a small standalone example, using the PageRouteBuilder:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Page1(), ); } } class Page1 extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.spaceAround, children: <Widget>[ RaisedButton( child: Text('Page2'), onPressed: () => Navigator.push( context, PageRouteBuilder( transitionDuration: Duration(seconds: 2), pageBuilder: (_, __, ___) => Page2())), ), Hero(tag: 'home', child: Icon(Icons.home)) ], ), ), ); } } class Page2 extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( body: Center( child: Hero( tag: 'home', child: Icon( Icons.home, ), ), ), ); } } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.