showSnackbar method
void
showSnackbar({
- String? title,
- String? subTitle,
- TextStyle? titleStyle,
- TextStyle? subTitleStyle,
- Widget? titleWidget,
- Widget? subTitleWidget,
- Widget? leading,
- Widget? trailing,
- Color? backgroundColor,
- Duration? duration,
- EdgeInsetsGeometry? contentPadding,
- EdgeInsetsGeometry? outerPadding,
- BorderRadius? borderRadius,
- Curve? animationCurve,
- AnimateFrom? animateFrom,
Implementation
void showSnackbar({
String? title,
String? subTitle,
TextStyle? titleStyle,
TextStyle? subTitleStyle,
Widget? titleWidget,
Widget? subTitleWidget,
Widget? leading,
Widget? trailing,
Color? backgroundColor,
Duration? duration,
EdgeInsetsGeometry? contentPadding,
EdgeInsetsGeometry? outerPadding,
BorderRadius? borderRadius,
Curve? animationCurve,
AnimateFrom? animateFrom,
}) {
// Get the OverlayState
final overlayState = Overlay.of(this);
// Create an OverlayEntry with your custom widget
final snackBar = OverlayEntry(
builder: (_) => SnackbarWidget(
title: title ??= "",
subTitle: subTitle ??= "",
titleStyle: titleStyle ??= const TextStyle(color: Colors.white),
subTitleStyle: subTitleStyle ??= const TextStyle(color: Colors.white),
titleWidget: titleWidget,
subTitleWidget: subTitleWidget,
leading: leading,
trailing: trailing,
backgroundColor: backgroundColor ??= Colors.blue,
duration: duration ??= const Duration(milliseconds: 1000),
contentPadding: contentPadding ??= const EdgeInsets.all(20),
borderRadius: borderRadius ??= BorderRadius.circular(10),
animationCurve: animationCurve ??= Curves.ease,
outerPadding: outerPadding ??=
const EdgeInsets.symmetric(horizontal: 10),
animateFrom: animateFrom ?? AnimateFrom.fromBottom,
),
);
// then insert it to the overlay
// this will show the toast widget on the screen
overlayState!.insert(snackBar);
// 3 secs later remove the toast from the stack
// and this one will remove the toast from the screen
Future.delayed(duration! * 2, snackBar.remove);
}