showSnackBar function
void
showSnackBar(})
Show snack bar
showSnackBar('message');
Implementation
void showSnackBar(String content,
{String? title,
int durationSeconds = 3,
Color? backgroundColor,
bool closePrevious = false}) async {
Widget contentWidget = Text(content);
if (title != null) {
contentWidget = Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
title,
style: TextStyle(fontWeight: FontWeight.bold),
),
contentWidget,
],
);
}
if (closePrevious) {
_snackBarController?.close();
}
_snackBarController =
ScaffoldMessenger.of(await getxContext).showSnackBar(SnackBar(
content: contentWidget,
duration: Duration(seconds: durationSeconds),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
behavior: SnackBarBehavior.floating,
backgroundColor: backgroundColor,
))
..closed.then((value) {
if (value != SnackBarClosedReason.hide) {
_snackBarController = null;
}
});
}