flushbar 0.8.1

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 93

Flushbar

Use this package if you need more customization when notifying your user. For Android developers, it is made to substitute toasts and snackbars.

See the install instructions.

This is a flutter widget inspired by Flashbar. Development of Flushbar and Flashbar are totally separate.

Getting Started

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, backbutton click, or a drag (case isDismissible is set to true).

class YourAwesomeApp extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'YourAwesomeApp',
      home: new 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, //Immutable
  reverseAnimationCurve: Curves.decelerate, //Immutable
  forwardAnimationCurve: Curves.elasticOut, //Immutable
  backgroundColor: Colors.red,
  shadowColor: Colors.blue[800],
  backgroundGradient: new LinearGradient(colors: [Colors.blu 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),
    ),
  ),
  linearProgressIndicator: LinearProgressIndicator(
    backgroundColor: Colors.blueGrey,
  ),
  titleText: new Text(
    "Hello Hero",
    style: TextStyle(fontWeight: FontWeight.bold, fontSize: color: Colors.yellow[600], fontFamily: "ShadowsIntoLightTwo"),
  ),
  messageText: new Text(
    "You killed that giant monster in the city. Congratulations!",
    style: TextStyle(fontSize: 18.0, color: Colors.green[fontFamily: "ShadowsIntoLightTwo"),
  ),
);

Complete Example

  • Note that the properties flushbarPosition, reverseAnimationCurve, forwardAnimationCurve are immutable and have to be set at construction time.
  • Don't forget to call show() or the bar will stay hidden.
  • To deactivate any of those properties, pass null to it.

Here is a notation a like to use.

flushbar
      ..title = "Title"
      ..message = "Message"
      ..titleText = Text()
      ..messageText = Text()
      ..duration = Duration()
      ..icon = Icon()
      ..mainButton = FlatButton()
      ..backgroundColor = Color()
      ..backgroundGradient = LinearGradient()
      ..isDismissible = true
      ..shadowColor = Color()
      ..linearProgressIndicator = LinearProgressIndicator()
      ..onStatusChanged = (status) {}
      ..show(context);

Left indicator bar

Flushbar has a lateral bar to better convey the humor of the notification. To use it, simple give leftBarIndicatorColor a color.

  • Note that we do not use a title in this example as it is not mandatory after version 0.8
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 create a Text 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 = new Text("Hello Hero",
      style:
          TextStyle(fontWeight: FontWeight.bold, fontSize: color: Colors.yellow[600], fontFa"ShadowsIntoLightTwo"))
  ..messageText = new 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. The same goes for shadows. shadow won't show by default. You will only see a shadow if you specify a color.

Flushbar()
  ..title = "Hey Ninja"
  ..message = "Lorem Ipsum is simply dummy text of the printing and typesetting industry"
  ..backgroundColor = Colors.red
  ..shadowColor = Colors.red[800]
  ..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 = new LinearGradient(colors: [Colors.Colors.teal])
  ..backgroundColor = Colors.red
  ..shadowColor = Colors.blue[800]
  ..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 this moment. 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 recomment that you specify the result generic type if you intend to collect an user input.

Flushbar flush;
bool _wasAddClicked;
@override
  Widget build(BuildContext context) {
    return Container(
      child: Center(
        child: MaterialButton(
          onPressed: () {
            flush = Flushbar<bool>() // <bool> is the type of the result passed to dismiss() and collected by show().then((result){})
              ..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),
                ),
              )
              ..show(context).then((result) {
                setState(() { // setState() is optional here
                  _wasAddClicked = result;
                });
              });
          },
        ),
      ),
    );
  }

Icon and Button

Flushbar position

Flushbar can be at FlushbarPosition.BOTTOM or FlushbarPosition.TOP.

  • This variable is immutable and can not be changed after the instance is created.
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. Use the isDismissible to change it.

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);

//TODO add gif

Progress Indicator

If you are loading something, use a LinearProgressIndicator If you want an undetermined progress indicator, do not set progressIndicatorController. If ou want a determined progress indicator, you now have full controll over the progress since you own the AnimationController

  • There is not 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);

//TODO add gif

Show and dismiss animation curves

You can set custom animation curves using forwardAnimationCurve and reverseAnimationCurve.

  • These properties are immutable
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);

//TODO add gif

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 = new GlobalKey<FormState>();
TextEditingController _controller1 = TextEditingController(text: "Initial Value");
TextEditingController _controller2 = TextEditingController(text: "Initial Value Two");
flush = Flushbar<List<String>>()
      ..userInputForm = Form(
          key: _formKey,
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
            TextFormField(
              controller: _controller1,
              onFieldSubmitted: (String value) {},
            ),
            TextFormField(
              controller: _controller2,
              onFieldSubmitted: (String value) {},
            ),
            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];
        }
      });

Bar input

This example tries to mimic the Material Design style guide This is the TextFormField customization omitted from the example above for simplicity:

TextFormField(
  initialValue: "Initial Value",
  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)),
)

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});

Give me a hand?

<a href="https://www.buymeacoffee.com/AndreHaueisen" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: auto !important;width: auto !important;" ></a>

[0.8.1] - 2018-08-12

Changes

  • Fixed Dart version issue

[0.8.0] - 2018-08-11

Breaking changes

  • Changed the behaviour of linearProgressIndicator to allow the user to controll its progress. See README.md for examples

Changes

  • Added a left vertical bar to better convey the humor of the notification. See README.md for examples
  • Title is not mandatory anymore

