cmdrootaccess / another-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.
https://pub.dev/packages/another_flushbar
MIT License
145 stars 90 forks source link

How to check if flushbar is already open? #32

Closed tuanbs closed 3 years ago

tuanbs commented 3 years ago

I'd like to check if flushbar is already open before showing a new one. Otherwise, the new one overlaps the old one. Something like this:

if (!Flushbar.isFlushbarOpen) {
    // Show Flushbar...
}

Thanks in advance.

cmdrootaccess commented 3 years ago

you can use isShowing() from here https://github.com/cmdrootaccess/another-flushbar/blob/d0b51947ffd184a0deb68a86bf38f7de78b57707/lib/flushbar.dart#L285

tuanbs commented 3 years ago

@cmdrootaccess Got it. Thank you very much.

MrPresidentWhite commented 3 years ago

@cmdrootaccess can you provide me an example please, because i can't get it to run

furkancetintass commented 2 years ago

define bool variable in the class

bool isSnackbarActive = false;

void showWarningFlushBar(
    BuildContext context,
    String content, {
    String? title,
  }) {
    if (!isSnackbarActive) {
      isSnackbarActive = true;
      Flushbar(
          flushbarPosition: FlushbarPosition.TOP,
          borderRadius: BorderRadius.circular(16),
          margin: const EdgeInsets.all(8),
          title: title ?? LocaleKeys.common_warning.locale,
          messageText: Text(
            content,
            maxLines: 3,
            style: const TextStyle(color: Colors.white),
          ),
          duration: const Duration(seconds: 2),
          backgroundGradient: LinearGradient(begin: Alignment.topLeft, end: Alignment.bottomRight, colors: [
            Colors.orange.shade600,
            Colors.amber.shade700,
          ])).show(context).then((value) {
        isSnackbarActive = false;
      });
    }
  }