This is a helper class to generate SnackBar notifications everywhere in the app's codebase without being limited to Scafold inherited widgets.
- Copy or download this file into your project.
- Import this file wherever you need to use it.
- Initiate the class on the main Scafold or wherever you use a Scafold widget.
- Use the class wherever you need to display a SnackBar notification.
NotificationManager.context = context; // the Scafold context
NotificationManager.successBackgroundColor = Colors.black; // default value is black. Can optionally be changed
NotificationManager.errorBackgroundColor = Colors.red; // default value is red. Can optionally be changed
NotificationManager.generateNewSuccessNotification(
"This is a success notification.",
fast: false,
);
NotificationManager.generateNewErrorNotification(
"This is an error notification.",
fast: false,
);
Both methods accept 2 parameters:
message
, the first parameter which is required and accepts a Stringfast
, a boolean flag which decides whether the SnackBar should be closed fast(after 500ms) or slow(after 1000ms),false
is by default.