uiblock 0.2.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 61

uiblock #

pub package GitHub Stars Platform

Easiest and simplest method to block/unblock ui for your flutter apps.

One line of code to block/unblock ui and stop user from navigating during loading or processing in your flutter apps. You could use it as a widget or directly as a global service/util.

  • Fully customizable
  • Android and IOS
  • Easy and Simple
  • No other dependencies
  • Well documented
  • Production ready

Getting Started #

Add the dependency uiblock: ^0.1.0 to your project and start using uiblock everywhere:

import 'package:uiblock/uiblock.dart';

To block ui

 // default
 UIBlock.block(context);
 
 //OR

 // if using globalKey
 UIBlock.block(_scaffoldGlobalKey.currentContext);

To unblock ui

 // call unblock after blockui to dissmiss
 UIBlock.unblock(context);

 //OR

 // if using globalKey
 UIBlock.unblock(_scaffoldGlobalKey.currentContext);

#

Using as a widget #

//toggle showLoader to block/unblock
FlatButton(
    child: Text('Load Async'),
    onPressed: () {
        setState(() {
            showLoader = !showLoader;
        });
    },
),

 // easily create custom block ui body
 Container(
    height: _height,
    child: UIBlock(
        loadingStateFromFuture: () async {
        if (showLoader) {
            // return null, to block ui
            return null;
        }
        // unblocks ui on hasData or hasError
        return Future.value(Random().nextInt(200));
        },
        barrierColor: Colors.blueGrey,
        barrierOpacity: 0.2,
        loadingTextWidget: Text('Loading data...'),
        hideBuilderOnNullData: true,
        builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
            return Center(child: Text('Async Data ${snapshot.data}'));
        },
    ),
 );

#

Blocking with text #

UIBlock.block(
    _scaffoldGlobalKey.currentContext,
    canDissmissOnBack: true,
    loadingTextWidget: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Text(
        'Press back to dissmiss',
        textAlign: TextAlign.center,
        style: TextStyle(
            color: Colors.white,
            fontSize: 18.0,
            fontWeight: FontWeight.w600,
        ),
        ),
    ),
);

Creating using child builder #

 // easily create custom block ui body
 UIBlock.block(
     _scaffoldGlobalKey.currentContext,
    backgroundColor: Colors.green.withOpacity(0.5),
    imageFilter: ImageFilter.blur(sigmaX: 5.0, sigmaY: 5.0),
    childBuilder: (BuildContext context) {
        // return your widget here
    },
 );

 // Don't forget to call unblock after block :)

For more details have a look at the other examples.

#

Properties #

PropertyTypeDefault
context (required)BuildContext-
childBuilderFunction-
customLoaderChildWidget-
loadingTextWidgetWidget-
imageFilterImageFilter-
backgroundColorColortransparent
canDissmissOnBackboolfalse

Widget Properties #

PropertyTypeDefault
builderFunctionyou implement it
loadingStateFromFutureFutureyour future function (APIs,etc)
loaderBuilderFunction-
customLoaderChildWidget-
loadingTextWidgetWidget-
offsetoffset-
barrierOpacitydouble0.4
barrierColorColorblack45
canDismissboolfalse
hideBuilderOnNullDataboolfalse

#

Improve #

Help me by reporting bugs, submit new ideas for features or anything else that you want to share.

  • Just write an issue on GitHub. ✏️
  • And don't forget to hit the like button for this package ✌️

[0.2.0] - 17 May 2020 #

  • You can now use UIBlock as a widget as well
  • Docs updated

[0.1.0] - 17 May 2020 #

  • Initial Release

example/lib/main.dart

import 'dart:async';
import 'dart:math';
import 'dart:ui';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:uiblock/default_uiblock_loader.dart';
import 'package:uiblock/uiblock.dart';

