zoukankan      html  css  js  c++  java
  • 【Flutter】应用广告页面-3秒后跳转

    flutter 广告页-3秒读数后或者点击跳过广告按钮后跳转

    /**
     * 广告页,3秒自动跳转到首页
     */
    
    import 'dart:async';
    
    import 'package:flutter/material.dart';
    
    
    class SplashScreen extends StatefulWidget {
      @override
      _SplashScreenState createState() => new _SplashScreenState();
    }
    
    class _SplashScreenState extends State<SplashScreen> {
      Timer _timer;
      int count = 3;
    
      startTime() async {
        //设置启动图生效时间
        var _duration = new Duration(seconds: 1);
        new Timer(_duration, () {
          // 空等1秒之后再计时
          _timer = new Timer.periodic(const Duration(milliseconds: 1000), (v) {
            count--;
            if (count == 0) {
              navigationPage();
            } else {
              setState(() {});
            }
          });
          return _timer;
        });
      }
    
      void navigationPage() {
        _timer.cancel();
        Navigator.of(context).pushReplacementNamed('/main');//要跳转的页面
      }
    
      @override
      void initState() {
        super.initState();
        startTime();
      }
    
      @override
      Widget build(BuildContext context) {
        return new Stack(
          alignment: const Alignment(1.0, -1.0), // 右上角对齐
          children: [
            new ConstrainedBox(
              constraints: BoxConstraints.expand(),
              child: new Image.asset(
                "assets/images/ad.jpg",//广告图
                fit: BoxFit.fill,
              ),
            ),
            new Padding(
              padding: new EdgeInsets.fromLTRB(0.0, 30.0, 10.0, 0.0),
              child: new FlatButton(
                onPressed: () {
                  navigationPage();
                },
    //            padding: EdgeInsets.all(0.0),
                color: Colors.grey,
                child: new Text(
                  "$count 跳过广告",
                  style: new TextStyle(color: Colors.white, fontSize: 12.0),
                ),
              ),
            )
          ],
        );
      }
    }
  • 相关阅读:
    sh执行脚本报错Syntax error: "(" unexpected
    Ubuntu源码编译安装PostgreSQL
    Linux解决Graphical installers are not supported by the VM
    pytest功能入门
    vscode配置远程开发环境失败_workbench.downloadResource
    花生壳新版 内网穿透教程
    同局域网内进行本机调试
    Windows10激活
    win server 2012安装Vmware tools
    windows实现超级隐藏用户
  • 原文地址:https://www.cnblogs.com/sangwl/p/11435191.html
Copyright © 2011-2022 走看看