snackBarContent function
Create the snackbar content
Implementation
SnackBar snackBarContent({
required BuildContext context,
required String title,
required String message,
Color backgroundColor = Colors.black,
Icon icon = const Icon(Icons.check_circle, color: Colors.amber, size: 28),
Color closeButtonColor = Colors.amber,
Color arrowBackgroundColor = Colors.white,
int? seconds,
}) {
Widget content = Stack(
clipBehavior: Clip.none,
children: [
Container(
margin: const EdgeInsets.only(top: 20),
decoration: BoxDecoration(
color: backgroundColor,
borderRadius: BorderRadius.circular(10),
),
child: Row(crossAxisAlignment: CrossAxisAlignment.center, children: [
const SizedBox(
width: 16,
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 24),
Text(
title,
style: const TextStyle(
color: Colors.white,
fontSize: 14,
fontWeight: FontWeight.bold),
),
const SizedBox(height: 8),
Text(
message,
style: const TextStyle(color: Colors.white, fontSize: 13),
),
const SizedBox(height: 16),
],
),
),
IconButton(
onPressed: () {
ScaffoldMessenger.of(context).hideCurrentSnackBar();
},
icon: Icon(
Icons.close,
color: closeButtonColor,
),
),
]),
),
Positioned(
left: 16,
top: -8,
child: CustomPaint(
painter: CustomStyleArrow(color: arrowBackgroundColor),
child: Container(
padding: const EdgeInsets.all(4),
child: icon,
),
),
),
],
);
return SnackBar(
backgroundColor: Colors.transparent,
behavior: SnackBarBehavior.floating,
elevation: 0,
duration: Duration(seconds: seconds ?? 10),
content: content,
);
}