GlobalKey _scaffoldGlobalKey = GlobalKey();

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'UI Block Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key}) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  // could be anything other than string,
  // depends on your BackdropModalRoute<T> return type
  String backdropResult = '';

  // ValueListenable<int> _listenable = ValueListenable();
  ValueNotifier<int> _counter = ValueNotifier<int>(0);

  bool showLoader = false;

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Scaffold(
        key: _scaffoldGlobalKey,
        appBar: AppBar(
          title: Text('UIBlock Demo'),
        ),
        body: Padding(
          padding: const EdgeInsets.all(24.0),
          child: Column(
            mainAxisSize: MainAxisSize.max,
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              FlatButton(
                child: Text('Load Async'),
                onPressed: () {
                  setState(() {
                    showLoader = !showLoader;
                  });
                },
              ),
              Container(
                height: 100,
                child: UIBlock(
                  loadingStateFromFuture: () async {
                    if (showLoader) {
                      // return null, to show loader
                      return null;
                    }
                    // hides loader on hasData or HasError
                    return Future.value(Random().nextInt(200));
                  },
                  barrierColor: Colors.blueGrey,
                  barrierOpacity: 0.2,
                  loadingTextWidget: Text('Loading data...'),
                  hideBuilderOnNullData: true,
                  builder:
                      (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
                    return Center(
                      child: Text('Async Data ${snapshot.data}'),
                    );
                  },
                ),
              ),
              Expanded(
                child: ListView(
                  children: <Widget>[
                    // default
                    _buildDefault(context),

                    SizedBox(height: 24),

                    // default dissmissible
                    _buildDefaultDissmissible(context),

                    SizedBox(height: 24),

                    // default with text
                    _buildDefaultWithText(context),

                    SizedBox(height: 24),

                    // custom using childBUilder
                    _buildCustomWithChildBuilder(context),
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  Widget _buildDefault(BuildContext context) {
    return Container(
      child: FlatButton(
        child: Text(
          "Default UIBlock (Dissmiss Disabled)",
          textAlign: TextAlign.center,
        ),
        onPressed: () async {
          UIBlock.block(_scaffoldGlobalKey.currentContext);

          await Future.delayed(Duration(seconds: 3), () => '1');

          UIBlock.unblock(_scaffoldGlobalKey.currentContext);
        },
      ),
    );
  }

  Widget _buildDefaultDissmissible(BuildContext context) {
    return Container(
      child: FlatButton(
        child: Text(
          "Default UIBlock (Dissmiss Enabled)",
          textAlign: TextAlign.center,
        ),
        onPressed: () async {
          UIBlock.block(
            _scaffoldGlobalKey.currentContext,
            canDissmissOnBack: true,
            loadingTextWidget: Padding(
              padding: const EdgeInsets.all(8.0),
              child: Text(
                'Press back to dissmiss',
                textAlign: TextAlign.center,
                style: TextStyle(
                  color: Colors.white,
                  fontSize: 18.0,
                  fontWeight: FontWeight.w600,
                ),
              ),
            ),
          );
        },
      ),
    );
  }

  Widget _buildDefaultWithText(BuildContext context) {
    return Container(
      child: FlatButton(
        child: Text(
          "Default UIBlock With Text (Dissmiss Disabled)",
          textAlign: TextAlign.center,
        ),
        onPressed: () async {
          UIBlock.block(
            _scaffoldGlobalKey.currentContext,
            loadingTextWidget: Padding(
              padding: const EdgeInsets.all(8.0),
              child: Text(
                'Cannot pop this loader, will dismiss in 3 seconds',
                textAlign: TextAlign.center,
                style: TextStyle(
                  color: Colors.white,
                  fontSize: 18.0,
                  fontWeight: FontWeight.w600,
                ),
              ),
            ),
          );

          Future.delayed(
            Duration(seconds: 3),
            () => UIBlock.unblock(_scaffoldGlobalKey.currentContext),
          );
        },
      ),
    );
  }

  Widget _buildCustomWithChildBuilder(BuildContext context) {
    return Container(
      child: FlatButton(
        child: Text(
          "Custom UIBlock With Child Builder & State",
          textAlign: TextAlign.center,
        ),
        onPressed: () async {
          UIBlock.block(
            _scaffoldGlobalKey.currentContext,
            backgroundColor: Colors.green.withOpacity(0.5),
            imageFilter: ImageFilter.blur(sigmaX: 5.0, sigmaY: 5.0),
            childBuilder: (BuildContext context) {
              _counter.value = 0;

              // increment counter
              Timer.periodic(Duration(seconds: 1), (timer) async {
                _counter.value++;

                if (_counter.value == 3) {
                  timer.cancel();
                  UIBlock.unblock(context);

                  await Future.delayed(
                      Duration(seconds: 2), () => _counter.value = 0);
                }
              });

              return Padding(
                padding: const EdgeInsets.all(24.0),
                child: Center(
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: <Widget>[
                      UIBlockDefaultLoader(),
                      ValueListenableBuilder<int>(
                        valueListenable: _counter,
                        builder: (context, value, child) {
                          return Padding(
                            padding: const EdgeInsets.all(12.0),
                            child: Text(
                              'Custom loader using "ChildBuilder".\n\n Closing in $value',
                              textAlign: TextAlign.center,
                              style: TextStyle(
                                color: Colors.black,
                                fontSize: 18.0,
                                fontWeight: FontWeight.w600,
                              ),
                            ),
                          );
                        },
                      ),
                    ],
                  ),
                ),
              );
            },
          );
        },
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  uiblock: ^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:uiblock/uiblock.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
23
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
61
Learn more about scoring.

We analyzed this package on Jul 9, 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:

  • uiblock that is a package requiring null.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.1
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