Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

flushbar

a flexible widget for user notification. customize your text, button, duration, animations and much more. for android devs, it is made to replace snackbars and toasts.

use this package if you need more customization when notifying your user. for android developers, it is made to substitute toasts and snackbars. ios developers, i don’t know what you use there, but you will like it.

see the install instructions.

this is a flutter widget inspired by flashbar. development of flushbar and flashbar are totally separate.

flushbar_logo

quick reference

since customization requires a lot of properties, here is a quick cheatsheet:

property what does it do
title the title displayed to the user
message the message displayed to the user.
titletext replaces [title]. although this accepts a [widget], it is meant to receive [text] or [richtext]
messagetext replaces [message]. although this accepts a [widget], it is meant to receive [text] or [richtext]
icon you can use any widget here, but i recommend [icon] or [image] as indication of what kind of message you are displaying. other widgets may break the layout
shouldiconpulse an option to animate the icon (if present). defaults to true.
aroundpadding adds a custom padding to flushbar
borderradius adds a radius to all corners of flushbar. best combined with [aroundpadding]. i do not recommend using it with [showprogressindicator] or [leftbarindicatorcolor]
backgroundcolor flushbar background color. will be ignored if [backgroundgradient] is not null.
leftbarindicatorcolor if not null, shows a left vertical bar to better indicate the humor of the notification. it is not possible to use it with a [form] and i do not recommend using it with [linearprogressindicator].
boxshadows the shadows generated by flushbar. leave it null if you don’t want a shadow. you can use more than one if you feel the need. check this example
backgroundgradient flushbar background gradient. makes [backgroundcolor] be ignored.
mainbutton a [flatbutton] widget if you need an action from the user.
ontap a callback that registers the user’s click anywhere. an alternative to [mainbutton]
duration how long until flushbar will hide itself (be dismissed). to make it indefinite, leave it null.
isdismissible determines if the user can swipe to dismiss the bar. it is recommended that you set a [duration] if [isdismissible] is false. if the user swipes to dismiss it, no value will be returned.
dismissdirection flushbardismissdirection.vertical by default. can also be [flushbardismissdirection.horizontal] in which case both left and right dismiss are allowed.
flushbarposition flushbar can be based on [flushbarposition.top] or on [flushbarposition.bottom] of your screen. [flushbarposition.bottom] is the default.
flushbarstyle flushbar can be floating or be grounded to the edge of the screen. if grounded, i do not recommend using [aroundpadding] or [borderradius]. [flushbarstyle.floating] is the default
forwardanimationcurve the [curve] animation used when show() is called. [curves.easeout] is default.
reverseanimationcurve the [curve] animation used when dismiss() is called. [curves.fastoutslowin] is default.
animationduration use it to speed up or slow down the animation duration
showprogressindicator true if you want to show a [linearprogressindicator].
progressindicatorcontroller an optional [animationcontroller] when you want to control the progress of your [linearprogressindicator].
progressindicatorbackgroundcolor a [linearprogressindicator] configuration parameter.
progressindicatorvaluecolor a [linearprogressindicator] configuration parameter.
overlayblur default is 0.0. if different than 0.0, creates a blurred overlay that prevents the user from interacting with the screen. the greater the value, the greater the blur.
overlaycolor default is [colors.transparent]. only takes effect if [overlayblur] > 0.0. make sure you use a color with transparency e.g. colors.grey[600].withopacity(0.2).
userinputform a [textformfield] in case you want a simple user input. every other widget is ignored if this is not null.
onstatuschanged a callback for you to listen to the different flushbar status

we are on youtube!

while studying flutter i stumbled on two amazing tutorials on how to use flushbar.
make sure you show those guys some love.

  1. a beginners tutorial by matej rešetár
  2. a more advanced usage by javier gonzález rodríguez

getting started

the examples bellow were updated for version 1.3.0. changes might have been made. see the changelog if any of the examples do not
reflect flushbar’s current state.

the possibilities

flushbar animated

a basic flushbar

the most basic flushbar uses only a message. failing to provide it before you call show() will result in a runtime error.
duration, if not provided, will create an infinite flushbar, only dismissible by code, back button clicks, or a drag (case isdismissible is set to true).

  • note that only message is a required parameter. all the other ones are optional
class yourawesomeapp extends statelesswidget {

  @override
  widget build(buildcontext context) {
    return materialapp(
      title: 'yourawesomeapp',
      home: scaffold(
        container(
          child: center(
            child: materialbutton(
              onpressed: (){
                flushbar(
                  title:  "hey ninja",
                  message:  "lorem ipsum is simply dummy text of the printing and typesetting industry",
                  duration:  duration(seconds: 3),              
                )..show(context);
              },
            ),
          ),
        ),
      ),
    );
  }
}

basic example

lets get crazy flushbar

here is how customized things can get.

