In this answer, I will share how to add sliding animation to bottom in flutter The code belows shows a minimal example of the SlideTransition. If you’d like to keep displaying it during the navigation from one screen to another, you’d have to draw it in a layer above your Navigator.
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
import 'package:flutter/material.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Home(), ); } } class Home extends StatefulWidget { @override State<StatefulWidget> createState() => HomeState(); } class HomeState extends State<Home> with SingleTickerProviderStateMixin { AnimationController controller; Animation<Offset> offset; @override void initState() { super.initState(); controller = AnimationController(vsync: this, duration: Duration(seconds: 1)); offset = Tween<Offset>(begin: Offset.zero, end: Offset(0.0, 1.0)) .animate(controller); } @override Widget build(BuildContext context) { return Scaffold( body: Stack( children: <Widget>[ Center( child: RaisedButton( child: Text('Show / Hide'), onPressed: () { switch (controller.status) { case AnimationStatus.completed: controller.reverse(); break; case AnimationStatus.dismissed: controller.forward(); break; default: } }, ), ), Align( alignment: Alignment.bottomCenter, child: SlideTransition( position: offset, child: Padding( padding: EdgeInsets.all(50.0), child: CircularProgressIndicator(), ), ), ) ], ), ); } } |
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.