showToast method
void
showToast({
- required Widget child,
- PositionedToastBuilder? positionedToastBuilder,
- Duration toastDuration = const Duration(seconds: 2),
- ToastGravity? gravity,
- Duration fadeDuration = const Duration(milliseconds: 350),
- bool ignorePointer = false,
- bool isDismissable = false,
showToast accepts all the required paramenters and prepares the child calls _showOverlay to display toast
Paramenter child
is requried
toastDuration default is 2 seconds
fadeDuration default is 350 milliseconds
Implementation
void showToast({
required Widget child,
PositionedToastBuilder? positionedToastBuilder,
Duration toastDuration = const Duration(seconds: 2),
ToastGravity? gravity,
Duration fadeDuration = const Duration(milliseconds: 350),
bool ignorePointer = false,
bool isDismissable = false,
}) {
if (context == null)
throw ("Error: Context is null, Please call init(context) before showing toast.");
Widget newChild = _ToastStateFul(
child,
toastDuration,
fadeDuration,
ignorePointer,
!isDismissable
? null
: () {
removeCustomToast();
});
/// Check for keyboard open
/// If open will ignore the gravity bottom and change it to center
if (gravity == ToastGravity.BOTTOM) {
if (MediaQuery.of(context!).viewInsets.bottom != 0) {
gravity = ToastGravity.CENTER;
}
}
OverlayEntry newEntry = OverlayEntry(builder: (context) {
if (positionedToastBuilder != null)
return positionedToastBuilder(context, newChild);
return _getPostionWidgetBasedOnGravity(newChild, gravity);
});
_overlayQueue.add(_ToastEntry(
entry: newEntry, duration: toastDuration, fadeDuration: fadeDuration));
if (_timer == null) _showOverlay();
}