flushbar
flushbar copied to clipboard
[Question] Is it possible to hide current flushbar?
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?
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 {
...
}
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
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 :)
I was looking for the same function. There is no Flushbar.of(context).dismiss()
, although this would be handy.
@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 theonTap()
method of theFlushbar
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.