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

所属分类

源码仓库

使用此插件的项目