loading_hud 0.2.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 68

LoadingHud #

A dialog with a loading indicator.

showcase

Getting Started #

Add dependency #

dependencies:
  loading_hud: ^0.2.0

Examples #

var loadingHud = LoadingHud(
  context,
  cancelable: true,                  // Cancelable when pressing Android back key
  canceledOnTouchOutside: true,      // Cancelable when touch outside of the LoadingHud
  dimBackground: true,               // Dimming background when LoadingHud is showing
  hudColor: Color(0x99000000),       // Color of the ProgressHud
  indicator: DefaultLoadingIndicator(
    color: Colors.white,
  ),
  iconSuccess: Icon(                 // Success icon
    Icons.done,
    color: Colors.white,
  ),
  iconError: Icon(                   // Error icon
    Icons.error,
    color: Colors.white,
  ),
  future: loadingSomething();
);

Future<Text> loadingSomething() async {
  try {
    var data = await loadingSomthingTimeConsuming();
    return Text('That was great!');
  } catch (e) {
    throw Text('Something went wrong.');
  }
}
  
/// Show LoadingHud
loadingHud.show();

/// Dismiss LoadingHud
loadingHud.dismiss();

0.1.0 #

  • Initial release.

0.2.0 #

  • Support displaying success and error message when loading is completed.

example/lib/main.dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:loading_hud/loading_hud.dart';
import 'package:loading_hud/loading_indicator.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'LoadingHUD',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('LoadingHUD'),
      ),
      body: ListView(
        children: <Widget>[
          _buildListItem(
            context,
            title: 'Show default',
            onTap: () => _buildDefaultHud(context).show(),
          ),
          _buildListItem(
            context,
            title: 'Show for 3 seconds',
            onTap: () {
              var progressHud = _buildUnCancelableHud(context);
              progressHud.show();
              Future.delayed(Duration(seconds: 3), () {
                progressHud.dismiss();
              });
            },
          ),
          _buildListItem(
            context,
            title: 'Show with background dimless',
            onTap: () => _buildNoDimBackgroundHud(context).show(),
          ),
          _buildListItem(
            context,
            title: 'Show success',
            onTap: () => _buildSuccessHud(context).show(),
          ),
          _buildListItem(
            context,
            title: 'Show error',
            onTap: () => _buildErrorHud(context).show(),
          ),
        ],
      ),
    );
  }

  Widget _buildListItem(BuildContext context,
      {String title, VoidCallback onTap}) {
    return Container(
      decoration: BoxDecoration(
        border: Border(
          bottom: BorderSide(
            color: Colors.grey,
            width: 0,
          ),
        ),
      ),
      child: ListTile(
        title: Text(title),
        onTap: onTap,
      ),
    );
  }

  LoadingHud _buildDefaultHud(BuildContext context) {
    return LoadingHud(context);
  }

  LoadingHud _buildUnCancelableHud(BuildContext context) {
    return LoadingHud(
      context,
      cancelable: false,
      canceledOnTouchOutside: false,
    );
  }

  LoadingHud _buildNoDimBackgroundHud(BuildContext context) {
    return LoadingHud(
      context,
      dimBackground: false,
      hudColor: Color(0x99000000),
      indicator: DefaultLoadingIndicator(
        color: Color(0xFFFFFFFF),
      ),
    );
  }

  LoadingHud _buildSuccessHud(BuildContext context) {
    return LoadingHud(
      context,
      iconSuccess: Icon(Icons.done),
      iconError: Icon(Icons.error),
      future: onSuccess(),
    );
  }

  Future<Text> onSuccess() {
    return Future.delayed(Duration(seconds: 2), () {
      return Text('That was great!');
    });
  }

  LoadingHud _buildErrorHud(BuildContext context) {
    return LoadingHud(
      context,
      hudColor: Colors.black54,
      indicator: DefaultLoadingIndicator(
        color: Color(0xFFFFFFFF),
      ),
      iconSuccess: Icon(
        Icons.done,
        color: Colors.white,
      ),
      iconError: Icon(
        Icons.error,
        color: Colors.white,
      ),
      future: onError(),
    );
  }

  Future<Text> onError() {
    try {
      return Future.delayed(Duration(seconds: 2), () {
            throw Text(
              'Something went wrong.',
              style: TextStyle(
                fontSize: 16,
                color: Colors.white,
                decoration: TextDecoration.none,
              ),
            );
          });
    } catch (e) {
      print(e);
    }
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  loading_hud: ^0.2.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:loading_hud/loading_hud.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
43
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
68
Learn more about scoring.

We analyzed this package on Jul 11, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

Because:

  • loading_hud that is a package requiring null.

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test