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 89 forks source link

close before show new flusbar #35

Closed mqhamdam closed 3 years ago

mqhamdam commented 3 years ago

Good day! I didnt find any method to programmatically close the current flushbar. There is a solution for snackbars (ScaffoldMessenger.of(context)..hideCurrentSnackbar()..showSnackbar(); .... how to implement this with flushbar?

emvaized commented 3 years ago

Flushbar _flush = new Flushbar( ... );

/// Show flushbar _flush.show(context);

/// Hide flushbar _flush.dismiss();

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