最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

flutter實(shí)現(xiàn)倒計(jì)時(shí)加載頁(yè)面

 更新時(shí)間:2022年03月24日 08:25:08   作者:sai-lingee  
這篇文章主要為大家詳細(xì)介紹了flutter實(shí)現(xiàn)倒計(jì)時(shí)加載頁(yè)面,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了flutter實(shí)現(xiàn)倒計(jì)時(shí)加載頁(yè)面的具體代碼,供大家參考,具體內(nèi)容如下

效果圖

實(shí)現(xiàn)步驟

1、pubspec.yaml中添加依賴 flustars,該包的TimelineUtil和TimerUtil類可以實(shí)現(xiàn)計(jì)時(shí)功能

dependencies:
? flustars: ^0.3.3

!注意空格哦

2、代碼實(shí)現(xiàn)

初始化TimerUtil

late TimerUtil util; ?
double current_time = 0;
void initState() {
? ? super.initState();

? ? util = new TimerUtil(mInterval: 18, mTotalTime: 5000);

? ? util.setOnTimerTickCallback((millisUntilFinished) {
? ? ? setState(() {
? ? ? ? //每次時(shí)間間隔回調(diào),把每次當(dāng)前總時(shí)間ms除以1000就是秒
? ? ? ? current_time = millisUntilFinished / 1000;
? ? ? ? //倒計(jì)時(shí)結(jié)束時(shí) 跳轉(zhuǎn)到首頁(yè) 當(dāng)然也可以等待資源加載完成再跳轉(zhuǎn)
? ? ? ? if (current_time == 0) {
? ? ? ? ? /*等待資源完成代碼塊*/
? ? ? ? ? //跳轉(zhuǎn)到首頁(yè)
? ? ? ? ? Navigator.push(
? ? ? ? ? ? ? context, MaterialPageRoute(builder: (context) => HomePage()));
? ? ? ? }
? ? ? });
? ? });

構(gòu)造頁(yè)面

?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<LoadingPage> {
? late TimerUtil util; //計(jì)時(shí)對(duì)象
? double current_time = 0; //當(dāng)前時(shí)間
? @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(() {
? ? ? ? //每次時(shí)間間隔回調(diào),把每次當(dāng)前總時(shí)間ms除以1000就是秒
? ? ? ? current_time = millisUntilFinished / 1000;
? ? ? ? //倒計(jì)時(shí)結(jié)束時(shí) 跳轉(zhuǎn)到首頁(yè) 當(dāng)然也可以等待資源加載完成再跳轉(zhuǎn)
? ? ? ? if (current_time == 0) {
? ? ? ? ? /*等待資源完成代碼塊*/
? ? ? ? ? //跳轉(zhuǎn)到首頁(yè)
? ? ? ? ? Navigator.push(
? ? ? ? ? ? ? context, MaterialPageRoute(builder: (context) => HomePage()));
? ? ? ? }
? ? ? });
? ? });

? ? //開(kāi)始倒計(jì)時(shí)
? ? 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'),
? ? ? ),
? ? );
? }
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

娄底市| 察隅县| 揭阳市| 威远县| 虎林市| 蓬溪县| 旅游| 巫溪县| 车险| 密山市| 云和县| 施秉县| 甘孜县| 青龙| 清水河县| 伊金霍洛旗| 额尔古纳市| 乌兰察布市| 五台县| 井陉县| 廊坊市| 栾城县| 资源县| 金乡县| 县级市| 沂南县| 福安市| 吴旗县| 海晏县| 邹平县| 嘉义市| 咸丰县| 沙湾县| 黄冈市| 温州市| 富裕县| 夹江县| 屯留县| 建湖县| 张家界市| 嘉义县|