flutter 学习 启动图闪图跳转到首页

关键词: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'),
      ),
    );
  }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值