最新国产好看的视频,伊人天堂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()));
? ? ? ? }
? ? ? });
? ? });

? ? //開始倒計(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)論

靖江市| 弋阳县| 勃利县| 昔阳县| 灯塔市| 类乌齐县| 巩留县| 永济市| 沙雅县| 寻甸| 和田市| 固安县| 建阳市| 连州市| 来安县| 紫云| 临桂县| 五原县| 宿松县| 大悟县| 博野县| 百色市| 县级市| 烟台市| 中山市| 渝北区| 武夷山市| 遂昌县| 乌拉特前旗| 南康市| 新和县| 旬阳县| 阳高县| 伊宁县| 漾濞| 依安县| 凤台县| 思茅市| 阳高县| 墨脱县| 滁州市|