import 'package:flutter/material.dart'; class OpacityAnimation extends StatefulWidget{ OpacityAnimation({Key key}) : super(key:key); _OpacityAnimationState createState() => _OpacityAnimationState(); } class _OpacityAnimationState extends State<OpacityAnimation>{ bool _visible = true; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('AnimatedOpacity淡入淡出动画'), ), body: Center( child: AnimatedOpacity( duration: Duration(milliseconds: 1000), opacity: _visible ? 1.0 : 0.0, child: Container( color: Colors.deepOrange, ), ), ), floatingActionButton: FloatingActionButton( onPressed: (){ setState(() { _visible = !_visible; }); }, tooltip: '显示隐藏', child: Icon(Icons.add), ), ); } }
部分素材资源来源网站,本站提供免费下载,如有侵权请联系站长马上删除!