flutter怎么实现倒计时加载页面
发表于:2025-11-07 作者:千家信息网编辑
千家信息网最后更新 2025年11月07日,本篇内容主要讲解"flutter怎么实现倒计时加载页面",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"flutter怎么实现倒计时加载页面"吧!效果图实现步
千家信息网最后更新 2025年11月07日flutter怎么实现倒计时加载页面
本篇内容主要讲解"flutter怎么实现倒计时加载页面",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"flutter怎么实现倒计时加载页面"吧!
效果图
实现步骤
1、pubspec.yaml中添加依赖 flustars,该包的TimelineUtil和TimerUtil类可以实现计时功能
dependencies: flustars: ^0.3.3
!注意空格哦
2、代码实现
初始化TimerUtil
late TimerUtil util; double current_time = 0;void initState() { super.initState(); util = new TimerUtil(mInterval: 18, mTotalTime: 5000); util.setOnTimerTickCallback((millisUntilFinished) { setState(() { //每次时间间隔回调,把每次当前总时间ms除以1000就是秒 current_time = millisUntilFinished / 1000; //倒计时结束时 跳转到首页 当然也可以等待资源加载完成再跳转 if (current_time == 0) { /*等待资源完成代码块*/ //跳转到首页 Navigator.push( context, MaterialPageRoute(builder: (context) => HomePage())); } }); });构造页面
Widget build(BuildContext context) { return Scaffold( body: Column( children: [ Image.asset('images/2.0/beijing.jpg'), Container( alignment: Alignment.centerRight, child: SizedBox( height: 50, width: 50, child: Stack( children: [ Center(child: CircularProgressIndicator( value: current_time == 5.0 ? 0 : (5 - current_time) / 5, ),), Center(child: Text('${current_time.toInt()}'),) ],) ), ), ], )); }完整代码
import 'package:flustars/flustars.dart';import 'package:flutter/material.dart';void main() { runApp(MyApp());}class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: LoadingPage(), ); }}class LoadingPage extends StatefulWidget { const LoadingPage({Key? key}) : super(key: key); @override _LoadingPageState createState() => _LoadingPageState();} class _LoadingPageState extends State { late TimerUtil util; //计时对象 double current_time = 0; //当前时间 @override Widget build(BuildContext context) { return Scaffold( body: Column( children: [ Image.asset('images/2.0/beijing.jpg'), Container( alignment: Alignment.centerRight, child: SizedBox( height: 50, width: 50, child: Stack( children: [ Center(child: CircularProgressIndicator( value: current_time == 5.0 ? 0 : (5 - current_time) / 5, ),), Center(child: Text('${current_time.toInt()}'),) ],) ), ), ], )); } @override void initState() { super.initState(); util = new TimerUtil(mInterval: 18, mTotalTime: 5000); util.setOnTimerTickCallback((millisUntilFinished) { setState(() { //每次时间间隔回调,把每次当前总时间ms除以1000就是秒 current_time = millisUntilFinished / 1000; //倒计时结束时 跳转到首页 当然也可以等待资源加载完成再跳转 if (current_time == 0) { /*等待资源完成代码块*/ //跳转到首页 Navigator.push( context, MaterialPageRoute(builder: (context) => HomePage())); } }); }); //开始倒计时 util.startCountDown(); }}class HomePage extends StatelessWidget { const HomePage({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('HomePage'), ), ); }} 到此,相信大家对"flutter怎么实现倒计时加载页面"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
倒计时
时间
页面
代码
资源
首页
内容
就是
学习
实用
更深
兴趣
功能
实用性
实际
对象
操作简单
效果
效果图
方法
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
告诉幼儿网络安全教育
信息化网络技术服务介绍
医院招聘数据库工程师
广东应用软件开发外包
网络安全志愿者 讲话稿
公安民警保密网络安全教育
内存 关系数据库
嘉兴无线网络技术推荐咨询
ie无法设置代理服务器
有流量却显示无法连接到服务器
网络安全法与法律规定
唐山网警检查商场网络安全
idc机房交换机与服务器配备
pyqt5重连数据库
大兴区加工软件开发经历
开启数据库服务器
针对数据库安全说法正确的是
查看自己数据库主机地址吗
奉贤区机电软件开发销售电话
软件开发专业的毕业设计
滨湖区互联网智能科技产品出厂价
当当网网络技术框架
工业级服务器对空气环境要求
迅雷网络技术上市
数据监控软件开发
数据库镜像失败重做是否要卸载
服务器 安全 root
户led屏网络安全要求
国防科技大学能源互联网课
新吴区运营软件开发成本