flushbar(
      title: "hey ninja",
      message: "lorem ipsum is simply dummy text of the printing and typesetting industry",
      flushbarposition: flushbarposition.top,
      flushbarstyle: flushbarstyle.floating,
      reverseanimationcurve: curves.decelerate,
      forwardanimationcurve: curves.elasticout,
      backgroundcolor: colors.red,
      boxshadows: [boxshadow(color: colors.blue[800], offset: offset(0.0, 2.0), blurradius: 3.0)],
      backgroundgradient: lineargradient(colors: [colors.bluegrey, colors.black]),
      isdismissible: false,
      duration: duration(seconds: 4),
      icon: icon(
        icons.check,
        color: colors.greenaccent,
      ),
      mainbutton: flatbutton(
        onpressed: () {},
        child: text(
          "clap",
          style: textstyle(color: colors.amber),
        ),
      ),
      showprogressindicator: true,
      progressindicatorbackgroundcolor: colors.bluegrey,
      titletext: text(
        "hello hero",
        style: textstyle(
            fontweight: fontweight.bold, fontsize: 20.0, color: colors.yellow[600], fontfamily: "shadowsintolighttwo"),
      ),
      messagetext: text(
        "you killed that giant monster in the city. congratulations!",
        style: textstyle(fontsize: 18.0, color: colors.green, fontfamily: "shadowsintolighttwo"),
      ),
    );

complete example

  • don’t forget to call show() or the bar will stay hidden.
  • to deactivate any of those properties, pass null to it.

styles

flushbar can be either floating or grounded to the edge of the screen.
i don’t recommend using aroundpadding or borderradius if you chose flushbarstyle.grounded style.

flushbar(flushbarstyle: flushbarstyle.floating)

or

flushbar(flushbarstyle: flushbarstyle.grounded)
floating style grounded style
floating style grounded style

padding and border radius

you can give it some padding and a border radius. works best with flushbarstyle.floating

flushbar(
  aroundpadding: edgeinsets.all(8),
  borderradius: 8,
);
  

padding and radius

left indicator bar

flushbar has a lateral bar to better convey the humor of the notification. to use it, simple give leftbarindicatorcolor a color.

flushbar(
  message: "lorem ipsum is simply dummy text of the printing and typesetting industry",
  icon: icon(
    icons.info_outline,
    size: 28.0,
    color: colors.blue[300],
    ),
  duration: duration(seconds: 3),
  leftbarindicatorcolor: colors.blue[300],
)..show(context);

left indicator example

customize your text

if you need a more fancy text, you can use text or richtext
and pass it to the titletext or messagetext variables.

  • note that title will be ignored if titletext is not null
  • note that message will be ignored if messagetext is not null
flushbar(
  title: "hey ninja", //ignored since titletext != null
  message: "lorem ipsum is simply dummy text of the printing and typesetting industry", //ignored since messagetext != null
  titletext: text("hello hero", style: textstyle(fontweight: fontweight.bold, fontsize: 20.0 color: colors.yellow[600], fontfamily:"shadowsintolighttwo"),),
  messagetext: text("you killed that giant monster in the city. congratulations!", style: textstyle(fontsize: 16.0, color: colors.green[fontfamily: "shadowsintolighttwo"),),
)..show(context);

customized text

customize background and shadow

you can paint the background with any color you want. you can use any shadow you want.
just give it a backgroundcolor and boxshadows.

flushbar(
  title: "hey ninja",
  message: "lorem ipsum is simply dummy text of the printing and typesetting industry",
  backgroundcolor: colors.red,
  boxshadows: [boxshadow(color: colors.red[800], offset: offset(0.0, 2.0), blurradius: 3.0,)],
)..show(context);

background and shadow

want a gradient in the background? no problem.

  • note that backgroundcolor will be ignored while backgroundgradient is not null
flushbar(
  title: "hey ninja",
  message: "lorem ipsum is simply dummy text of the printing and typesetting industry",
  backgroundgradient: lineargradient(colors: [colors.colors.teal],),
  backgroundcolor: colors.red,
  boxshadows: [boxshadow(color: colors.blue[800], offset: offset(0.0, 2.0), blurradius: 3.0,)],
)..show(context);

background gradient

icon and button action

let us put a icon that has a pulseanimation. icons have this animation by default and cannot be changed as of now.
also, let us put a button. have you noticed that show() returns a future?
this future will yield a value when you call dismiss([t result]).
i recommend that you specify the result generic type if you intend to collect an user input.

flushbar flush;
bool _wasbuttonclicked;
@override
  widget build(buildcontext context) {
    return container(
      child: center(
        child: materialbutton(
          onpressed: () {
            flush = flushbar<bool>(
              title: "hey ninja",
              message: "lorem ipsum is simply dummy text of the printing and typesetting industry",
              icon: icon(
                       icons.info_outline,
                       color: colors.blue,),
              mainbutton: flatbutton(
                             onpressed: () {
                                 flush.dismiss(true); // result = true
                               },
                             child: text(
                               "add",
                               style: textstyle(color: colors.amber),
                             ),
                           ),) // <bool> is the type of the result passed to dismiss() and collected by show().then((result){})
              ..show(context).then((result) {
                setstate(() { // setstate() is optional here
                  _wasbuttonclicked = result;
                });
              });
          },
        ),
      ),
    );
  }

icon and button

flushbar position

flushbar can be at flushbarposition.bottom or flushbarposition.top.

flushbar(
  flushbarposition: flushbarposition.top,
  title: "hey ninja",
  message: "lorem ipsum is simply dummy text of the printing and typesetting industry",)..show(context);

bar position

duration and dismiss policy

by default, flushbar is infinite. to set a duration, use the duration property.
by default, flushbar is dismissible by the user. a right or left drag will dismiss it.
set isdismissible to false to change this behaviour.

flushbar(
  title: "hey ninja",
  message: "lorem ipsum is simply dummy text of the printing and typesetting industry",
  duration: duration(seconds: 3),
  isdismissible: false,
)..show(context);

progress indicator

if you are loading something, use a linearprogressindicator
if you want an undetermined progress indicator, do not set progressindicatorcontroller.
if you want a determined progress indicator, you now have full control over the progress since you own the animationcontroller

  • there is no need to add a listener to your controller just to call setstate(){}. once you pass in your controller, flushbar will do this automatically. just make sure you call _controller.forward()

animationcontroller _controller = animationcontroller(
      vsync: this,
      duration: duration(seconds: 3),
    );

flushbar(
  title: "hey ninja",
  message: "lorem ipsum is simply dummy text of the printing and typesetting industry",
  showprogressindicator: true,
  progressindicatorcontroller: _controller,
  progressindicatorbackgroundcolor: colors.grey[800],
)..show(context);

show and dismiss animation curves

you can set custom animation curves using forwardanimationcurve and reverseanimationcurve.

flushbar(
  forwardanimationcurve: curves.decelerate,
  reverseanimationcurve: curves.easeout,
  title: "hey ninja",
  message: "lorem ipsum is simply dummy text of the printing and typesetting industry",
)..show(context);

listen to status updates

you can listen to status update using the onstatuschanged property.

  • note that when you pass a new listener using onstatuschanged, it will activate once immediately so you can check in what state the flushbar is.

flushbar flushbar = flushbar(title: "hey ninja", message: "lorem ipsum is simply dummy text of the printing and typesetting industry");

  flushbar
    ..onstatuschanged = (flushbarstatus status) {
      switch (status) {
        case flushbarstatus.showing:
          {
            dosomething();
            break;
          }
        case flushbarstatus.is_appearing:
          {
            dosomethingelse();
            break;
          }
        case flushbarstatus.is_hiding:
          {
            dosomethingelse();
            break;
          }
        case flushbarstatus.dismissed:
          {
            dosomethingelse();
            break;
          }
      }
    }
    ..show(context);

input text

sometimes we just want a simple user input. use the propertyuserinputform.

  • note that buttons, messages, and icons will be ignored if userinputform != null
  • dismiss(result) will yield result. dismiss() will yield null.
flushbar<list<string>> flush;
final globalkey<formstate> _formkey = globalkey<formstate>();
textformfield getformfield(string text) {
    return textformfield(
      initialvalue: text,
      style: textstyle(color: colors.white),
      maxlength: 100,
      maxlines: 1,
      maxlengthenforced: true,
      decoration: inputdecoration(
          fillcolor: colors.white10,
          filled: true,
          icon: icon(
            icons.label,
            color: colors.grey[500],
          ),
          border: underlineinputborder(),
          helpertext: "helper text",
          helperstyle: textstyle(color: colors.grey),
          labeltext: "label text",
          labelstyle: textstyle(color: colors.grey)),
    );
  }

flush = flushbar<list<string>>(
  userinputform = form(
          key: _formkey,
          child: column(
            mainaxissize: mainaxissize.min,
            children: [
              gettextformfield("initial value"),
              gettextformfield("initial value two"),
            ]
            align(
              alignment: alignment.bottomright,
              child: padding(
                padding: const edgeinsets.only(top: 8.0),
                child: materialbutton(
                  textcolor: colors.amberaccent,
                  child: text("submit"),
                  onpressed: () {
                    flush.dismiss([_controller1.value.text, _controller2.value.text]);
                  },
                ),
              ),
            )
          ],),),
)..show(context).then((result) {
        if (result != null) {
          string userinput1 = result[0];
          string userinput2 = result[1];
        }
      });

this example tries to mimic the material design style guide

bar input

flushbar helper

i made a helper class to facilitate the creation of the most common flushbars.

flushbarhelper.createsuccess({message, title, duration});
flushbarhelper.createinformation({message, title, duration});
flushbarhelper.createerror({message, title, duration});
flushbarhelper.createaction({message, title, duration flatbutton});
flushbarhelper.createloading({message,linearprogressindicator, title, duration, progressindicatorcontroller, progressindicatorbackgroundcolor});
flushbarhelper.createinputflushbar({textform});

Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Comments are closed.