/**
* 广告页,3秒自动跳转到首页
*/
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:zybdapp/youshang/main_screen.dart';
void main() {
runApp(new MaterialApp(
title: 'ad',
home: new SplashScreen(),
routes: <String, WidgetBuilder>{
'/main': (BuildContext context) => new MainScreen()
},
));
}
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),
),
),
)
],
);
}
}
flutter 广告页-3秒读数后或者点击跳过广告按钮后跳转
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 023|决策时间:用户思考了很久,又把商品放回去了,怎么办? 什么是“决策时间”?消费者的注意力时长越来越短,人们...
- 【蝴蝶效应】 蝴蝶效应:上个世纪70年代,美国一个名叫洛伦兹的气象学家在解释空气系统理论时说,亚马逊雨林一只蝴蝶...