A simple modal progress HUD (heads-up display, or progress indicator) for flutter

Overview

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!

Comments
  • Pre-build stack in constructor for performance enhancement

    Pre-build stack in constructor for performance enhancement

    You are welcome, thank you for implementing such good idea of modal hud!

    Btw, I think that solution can be optimized even further because we can create a list of widgets for a stack right in the constructor, remove the most of logic and construction from the build function and only return there "child" or "stack" depending on async flag.

    But the most important was done already: do not complicate the widgets hierarchy in the most common case when hud is off.

    Originally posted by @arsenioo in https://github.com/mmcc007/modal_progress_hud/pull/14#issuecomment-474314257

    opened by mmcc007 3
  • Exception while using inside a ListView

    Exception while using inside a ListView

    ════════ Exception caught by rendering library ═════════════════════════════════
    The following assertion was thrown during performLayout():
    BoxConstraints forces an infinite height.
    
    These invalid constraints were provided to RenderDecoratedBox's layout() function by the following function, which probably computed the invalid constraints in question:
      RenderConstrainedBox.performLayout (package:flutter/src/rendering/proxy_box.dart:270:13)
    The offending constraints were: BoxConstraints(w=320.0, h=Infinity)
    The relevant error-causing widget was
        ModalProgressHUD 
    lib/…/welcome/user_profile_update_form.dart:58
    When the exception was thrown, this was the stack
    #0      BoxConstraints.debugAssertIsValid.<anonymous closure>.throwError 
    package:flutter/…/rendering/box.dart:519
    #1      BoxConstraints.debugAssertIsValid.<anonymous closure> 
    package:flutter/…/rendering/box.dart:563
    #2      BoxConstraints.debugAssertIsValid 
    package:flutter/…/rendering/box.dart:567
    #3      RenderObject.layout 
    package:flutter/…/rendering/object.dart:1672
    #4      RenderConstrainedBox.performLayout 
    package:flutter/…/rendering/proxy_box.dart:270
    ...
    
    opened by MartinJLee 1
  • 'package:flutter/src/rendering/object.dart': Failed assertion: line 1645 pos 12: '!_debugDoingThisLayout': is not true.

    'package:flutter/src/rendering/object.dart': Failed assertion: line 1645 pos 12: '!_debugDoingThisLayout': is not true.

    Hi

    Thanks for a great plugin, but I just installed an I get this exception when using it

    'package:flutter/src/rendering/object.dart': Failed assertion: line 1645 pos 12: '!_debugDoingThisLayout': is not true.

    I followed the example on my project.

    Here doctor output

    $ flutter doctor
    Doctor summary (to see all details, run flutter doctor -v):
    [√] Flutter (Channel master, v1.10.3-pre.46, on Microsoft Windows [Version 10.0.18362.418], locale en-ZA)
     
    [√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    [!] Android Studio (version 3.4)
        X Flutter plugin not installed; this adds Flutter specific functionality.
        X Dart plugin not installed; this adds Dart specific functionality.
    [√] VS Code (version 1.39.1)
    [√] Connected device (1 available)
    
    ! Doctor found issues in 1 category.
    
    good first issue waiting for response 
    opened by siyasangab 1
  • It doesn't work,if i call othen method Under the showState Until the method is executed

    It doesn't work,if i call othen method Under the showState Until the method is executed

    and i use

    new Future.delayed(new Duration(seconds: 1), () {
         //call othen methond
          });
    

    the circle Stop turning, how can i use this? @mmcc007

    waiting for response 
    opened by jjjachyty 1
  • HUD is not appearing

    HUD is not appearing

    Hi,

    I got this error from logs:

    I/flutter (29162): Another exception was thrown: BoxConstraints forces an infinite height. I/flutter (29162): Another exception was thrown: RenderBox was not laid out: RenderConstrainedBox#5e18e relayoutBoundary=up15 NEEDS-PAINT I/flutter (29162): Another exception was thrown: RenderBox was not laid out: RenderSemanticsAnnotations#32bdb relayoutBoundary=up14 NEEDS-PAINT I/flutter (29162): Another exception was thrown: RenderBox was not laid out: RenderPointerListener#980e2 relayoutBoundary=up13 NEEDS-PAINT I/flutter (29162): Another exception was thrown: RenderBox was not laid out: RenderSemanticsGestureHandler#24ed8 relayoutBoundary=up12 NEEDS-PAINT I/flutter (29162): Another exception was thrown: RenderBox was not laid out: RenderExcludeSemantics#76cbb relayoutBoundary=up11 NEEDS-PAINT I/flutter (29162): Another exception was thrown: RenderBox was not laid out: RenderBlockSemantics#56409 relayoutBoundary=up10 NEEDS-PAINT I/flutter (29162): Another exception was thrown: RenderBox was not laid out: RenderOpacity#6bd88 relayoutBoundary=up9 NEEDS-PAINT

    good first issue waiting for response 
    opened by x8Haider 1
  • xception thrown by package modal_progress_hud - its simple impl only

    xception thrown by package modal_progress_hud - its simple impl only

    Steps to Reproduce Basic Implementation of Flutter package : https://pub.dartlang.org/packages/modal_progress_hud

    as shown in the example.

    Logs I/flutter (28537): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ I/flutter (28537): The following assertion was thrown building LoginPage(dirty, state: _LoginPageState#f76d1): I/flutter (28537): 'package:modal_progress_hud/modal_progress_hud.dart': Failed assertion: line 43 pos 16: 'child != I/flutter (28537): null': is not true. I/flutter (28537): I/flutter (28537): Either the assertion indicates an error in the framework itself, or we should provide substantially I/flutter (28537): more information in this error message to help you determine and fix the underlying cause. I/flutter (28537): In either case, please report this assertion by filing a bug on GitHub: I/flutter (28537): https://github.com/flutter/flutter/issues/new?template=BUG.md I/flutter (28537): I/flutter (28537): When the exception was thrown, this was the stack: I/flutter (28537): #2 new ModalProgressHUD (package:modal_progress_hud/modal_progress_hud.dart:43:16) I/flutter (28537): #3 _LoginPageState.build (package:flutter_app/page/login.dart:185:13) I/flutter (28537): #4 StatefulElement.build (package:flutter/src/widgets/framework.dart:3809:27) I/flutter (28537): #5 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3721:15) I/flutter (28537): #6 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5) I/flutter (28537): #7 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)

    opened by pavanjoshi 1
  • close the progress indicator

    close the progress indicator

    hello, I tried to add a function to close the progress indicator manualy (button) or automaticaly (delay) but I havn't succeded. I would add the posibility for the user to close the progress indicator if there is no connection.

    opened by nitneuq33000 1
  • Navbar and keyboard

    Navbar and keyboard

    Hi!

    Using the following settings, the navbar isn't being hidden when the keyboard appears

    return Scaffold(
          body: PersistentTabView(
            controller: _controller,
            screens: _InitialWidgetState._pages
                .map((e) => SafeArea(child: e.value1))
                .toList(),
            items: _InitialWidgetState._pages
                .map((e) => PersistentBottomNavBarItem(
                      icon: e.value2,
                      title: e.value3,
                      inactiveColor: Colors.black,
                      titleFontSize: Theme.of(context).textTheme.bodyText2.fontSize,
                    ))
                .toList(),
            popAllScreensOnTapOfSelectedTab: false,
            navBarHeight: 65,
            navBarStyle: NavBarStyle.style13,
            decoration: NavBarDecoration(
              borderRadius: BorderRadius.circular(15),
              boxShadow: const [BoxShadow()],
            ),
          ),
          
        );
    
    opened by fernando-s97 0
  • Using in InitState()

    Using in InitState()

    How do we use this library when using an Async method in initState? We have a dependency on Widget while in InitState, no widget has been created yet.

    opened by esmaeil-ahmadipour 0
  • The referenced page is not safety

    The referenced page is not safety

    On the top page of modal_progress_hud(https://pub.dev/packages/modal_progress_hud#-installing-tab-), you introduce an article that you are inspired, but that page seems to be currently redirected to another insecure page. I think you should disable that link for now.

    opened by inclu-cat 0
  • Support for null-safety

    Support for null-safety

    • Package migrated to null safety.
    • Example project upgraded to support Android embedding v2 and Flutter web. changed the version to 1.0.0 to indicate breaking changes.
    opened by luis901101 0
Owner
Maurice McCabe
Flutter fan
Maurice McCabe
A clean and lightweight progress HUD for your iOS and tvOS app.

SVProgressHUD SVProgressHUD is a clean and easy-to-use HUD meant to display the progress of an ongoing task on iOS and tvOS. Demo Try SVProgressHUD on

SVProgressHUD 12.4k Jan 3, 2023
Flutter package to get keyboard height. Can be used to display a sticker/emoji modal with correct height.

flutter_persistent_keyboard_height Flutter package to get keyboard height. The height is persisted during app sessions and keyboard states (you can us

Arshak Aghakaryan 13 Oct 17, 2022
Smooth-Page-Indicator-Example-Flutter - A simple example about smooth page indicator in Flutter

Smooth Page Indicator Example - Flutter Screenshots ⚠️ Essential Packages smooth

AmirHossein Bayat 6 Dec 7, 2022
Iosish indicator - 🍎 Create awesome and simple iOS style floating indicator which can be found when silent/sleep mode switched on Flutter.

Iosish indicator - ?? Create awesome and simple iOS style floating indicator which can be found when silent/sleep mode switched on Flutter.

Kim Seung Hwan 2 Apr 1, 2022
Flutter plugin to display a simple steps indicator line widget

steps_indicator A simple steps indicator widget Installation Add steps_indicator: ^1.3.0 in your pubspec.yaml dependencies. And import it: import 'pac

Hugo EXTRAT 49 Oct 18, 2022
A simple button that gives you the possibility to transform into a circular one and shows a progress indicator

Progress Button A simple button that gives you the possibility to transform into

Daniel B Schneider 0 Dec 22, 2021
Flutter component Gradient Progress Indicator

Gradient Progress Indicator Introduction This package shows a circular progress indicator with gradient colors, and it is possible insert texts inside

Otoniel Moreira Duarte 2 Dec 5, 2022
This example uses a ScrollView, JSON Rest API, Navigation, Alert Pop Up, Progress Indicator, Globals, Images in a shared asset folder, and 100% Shared Code

This example uses a ScrollView, JSON Rest API, Navigation, Alert Pop Up, Progress Indicator, Globals, Images in a shared asset folder, and 100% Shared Code. Now with the ability to login with FaceID, TouchID, and Fingerprint Reader on Android.

Rody Davis 672 Jan 6, 2023
Display images flutter - Simple app to display images in flutter

Display Images In Flutter Simple app to display images in a flutter. In this dem

Manish Ahire 1 Jan 29, 2022
Flutter modal bottom route - A flutter route animation

flutter_modal_bottom_route This is a flutter route animation demo. See Chinouo J

null 4 Aug 19, 2022
Adaptive dialog - Show alert dialog or modal action sheet adaptively according to platform.

adaptive_dialog Show alert dialog or modal action sheet adaptively according to platform. showOkAlertDialog Convenient wrapper of showAlertDialog. iOS

Masayuki Ono (mono) 244 Dec 17, 2022
A Very Flexible Widget that can Implement Material Sheets on all Directions, both modal and persistent, and consequently a Material Navigation Drawer

Flutter_MaterialSheetAndNavigationDrawer If this project helped you reduce developement time or you just want to help me continue making useful tools

Bryan Cancel 30 Dec 4, 2021
Flutter ticket pass - A Flutter Widget to display the details of a ticket/pass purchased by customers and display the details of the purchase

ticket_pass_package A Flutter package to display the purchase of a ticket/pass along with additional details such as list of buyers. The source code i

null 40 Aug 13, 2022
A Flutter step_tracker plugin is collect information from user and display progress through a sequence of steps. this plugin also have privilege for fully customization from user side. like flipkart, amazon, myntra, meesho.

step_tracker plugin A Flutter step_tracker plugin is collect information from user and display progress through a sequence of steps. this plugin also

Roshan nahak 5 Oct 21, 2022
Flutter package to diplay progress through a milestone progress widget

milestone_progress Flutter package for IOS and Android to display progress through milestone progress widget. Screenshots ## Usage [Example]https://gi

Harpreet Singh 16 Aug 4, 2020
Wave progress - A custom wave progress widget

wave_progress_widget A customable wave progress widget Preview How to use Add this to your package's pubspec.yaml file: dependencies: wave_progress_

idan ben shimon 41 Jul 18, 2022
A simple ratingbar for flutter which also include a rating bar indicator, supporting any fraction of rating.

A simple yet fully customizable rating bar for flutter which also include a rating bar indicator, supporting any fraction of rating. Salient Features

Sarbagya Dhaubanjar 324 Dec 27, 2022
Simple alarm app - An alarm with analog clock face and digital indicator in the center for flutter

simple_alarm_app A new Flutter project. Getting Started It's an alarm with analo

null 1 Mar 14, 2022
A tab bar widget for Flutter 💙 with point indicator.

flutter_point_tab_bar A tab bar widget with point indicator. Demo Usage TabBar( controller: _tabController, indicator: PointTabIndicator(

Hiển Lê 5 Sep 16, 2022