关键词:AnimationController Animation SingleTickerProviderStateMixin
import 'package:flutter/material.dart';
import 'my_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() {
// TODO: implement initState
super.initState();
_controller = AnimationController(vsync: this, duration: Duration(milliseconds: 3000));
_animation = Tween(begin: 0.0,end: 1.0).animate(_controller);
_animation.addStatusListener((status) {
if(status == AnimationStatus.completed){
Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(builder:(context)=>MyHomePage()), (route) => route == null);
}
});
_controller.forward();
}
@override
void dispose() {
// TODO: implement dispose
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return FadeTransition(opacity: _animation,
child: Image.network('https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1608269781192&di=bcb23e1c31fc16c6f622a3c6bd172cfa&imgtype=0&src=http%3A%2F%2Fattach.bbs.miui.com%2Fforum%2F201209%2F12%2F0858331k9zk29u26f2mzqn.jpg',scale: 2.0,fit: BoxFit.cover,),);
}
}
import 'package:flutter/material.dart';
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('HomePage'),),
body: Center(
child: Text('I am Home Page'),
),
);
}
}