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

[Question] Possibility to create a class #149

Open
shifenis opened this issue Jul 16, 2020 · 2 comments
Open

[Question] Possibility to create a class #149

shifenis opened this issue Jul 16, 2020 · 2 comments

Comments

@shifenis
Copy link

Hello everyone,
Is possible to create a class to be able to use the Flushbar with a default value. I mean, every time that you need to present an error you can invoke that class that has the default value, as well as a class for info.

How can I approach it?

@fernando-s97
Copy link

fernando-s97 commented Aug 13, 2020

I guess the lib by default doesn't support it. Some alternatives would be:

  1. Extends Flushbar
class FlushbarError extends Flushbar {}
  1. Make another class just like FlushbarHelper, but with your data
class MyFlushbarHelper {
  static void static void showError(...) {
    return Flushbar(...);
  }
}

But the ideal would be the possibility create the snackbars with default values, and be allowed to change them on demand.

@benPesso
Copy link

benPesso commented Oct 1, 2020

I have a LittleHelper class that I use to display errors, alerts, dialogs, and other such repetitive things. I've implemented it with a factory, so that it gets the BuildContext automatically, like so:

class LittleHelper {
  final BuildContext context;

  LittleHelper(this.context);

  factory LittleHelper.of(BuildContext context) {
    return LittleHelper(context);
  }

...
}

Which then allows me to just do this:

LittleHelper.of(context).showAlert(...); // Displays a Flushbar.

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