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

How do i add a dissmiss button to the Flushbar #166

Open
nnyamekye opened this issue Dec 4, 2020 · 2 comments
Open

How do i add a dissmiss button to the Flushbar #166

nnyamekye opened this issue Dec 4, 2020 · 2 comments

Comments

@nnyamekye
Copy link

I'm trying to show a Flushbar when a TimeoutException is thrown. My implementation can be seen below.

My IDE complains that "Local variable 'flush' can't be referenced before it is declared." which make sense but i see a lot of examples where people do this. Please help

on TimeoutException {
      var flush = Flushbar(
        title: 'Server Unavailable',
        backgroundColor: primaryColor,
        message: '😓 Sorry the server is currently unavailable',
        flushbarPosition: FlushbarPosition.TOP,
        margin: EdgeInsets.all(8),
        borderRadius: 8,
        icon: Icon(
          Icons.error_outline,
          size: 28.0,
          color: Colors.white,
        ),
        mainButton: FlatButton(
          onPressed: () {
            flush.dismiss(true); // result = true
          },
          child: Text(
            "DISMISS",
            style: TextStyle(
                color: Colors.white,
                fontWeight: FontWeight.bold,
                fontSize: 10
            ),
          ),
        ),
    ).show(context);
    }
@Matej-Hlatky
Copy link

Hi @nnyamekye ,

This is more like a Dart language issue than Flushbar question.
I had resolved it by defining local variable first which cannot be assigned right away. 🤷‍♂️

Flushbar flush;
flush = Flushbar<T>(
  mainButton: IconButton(
    onPressed: () {
      flush.dismiss(true);
    },
    color: Colors.red,
    icon: Icon(Icons.close),
  ),
);

Hope this helps.

@rdani91
Copy link

rdani91 commented Dec 23, 2020

Use Navigator.pop(context)

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

3 participants