[0.7.6] - 2018-08-07

Changes

  • Version update to supprt master channel

[0.7.5] - 2018-07-28

Changes

  • Fix bug where keyboard did not show when using a Form
  • Flushbar is now compatible with the master channel
  • Bug fixes

[0.7.1] - 2018-07-08

Changes

  • Flushbar doc update

[0.7.0] - 2018-07-08

Breaking changes

  • Flushbar does not need a global instance anymore
  • Flushbar it now made be used only one time. After it hits the dismissed state, that instance wont work anymore
  • Due to the behaviour above, there is no need to call commitChanges() anymore
  • Flushbar does not need to be within a Stack widget anymore
  • Purged state eliminated
  • FlushbarMorph is now called FlushbarHelper

Changes

  • README.md is updated

Known issues

  • When using a Form, the keyboard is not shown. Still figuring out how to solve it.

[0.5.6] - 2018-06-20

Changed

  • Fixed dependency issue

[0.5.5] - 2018-06-20

Changed

  • Updated flushbar_morph
  • Updated sdk version

[0.5.4] - 2018-06-16

Changed

  • Flushbar now animates size changes when commit is called while showing
  • Layout refinements

[0.5.2] - 2018-06-05

Changed

  • User input now receives a Form to facilitate field validation

[0.5.1] - 2018-06-05

Changed

  • Fixed brain fart. Same changes as 0.5.0

[0.5.0] - 2018-06-05

Changed

  • Removed change...() functions. Cascade notation is now recommended
  • Update readme file
  • Default message font size reduced from 16.0 to 14.0
  • Default title font size reduced from 16.0 to 15.0

[0.4.7] - 2018-06-04

Changed

  • Fixed bug with bar duration
  • Blink animation when Flushbar is not dismissed now animates the whole bar and is synchronised with content change.

[0.4.5] - 2018-06-03

Added

  • Blink animation when commitChanges() is called when Flushbar is not dismissed. This provides a smooth content transition
  • Helper class to morph Flushbar (FlushbarMorph)

Changed

  • Code cleanup

[0.4.0] - 2018-05-27

Added

  • InputTextField

[0.3.1] - 2018-05-27

Changed

  • Fixed bar being automatically called
  • Title and message are not required at construction time
  • Better usage example
  • Removed callback from constructor

[0.3.0] - 2018-05-27

Changed

  • Removed the possibility to chose icon position
  • Widgets are now aligned correctly
  • Documentation improvements

[0.2.5] - 2018-05-26

Changed

  • Bug fixes
  • Moved icon animation into the flushbar
  • changeStatusListener() is now activated on change

[0.2.0] - 2018-05-24

Added

  • Removed requirement for a initial widget
  • OnStatusChanged callback so it is possible to listen to the various Flushbar status
  • The callback can be changed using changeStatusListener()
  • Started working on the README.md file

Changed

  • IconAwareAnimation is now more general and it is called PulseAnimator
  • Flushbar now accepts an Icon instead of only the IconData and IconColor
  • Alignment changes
  • Default background color

[0.0.1] - 2018-05-23

Added

  • Flushbar creation
  • Single button action
  • Status listeners
  • Left or right icon positioning
  • Top or bottom positioning

Use this package as a library

1. Depend on it

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


dependencies:
  flushbar: ^0.8.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


import 'package:flushbar/flushbar.dart';
  
Version Uploaded Documentation Archive
0.8.1 Aug 12, 2018 Go to the documentation of flushbar 0.8.1 Download flushbar 0.8.1 archive
0.8.0 Aug 11, 2018 Go to the documentation of flushbar 0.8.0 Download flushbar 0.8.0 archive
0.7.6 Aug 7, 2018 Go to the documentation of flushbar 0.7.6 Download flushbar 0.7.6 archive
0.7.5 Jul 28, 2018 Go to the documentation of flushbar 0.7.5 Download flushbar 0.7.5 archive
0.7.1 Jul 8, 2018 Go to the documentation of flushbar 0.7.1 Download flushbar 0.7.1 archive
0.7.0 Jul 8, 2018 Go to the documentation of flushbar 0.7.0 Download flushbar 0.7.0 archive
0.5.6 Jul 3, 2018 Go to the documentation of flushbar 0.5.6 Download flushbar 0.5.6 archive
0.5.5 Jun 20, 2018 Go to the documentation of flushbar 0.5.5 Download flushbar 0.5.5 archive
0.5.4 Jun 16, 2018 Go to the documentation of flushbar 0.5.4 Download flushbar 0.5.4 archive
0.5.2 Jun 5, 2018 Go to the documentation of flushbar 0.5.2 Download flushbar 0.5.2 archive

All 19 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
85
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
93
Learn more about scoring.

We analyzed this package on Aug 12, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.11.8
  • Flutter: 0.5.7

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Suggestions

Package is pre-v1 release.

While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction of the API.

Maintain an example.

Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use flushbar.dart.

Fix lib/flushbar.dart.

Analysis of lib/flushbar.dart reported 1 hint:

line 70 col 7: This class inherits from a class marked as @immutable, and therefore should be immutable (all instance fields must be final).

Format lib/flushbar_helper.dart.

Run flutter format to format lib/flushbar_helper.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.52.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.6 1.14.11
meta 1.1.5 1.1.6
sky_engine 0.0.99
typed_data 1.1.5 1.1.6
vector_math 2.0.6 2.0.8
Dev dependencies
flutter_test