flushbar icon indicating copy to clipboard operation
flushbar copied to clipboard

[Question] Possibility to create a class

Open shifenis opened this issue 3 years ago • 2 comments

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?

shifenis avatar Jul 16 '20 10:07 shifenis

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.

fernando-s97 avatar Aug 13 '20 19:08 fernando-s97

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.

benPesso avatar Oct 01 '20 11:10 benPesso