import 'package:flutter/material.dart'; import 'home_page.dart'; class SplashScreen extends StatefulWidget { @override _SplashScreenState createState() => _SplashScreenState(); } class _SplashScreenState extends State<SplashScreen> with SingleTickerProviderStateMixin {//混入 //申明变量 控制动画的(控制动画的时间 效果等) AnimationController _controller; Animation _animation;//控制动画 @override void initState() { super.initState(); _controller=AnimationController(vsync: this,duration: Duration(milliseconds: 3000)); // vsync垂直动态演示的意思 Duration持续时间 _animation = Tween(begin: 0.0, end:1.0).animate(_controller); _animation.addStatusListener((status) { //监听动画结束状态 if(status == AnimationStatus.completed){ // pushAndRemoveUntil 跳转到下一页 把动画结束掉 Navigator.of(context).pushAndRemoveUntil( MaterialPageRoute(builder: (context) => MyHomePage(),), (route) => route==null //固定写法 返回的是1个true ); } }); //使用控制器播放动画 _controller.forward(); } @override void dispose() { //销毁的时候 _controller.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return FadeTransition( opacity: _animation, child: Image.asset( 'images/1111.jpg', scale: 1.0, fit: BoxFit.cover, ), ); } }