toast function

void toast(
  1. String message, {
  2. Duration duration = Toast.LENGTH_SHORT,
  3. BuildContext? context,
})

Popup a message in front of screen.

duration : the duration to show a toast, for most situation, you can use Toast.LENGTH_SHORT and Toast.LENGTH_LONG

Implementation

void toast(
  String message, {
  Duration duration = Toast.LENGTH_SHORT,
  BuildContext? context,
}) {
  if (duration <= Duration.zero) {
    //fast fail
    return;
  }

  showOverlay(
    (context, t) {
      return IgnorePointer(
        child: Opacity(
          opacity: t,
          child: _Toast(content: Text(message)),
        ),
      );
    },
    curve: Curves.ease,
    key: const ValueKey('overlay_toast'),
    duration: duration,
    context: context,
  );
}