NxCustomSnackBar class
A utility class providing snackbar notifications with predefined styles.
This class offers three predefined styles:
- Error snackbar (red with close icon)
- Success snackbar (green with checkmark icon)
- Warning snackbar (orange with warning icon)
It also provides a custom snackbar option where you can specify:
- Custom background color
- Custom icon
- Duration (in seconds, defaults to 2)
- SnackBar behavior (floating or fixed)
Example usage:
// Show an error snackbar (fixed 2-second duration)
NxCustomSnackBar.showErrorSnackBar(
context: context,
message: 'An error occurred'
);
// Show a success snackbar (fixed 2-second duration)
NxCustomSnackBar.showSuccessSnackBar(
context: context,
message: 'Operation completed successfully'
);
// Show a custom snackbar with custom duration and behavior
NxCustomSnackBar.showCustomSnackBar(
context: context,
message: 'Custom message',
color: Colors.purple,
icon: Icons.star,
seconds: 5,
snackBarBehavior: SnackBarBehavior.fixed,
);
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
showCustomSnackBar(
{required BuildContext context, required String message, required Color color, IconData? icon, int seconds = 2, SnackBarBehavior snackBarBehavior = SnackBarBehavior.floating}) → ScaffoldFeatureController< SnackBar, SnackBarClosedReason> - Shows a snackbar with custom styling options.
-
showErrorSnackBar(
{required BuildContext context, required String message}) → ScaffoldFeatureController< SnackBar, SnackBarClosedReason> - Shows a red snackbar with an error icon.
-
showSuccessSnackBar(
{required BuildContext context, required String message}) → ScaffoldFeatureController< SnackBar, SnackBarClosedReason> - Shows a green snackbar with a checkmark icon.
-
showWarningSnackBar(
{required BuildContext context, required String message}) → ScaffoldFeatureController< SnackBar, SnackBarClosedReason> - Shows an orange snackbar with a warning icon.