Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dismiss before show other flashbar #7

Closed
boungly opened this issue Apr 24, 2020 · 4 comments
Closed

Dismiss before show other flashbar #7

boungly opened this issue Apr 24, 2020 · 4 comments

Comments

@boungly
Copy link

boungly commented Apr 24, 2020

I wonder if there's any way to dismiss the current flashbar (if it's showing)?

I don't want it to be stacked in each other.

@sososdk
Copy link
Owner

sososdk commented Apr 26, 2020

I think you may need to manage it yourself:

FlashController _previousController;

Future<T> toast<T>(BuildContext context, String message) async {
  if (_previousController?.isDisposed == false) _previousController.dismiss();
  _previousController = FlashController<T>(
    context,
    (context, controller) {
      return Flash.dialog(
        controller: controller,
        alignment: const Alignment(0, 0.5),
        margin: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
        borderRadius: const BorderRadius.all(Radius.circular(8.0)),
        enableDrag: false,
        backgroundColor: Colors.black87,
        child: DefaultTextStyle(
          style: const TextStyle(fontSize: 16.0, color: Colors.white),
          child: Padding(
            padding:
                const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
            child: Text(message),
          ),
        ),
      );
    },
    duration: const Duration(seconds: 3),
  );
  return _previousController.show();
}

@boungly
Copy link
Author

boungly commented Apr 28, 2020

@sososdk: Thank a lot for this code. It's working now.

@sososdk sososdk closed this as completed Apr 28, 2020
@yhelwa
Copy link

yhelwa commented May 4, 2022

Is there a way to make the flashbar fade in and out but across all screens, not just one screen? I used fade transition widget on the flashbar but its only fading on one screen (the screen that it is applied to)

@KamilSvoboda
Copy link

To check flashbar is dismissed you need to use slightly different way now:

if (_previousController?.controller.isDismissed == false) _previousController?.dismiss();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants