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
| class GMExampleAnimatedCrossFadeTest extends StatefulWidget { GMExampleAnimatedCrossFadeTest({Key key}) : super(key: key);
@override _GMExampleAnimatedCrossFadeTestState createState() => _GMExampleAnimatedCrossFadeTestState(); }
class _GMExampleAnimatedCrossFadeTestState extends State<GMExampleAnimatedCrossFadeTest> { bool _isShowFirst = true; @override Widget build(BuildContext context) { return Scaffold( body: Center( child: AnimatedCrossFade( duration: Duration(seconds: 1), crossFadeState: _isShowFirst ? CrossFadeState.showFirst : CrossFadeState.showSecond, firstChild: Container( height: 150, width: 150, alignment: Alignment.center, decoration: BoxDecoration( shape: BoxShape.circle, color: Colors.blue, ), child: Text( "first child", style: TextStyle(color: Colors.white), ), ), secondChild: Container( height: 150, width: 150, alignment: Alignment.center, decoration: BoxDecoration( shape: BoxShape.rectangle, color: Colors.orange, borderRadius: BorderRadius.circular(20), ), child: Text( "second child", style: TextStyle(color: Colors.white), ), ), ), ), floatingActionButton: FloatingActionButton( onPressed: () { setState(() { _isShowFirst = !_isShowFirst; }); }, ), ); } }
|