搜索插件、代码仓与 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!

所属分类

源码仓库

使用此插件的项目