snack method
void
snack(})
Displays a customizable SnackBar.
Supports optional action, styles, auto-clear, and margin control.
Implementation
void snack(
String message, {
bool success = true,
bool clearAll = true,
int ms = 2000,
String? actionText,
TextStyle? messageStyle,
TextStyle? actionStyle,
VoidCallback? onAction,
bool zeroMargin = true,
Color? textColor,
}) {
if (!mounted) return;
if (clearAll) {
ScaffoldMessenger.of(this).clearSnackBars();
}
ScaffoldMessenger.of(this).showSnackBar(
SnackBar(
elevation: 0,
behavior: SnackBarBehavior.floating,
duration: Duration(milliseconds: ms),
margin:
zeroMargin
? const EdgeInsets.symmetric(horizontal: 0, vertical: 0)
: null,
content: Row(
children: [
Expanded(
child: Text(
message,
style: TextStyle(
color: textColor ?? Colors.black,
).merge(messageStyle),
),
),
if (actionText != null)
Padding(
padding: const EdgeInsets.only(left: 8),
child: GestureDetector(
onTap: () {
ScaffoldMessenger.of(this).clearSnackBars();
onAction?.call();
},
child: Text(
actionText,
style: TextStyle(
color: Colors.blue,
fontWeight: FontWeight.w600,
).merge(actionStyle),
),
),
),
],
),
),
);
}