Flutter 中使用 HUD Progress 組件

原文

https://medium.com/flutterdev...

前言

在 flutter 中,咱們顯示任何進度指示器,由於咱們的應用程序是繁忙的或在擱置,爲此,咱們顯示一個循環的進度指示器。覆蓋加載屏幕顯示一個進度指示器,也稱爲模態進度 HUD 或平視顯示,這一般意味着應用程序正在加載或執行一些工做。android

在本文中,咱們將利用 HUD 進程程序包來探討平視顯示器在 flutter 方面的進展。有了這個軟件包,咱們能夠很容易地實現平視顯示的顫振進度。那麼讓咱們開始吧。git

pub.dev

https://pub.dev/packages/flut...github

https://pub.dev/packages/flut...編程

正文

HUD Progress

Flutter HUD Progress 是一種進度指示器庫,就像一個循環的進度指示器。在這裏,HUD 意味着一個擡頭顯示器/進度彈出對話框將打開以上的屏幕,將有一個循環的進度指示器。使用這個庫,咱們能夠使用咱們的 flutter 。應用程序能夠顯示循環進度指示器。api

屬性

  • borderColor:
    邊框/顏色: 邊框顏色屬性用於更改指示符背景邊框顏色
  • backgroundColor:
    背景顏色: 背景顏色屬性用於更改指示器背景的顏色
  • indicatorColor:
    標誌/顏色: 背景顏色屬性用於更改指示器背景的顏色
  • textStyle:
    文字樣式: 屬性用於指示符下面顯示的文本,文本的顏色和樣式能夠在該屬性中更改

安裝

  • 第一步: 添加依賴項

將依賴項添加到 pubspec ー yaml 文件。微信

dependencies:
  flutter_progress_hud: ^2.0.0
  • 第二步: 導包
import 'package:flutter_progress_hud/flutter_progress_hud.dart';
  • 第三步: 啓用 AndriodX
org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true

例子

lib 目錄中建立一個名爲 progress_hud_demo.dart 的新 dart 文件。app

在建立 Flutter HUD Progress 以前,咱們包裝了一個進度遮光罩的容器,其次是建設者類。在內部,咱們使用了咱們的小部件,並定義了進度指示器的邊框顏色和背景顏色。讓咱們詳細地瞭解一下這一點。jvm

ProgressHUD(
  borderColor:Colors.orange,
  backgroundColor:Colors.blue.shade300,
  child:Builder(
    builder:(context)=>Container(
      height:DeviceSize.height(context),
      width:DeviceSize.width(context),
      padding:EdgeInsets.only(left:20,right:20,top:20),
    ),
  ),
),

如今咱們已經採起了一個按鈕,在其中指示器設置持續時間 5 秒的指示器時間將來。delayed() 並顯示進度的文本。編程語言

Container(
  margin: EdgeInsets.only(
      left:20.0, right:20.0, top:55.0),
  child: CustomButton(
    mainButtonText:'Submit',
    callbackTertiary:(){
      final progress = ProgressHUD.of(context);
      progress.showWithText('Loading...');
      Future.delayed(Duration(seconds:5), () {
        progress.dismiss();
      });
    },
    color:Colors.blue,
  ),
),

當咱們運行應用程序時,咱們應該獲得屏幕的輸出,就像下面的屏幕截圖同樣。ide

完整代碼

import 'package:flutter/material.dart';
import 'package:progress_hud_demo/shared/custom_button.dart';
import 'package:progress_hud_demo/shared/custom_text_field.dart';
import 'package:progress_hud_demo/themes/device_size.dart';
import 'package:flutter_progress_hud/flutter_progress_hud.dart';
class ProgressHudDemo extends StatefulWidget {
  @override
  _ProgressHudDemoState createState() => _ProgressHudDemoState();
}

class _ProgressHudDemoState extends State<ProgressHudDemo> {
  bool _isInAsyncCall = false;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor:Colors.white,
      appBar:AppBar(
        backgroundColor:Colors.blue,
        title:Text('Flutter HUD Progress Demo'),
        elevation:0.0,
      ),
      body:ProgressHUD(
        borderColor:Colors.orange,
        backgroundColor:Colors.blue.shade300,
        child:Builder(
          builder:(context)=>Container(
            height:DeviceSize.height(context),
            width:DeviceSize.width(context),
            padding:EdgeInsets.only(left:20,right:20,top:20),
            child:Column(
              crossAxisAlignment:CrossAxisAlignment.start,
              children: [

                Column(
                  crossAxisAlignment:CrossAxisAlignment.start,
                  children: [
                    Text('Sign In',style:TextStyle(fontFamily:'Roboto Bold',fontSize:27,fontWeight:FontWeight.bold),),
                  ],
                ),

                SizedBox(height:50,),


                Column(
                  children: [
                    CustomTextField(hintText: 'Email', type:TextInputType.text, obscureText: false),


                    SizedBox(height:35,),

                    CustomTextField(hintText: 'Password', type:TextInputType.text, obscureText: true),
                  ],
                ),

                Container(
                  margin: EdgeInsets.only(
                      left:20.0, right:20.0, top:55.0),
                  child: CustomButton(
                    mainButtonText:'Submit',
                    callbackTertiary:(){
                      final progress = ProgressHUD.of(context);
                      progress.showWithText('Loading...');
                      Future.delayed(Duration(seconds:5), () {
                        progress.dismiss();
                      });
                    },
                    color:Colors.blue,
                  ),
                ),

              ],
            ),
          ),
        ),
      ),
    );
  }
}

© 貓哥

https://ducafecat.tech/

https://github.com/ducafecat

往期

開源

GetX Quick Start

https://github.com/ducafecat/...

新聞客戶端

https://github.com/ducafecat/...

strapi 手冊譯文

https://getstrapi.cn

微信討論羣 ducafecat

系列集合

譯文

https://ducafecat.tech/catego...

Dart 編程語言基礎

https://space.bilibili.com/40...

Flutter 零基礎入門

https://space.bilibili.com/40...

Flutter 實戰從零開始 新聞客戶端

https://space.bilibili.com/40...

Flutter 組件開發

https://space.bilibili.com/40...

Flutter Bloc

https://space.bilibili.com/40...

Flutter Getx4

https://space.bilibili.com/40...

Docker Yapi

https://space.bilibili.com/40...

相關文章
相關標籤/搜索