show method

void show({
  1. String message = "Toast is here",
  2. Duration duration = const Duration(seconds: 2),
  3. PitelToastPosition position = PitelToastPosition.bottom,
})

Implementation

void show({
  String message = "Toast is here",
  Duration duration = const Duration(seconds: 2),
  PitelToastPosition position = PitelToastPosition.bottom,
}) {
  final context = NavigationService.navigatorKey.currentContext;
  if (context == null) return;

  _toastEntry?.remove();

  _toastEntry = OverlayEntry(
    builder: (context) => _ToastWidget(
      message: message,
      duration: duration,
      position: position,
      onDismiss: () {
        _toastEntry?.remove();
        _toastEntry = null;
      },
    ),
  );

  NavigationService.navigatorKey.currentState?.overlay?.insert(_toastEntry!);
}