搜尋套件、儲存庫與 APP 分類

套件詳情v0.1.3

modal_progress_hud

一個模態進度指示器小部件(HUD = 頭部顯示)。包裝在另一個小部件周圍,以在異步呼叫期間阻止對小部件的存取。也接受自訂旋轉圖示。

近 30 天下載
1110
喜歡數
485
Pub 分數
40

安裝套件

flutter pub add modal_progress_hud

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Flutter 套件,提供模態進度指示器(HUD),可在任何 widget 上方顯示載入覆蓋層。在異步操作(如 API 呼叫或資料處理)期間阻止使用者互動,確保順暢的使用者體驗。HUD 支援可自訂的旋轉動畫,允許開發者使用自己的載入動畫。非常適合防止在等待結果時意外點擊。可與按鈕或表單等 widget 無縫搭配。

適用情境

  • 在異步操作期間阻止UI
  • 在表單中顯示加載狀態
  • 防止在資料獲取期間出現點擊
  • 透過視覺反饋提升使用者體驗
  • 自定義加載指示器

主要特色

  • 模態覆蓋層阻擋互動
  • 支援自訂旋轉指示器
  • 與現有小部件的簡單整合
  • 非侵入式加載顯示
  • 適用於任何 widget 樹

適合對象

  • 需要快速加載覆蓋層的開發者
  • 頻繁異步操作的應用程式
  • 需要明確加載狀態的 UI
  • 注重使用者體驗一致性的團隊
  • 使用最少樣板程式碼的專案

使用建議

  • 不處理錯誤狀態
  • 無內建重試機制
  • Spinner 自訂需要額外的設定
  • 超出基本的樣式選項有限
  • 不適用於複雜的載入工作流程

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

modal_progress_hud

A simple widget wrapper to enable modal progress HUD (a modal progress indicator, HUD = Heads Up Display)

pub package Build Status Coverage Status

Inspired by this article.

Demo

Demo

See example for details

Usage

Add the package to your pubspec.yml file.

dependencies:
  modal_progress_hud: ^0.1.3

Next, import the library into your widget.

import 'package:modal_progress_hud/modal_progress_hud.dart';

Now, all you have to do is simply wrap your widget as a child of ModalProgressHUD, typically a form, together with a boolean that is maintained in local state.

...
bool _saving = false
...

@override
Widget build(BuildContext context) {
  return Scaffold(
     body: ModalProgressHUD(child: Container(
       Form(...)
     ), inAsyncCall: _saving),
  );
}

Options

The current parameters are customizable in the constructor

ModalProgressHUD(
  @required inAsyncCall: bool,
  @required child: Widget,
  opacity: double,
  color: Color,
  progressIndicator: CircularProgressIndicator,
  offset: double
  dismissible: bool,
);

Example

Here is an example app that demonstrates the usage.

  1. On initial load, _saving is false which causes your child widget to display
  2. When the form is submitted, _saving is set to true, which will display the modal
  3. Once the async call is complete, _saving is set back to false, hiding the modal
class SettingsPage extends StatefulWidget {
  @override
  _SettingsPageState createState() => new _SettingsPageState();
}

class _SettingsPageState extends State<SettingsPage> {
  bool _saving = false;

  void _submit() {

    setState(() {
      _saving = true;
    });

    //Simulate a service call
    print('submitting to backend...');
    new Future.delayed(new Duration(seconds: 4), () {
      setState(() {
        _saving = false;
      });
    });
  }

  Widget _buildWidget() {
    return new Form(
      child: new Column(
        children: [
          new SwitchListTile(
            title: const Text('Bedroom'),
            value: _bedroom,
            onChanged: (bool value) {
              setState(() {
                _bedroom = value;
              });
            },
            secondary: const Icon(Icons.hotel),
          ),
          new RaisedButton(
            onPressed: _submit,
            child: new Text('Save'),
          ),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('Flutter Progress Indicator Demo'),
        backgroundColor: Colors.blue,
      ),
      body: ModalProgressHUD(child: _buildWidget(), inAsyncCall: _saving),
    );
  }
}

Update: See this article on Medium about async form validation

See the example application source for a complete sample app using the modal progress HUD. Included in the example is a method for using a form's validators while making async calls (see flutter/issues/9688 for details).

Issues and feedback

Please file issues to send feedback or report a bug. Thank you!

所屬分類

原始碼儲存庫

使用此套件的專案