flushbar icon indicating copy to clipboard operation
flushbar copied to clipboard

[Question] Is it possible to hide current flushbar?

Open amadeu01 opened this issue 4 years ago • 5 comments

Before going to show some new flushbar, I would like to dismiss any, if they exists.

Snackbar has a method like hideCurrentSnackBar

Scaffold.of(context)
              ..hideCurrentSnackBar()
              ..showSnackBar(
                SnackBar(
                  content: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      CircularProgressIndicator(),
                    ],
                  ),
                ),
              );
          }

So, is it possible to do something similar with flushbar?

amadeu01 avatar May 04 '20 03:05 amadeu01

Use dismiss()

 /// Dismisses the flushbar causing is to return a future containing [result].
 /// When this future finishes, it is guaranteed that Flushbar was dismissed.
Future<T> dismiss([T result]) async {
    ...
  }

AndreHaueisen avatar May 15 '20 23:05 AndreHaueisen

Use dismiss()

 /// Dismisses the flushbar causing is to return a future containing [result].
 /// When this future finishes, it is guaranteed that Flushbar was dismissed.
Future<T> dismiss([T result]) async {
    ...
  }

is dismiss() a class function like hideCurrentSnackBar ?

Can I do something like

Flushbar.of(context).dismiss()

?

amadeu01 avatar May 16 '20 00:05 amadeu01

@amadeu01

Maybe he was busy and forgot to answer you. I was able to get the dismiss() function to work.

You basically define a function like this


removeFlushbar(Flushbar flushbar) {
    flushbar.dismiss();
  }

somewhere at the top of your code, then call the removeFlushbar() function in the onTap() method of the Flushbar widget.

It should look something like this


  Flushbar _flushBar = Flushbar(
            margin: EdgeInsets.all(5),
            borderRadius: 5,
            isDismissible: false,
             onTap: (flushbar) {
              removeFlushbar(flushbar);
        },
            flushbarStyle: FlushbarStyle.FLOATING,
            flushbarPosition: FlushbarPosition.BOTTOM,
            message: 'Your message',
            duration: Duration(seconds: 4),
          );

       _flushbar..show(context); //Don't worry just a fancy way of calling the showing the Flushbar.

Hope that helps :)

adeolaex avatar Jun 28 '20 17:06 adeolaex

I was looking for the same function. There is no Flushbar.of(context).dismiss(), although this would be handy.

ThinkDigitalSoftware avatar Jul 28 '20 23:07 ThinkDigitalSoftware

@amadeu01

Maybe he was busy and forgot to answer you. I was able to get the dismiss() function to work.

You basically define a function like this

removeFlushbar(Flushbar flushbar) {
    flushbar.dismiss();
  }

somewhere at the top of your code, then call the removeFlushbar() function in the onTap() method of the Flushbar widget.

It should look something like this

  Flushbar _flushBar = Flushbar(
            margin: EdgeInsets.all(5),
            borderRadius: 5,
            isDismissible: false,
             onTap: (flushbar) {
              removeFlushbar(flushbar);
        },
            flushbarStyle: FlushbarStyle.FLOATING,
            flushbarPosition: FlushbarPosition.BOTTOM,
            message: 'Your message',
            duration: Duration(seconds: 4),
          );

       _flushbar..show(context); //Don't worry just a fancy way of calling the showing the Flushbar.

Hope that helps :)

You could also just do this:

onTap: (flushbar) {
  flushbar.dismiss();
},

Especially if your removeFlushbar method isn't doing anything fancy inside it.

benPesso avatar Oct 01 '20 11:10 benPesso