showToast method
void
showToast(
- BuildContext context,
- ShowToastAction toastAction,
- Widget? customToastBody, {
- DataContext? dataContext,
Implementation
void showToast(BuildContext context, ShowToastAction toastAction,
Widget? customToastBody,
{DataContext? dataContext}) {
_toast.init(context);
_toast.removeQueuedCustomToasts();
ToastGravity toastGravity;
if (toastAction.alignment == Alignment.topCenter) {
toastGravity = ToastGravity.TOP;
} else if (toastAction.alignment == Alignment.topLeft) {
toastGravity = ToastGravity.TOP_LEFT;
} else if (toastAction.alignment == Alignment.center) {
toastGravity = ToastGravity.CENTER;
} else if (toastAction.alignment == Alignment.centerLeft) {
toastGravity = ToastGravity.CENTER_LEFT;
} else if (toastAction.alignment == Alignment.centerRight) {
toastGravity = ToastGravity.CENTER_RIGHT;
} else if (toastAction.alignment == Alignment.bottomCenter) {
toastGravity = ToastGravity.BOTTOM;
} else if (toastAction.alignment == Alignment.bottomLeft) {
toastGravity = ToastGravity.BOTTOM_LEFT;
} else if (toastAction.alignment == Alignment.bottomRight) {
toastGravity = ToastGravity.BOTTOM_RIGHT;
} else {
// default
toastGravity = ToastGravity.TOP_RIGHT;
}
_toast.showToast(
positionedToastBuilder: (context, child, gravity) {
return _getPostionWidgetBasedOnGravity(context, child, toastGravity);
},
toastDuration: toastAction.duration != null
? Duration(seconds: toastAction.duration!)
: const Duration(seconds: 10),
child: Align(
alignment: toastAction.alignment ?? Alignment.center,
child:
_getToastWidget(context, dataContext, toastAction, customToastBody),
),
);
}