我想为第一个屏幕设置动画,当用户打开带有淡入淡出效果的应用程序时会显示该屏幕。我尝试将我的屏幕包装到 AnimatedOpacity 小部件中,但没有任何效果。
MaterialApp{
home:FutureBuilder<ApiResponse<Profile>>(
future:api.fetchProfile(),
builder:(context,snapshot){
return snapshot.data != null ? AnimatedOpacity(
child: FirstScreen(),
duration: Duration(milliseconds: 500),
opacity: 1.0,
):Container();
}
),
}
有人做过吗?我正在为 MaterialApp 挖掘文档,我试图弄清楚它仍然不知道如何去做。
最佳答案
我不确定这是否是你想要的,但你可以使用FadeTransition
:
void main() => runApp(MaterialApp(
home:FirstPage(),
));
class FirstPage extends StatefulWidget {
@override
_FirstPageState createState() => new _FirstPageState();
}
class _FirstPageState extends State<FirstPage> with TickerProviderStateMixin {
AnimationController animationController;
@override
void initState() {
animationController=AnimationController(
vsync:this,
duration:(Duration(seconds: 2)),
);
super.initState();
}
@override
void dispose() {
animationController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
animationController.forward();
return FadeTransition(
opacity: animationController,
child: Scaffold(
appBar:AppBar(
backgroundColor: Colors.redAccent,
),
body:Center(child:Text('I am your first page'))
),
);
}
}
关于flutter - Dart 动画 MaterialApp 主屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52011367/