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

modal_progress_hud_nsn 封面
套件詳情v0.5.1

modal_progress_hud_nsn

一個帶有聲音空安全的模態進度指示器小部件。https://github.com/mmcc007/modal_progress_hud 的分支

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
1.3萬
喜歡數
302
Pub 分數
160

安裝套件

flutter pub add modal_progress_hud_nsn

套件介紹

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

一個 Flutter 套件,提供具備 Sound Null Safety 的模態進度指示器元件,用於在現有 UI 元素上顯示載入覆蓋層。這是原始 modal_progress_hud 的維護分支,針對現代 Dart 實踐進行優化。該元件在載入期間會阻擋使用者互動,並可透過布林旗標輕鬆控制。非常適合在多個平台顯示網路請求或長時間運作作業的載入狀態。

適用情境

  • 在 API 呼叫期間顯示載入狀態
  • 在表單提交期間阻止UI
  • 在後台任務中顯示進度
  • 增強資料擷取過程中的使用者體驗
  • 在登入流程中提供視覺反饋

主要特色

  • Sound Null Safety 支持
  • 用於可見性的簡單布林控制
  • 模態覆蓋層,停用底層 UI
  • 跨平台相容性
  • 與現有組件的輕鬆整合
  • 可自訂的載入指示器

適合對象

  • 使用空安全的 Flutter 開發人員
  • 需要清晰加載反饋的應用程式
  • 需要輕量級進度指示器的項目
  • 維護具有更新依賴項的舊代碼庫的團隊
  • 具有頻繁異步操作的UI密集型應用程式

使用建議

  • 可能需要手動處理嵌套疊加層
  • 不適用於非模態加載場景
  • 超出基本樣式的自訂功能有限
  • 依賴於父控制項的佈局約束
  • 最佳使用方式為一次僅有一個活躍加載狀態

原始 README

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

modal_progress_hud_nsn

pub package

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

A fork of the original modal_progress_hud by mmcc007 with Null Safety and additional features.

Usage

Add the modal_progress_hud_nsn to dependencies in pubspec.yaml.

dependencies:
    modal_progress_hud_nsn: ^0.5.1

Next, import the library into your app.

import 'package:modal_progress_hud_nsn/modal_progress_hud_nsn.dart';

Now, wrap your widget as a child of ModalProgressHUD, typically a form, together with a boolean variable that is maintained in local state.

...
bool _saving = false
...

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

Options

Below parameters can be customised accordingly.

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

Example

An example app that demonstrates the usage.

  1. On initial load, _saving defaults to 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.
Example Code
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),
    );
  }
}

Similar Alternatives

Useful Resources

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, request features or report a bug. Thank you!

所屬分類

原始碼儲存庫

使用此套件的專案