If you want to animate show or hide widgets with flutter? You can use the following example code to animate show or hide widgets with flutter.
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 | import 'package:flutter/material.dart'; class MyWidget extends StatefulWidget { @override State<StatefulWidget> createState() { return _MyWidgetState(); } } class _MyWidgetState extends State<MyWidget> { bool loading = true; @override Widget build(BuildContext context) { return Container( child: Stack( children: <Widget>[ Center( child: GestureDetector( onTap: _toggle, child: Text("WELCOME"), ), ), IgnorePointer( ignoring: !loading, child: AnimatedOpacity( opacity: loading ? 1 : 0, duration: Duration(milliseconds: 500), child: Container( color: Theme.of(context).scaffoldBackgroundColor, child: Center( child: SizedBox( width: 24, height: 24, child: GestureDetector( onTap: _toggle, child: CircularProgressIndicator(), ), ), ), ), ), ) ], ), ); } _toggle() { setState(() { loading = !loading; }); } } |
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.