showComicToast function
ComicRaised
showComicToast(
- BuildContext context,
- String message, {
- ComicTone? tone,
- IconData? icon,
- ComicStyle? style,
- Duration duration = const Duration(milliseconds: 2500),
Shows message as a ComicToast above the page's foot for duration, replacing the navigator's previous toast. It
takes no focus and no press: a toast that needs an answer is a showComicSnackBar.
showComicToast(context, 'Link copied', tone: ComicTone.success)
Implementation
ComicRaised showComicToast(
BuildContext context,
String message, {
ComicTone? tone,
IconData? icon,
ComicStyle? style,
Duration duration = const Duration(milliseconds: 2500),
}) {
final navigator = Navigator.of(context);
final overlay = navigator.overlay!;
_toasts[overlay]?.dismiss();
final carried = _Carried(context, navigator);
final shellAllowance = ShellInsets.of(context);
final handle = _Overlaid();
_toasts[overlay] = handle;
handle.closed.whenComplete(() {
if (identical(_toasts[overlay], handle)) _toasts[overlay] = null;
});
handle.entry = OverlayEntry(
builder: (context) => carried.wrap(
context,
_OverlayMotion(
handle: handle,
motion: carried.motion,
child: IgnorePointer(
child: SafeArea(
child: Padding(
padding: EdgeInsets.fromLTRB(
16,
16,
16,
24 +
math.max(
shellAllowance,
MediaQuery.viewInsetsOf(context).bottom,
),
),
child: Align(
alignment: Alignment.bottomCenter,
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 420),
child: ComicToast(
message,
tone: tone,
icon: icon,
style: style,
),
),
),
),
),
),
),
),
);
overlay.insert(handle.entry!);
handle.timer = Timer(duration, handle.dismiss);
return handle;
}