appSnackBar function
void
appSnackBar({
- required BuildContext context,
- required String message,
- Color? backgroundColor,
- Color? textColor,
- double? fontSize,
- SnackBarBehavior? behavior,
- Duration duration = const Duration(seconds: 3),
- EdgeInsetsGeometry? margin,
- double? elevation,
- SnackBarAction? action,
- IconData? icon,
- Color? iconColor,
- double? iconSize,
A helper function to easily show customizable SnackBars.
Supports icons, actions, and floating or fixed behavior.
Implementation
void appSnackBar({
required BuildContext context,
required String message,
Color? backgroundColor,
Color? textColor,
double? fontSize,
SnackBarBehavior? behavior,
Duration duration = const Duration(seconds: 3),
EdgeInsetsGeometry? margin,
double? elevation,
SnackBarAction? action,
IconData? icon,
Color? iconColor,
double? iconSize,
}) {
final SnackBarBehavior resolvedBehavior =
behavior ?? SnackBarBehavior.floating;
final Widget content = Row(
mainAxisSize: MainAxisSize.min,
children: [
if (icon != null) ...[
Icon(
icon,
color: iconColor ?? Colors.white,
size: iconSize ?? 20,
),
const SizedBox(width: 8),
],
Flexible(
child: Text(
message,
style: TextStyle(
color: textColor ?? Colors.white,
fontSize: fontSize ?? 14,
),
),
),
],
);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: content,
backgroundColor: backgroundColor ?? Colors.blueAccent,
behavior: resolvedBehavior,
duration: duration,
margin: margin,
elevation: elevation,
action: action,
),
);
}