Skip to content

Source on GitHublib/src/ui_kit/fast_toast/

Overview

Global toasts live on the app-root overlay. Call showToast / showCustomToast without a BuildContext; they are not tied to the navigator stack. Only one toast is visible at a time; extras wait in a FIFO queue.

TopicNotes
Show APIshowToast(message) / showCustomToast(widget)
HostWrap MaterialApp.builder with FastToastOverlay
QueueSingle slot, FIFO; pending cap 5, drop-oldest
ThemeFastToastTheme (ThemeExtension) for the text panel only
Not providedsuccess / error / info types, priority interrupt, progress toasts

TIP

Calls made before FastToastOverlay is mounted enqueue without throwing. See the example app’s ToastExample page for a full demo.


Setup

dart
import 'package:flutter/material.dart';
import 'package:fast_package/fast_package.dart';

MaterialApp(
  builder: (context, child) {
    return FastToastOverlay(
      child: child ?? const SizedBox.shrink(),
    );
  },
  // ...
);

Examples

dart
import 'package:fast_package/fast_package.dart';

showToast('Saved');

showToast(
  'Network error',
  config: FastToastConfig(
    duration: Duration(seconds: 3),
    position: FastToastPosition.bottom,
    dismissible: true,
  ),
);

showCustomToast(
  Row(
    mainAxisSize: MainAxisSize.min,
    children: [
      Icon(Icons.check_circle, color: Colors.green),
      SizedBox(width: 8),
      Text('Custom content'),
    ],
  ),
);

FastToast.dismiss();
FastToast.dismissAll();

showCustomToast inserts your widget as toast content. The host still owns queue, position, duration, and motion, and does not wrap default panel chrome. The widget is built under the overlay tree (Builder / Theme.of work); do not capture a disposed page BuildContext.


Theme setup

FastToastTheme styles the default showToast text panel only:

dart
MaterialApp(
  theme: ThemeData(
    brightness: Brightness.light,
    extensions: const [FastToastTheme.light],
  ),
  darkTheme: ThemeData(
    brightness: Brightness.dark,
    extensions: const [FastToastTheme.dark],
  ),
  builder: (context, child) {
    return FastToastOverlay(child: child ?? const SizedBox.shrink());
  },
);

Resolution order:

  1. A FastToastTheme registered on ThemeData
  2. Fallback to FastToastTheme.light / dark from ThemeData.brightness

API

showToast / showCustomToast

dart
void showToast(String message, {FastToastConfig? config});

void showCustomToast(Widget toast, {FastToastConfig? config});

FastToast

MemberNotes
isShowingWhether a toast is on screen
pendingCountPending items, excluding the visible toast
dismiss()Exit the current toast, then show the next; no-op when idle
dismissAll()Clear the queue and remove the current toast immediately

FastToastConfig

ParameterDefaultNotes
duration2000msTime on screen before exit animation
positionFastToastPosition.centertop / center / bottom
dismissiblefalseTap content to dismiss

Non-goals

  • No FastToastType and no success / error / info helpers
  • No Loading coordination and no high-priority interrupt
  • No animation enum and no progress toast

Released under the MIT License