NIB / DOCUMENTATION
Toast — NibComponents
Announce a local outcome, handle duplicate ids, and provide an undo action.
Open interactive viewChoose where notifications live
showNibToast returns an id and accepts an optional context. With a context it resolves that context’s root Overlay. Without one, install NibToaster once above the application content. NibToaster supplies an Overlay itself, so it can sit above MaterialApp’s Navigator in builder.
The preview mounts a bounded NibToaster and passes context explicitly. Context chooses the root overlay, which may be the page overlay above the preview. The manager is process-global, not a per-widget queue or tenant boundary. Prefer one app host and a consistent policy for ids. Concurrent hosts do not create isolated managers.
MaterialApp(
builder: (context, child) => NibToaster(child: child!),
home: const HomePage(),
);Describe the outcome and place its stack
NibToastVariant has normal, success, error, warning, and info. NibToastVariantX.defaultIcon() and accent(theme) resolve the icon and accent; normal has no default icon. Override icon, content, padding, borderRadius, or backgroundColor when appropriate. Custom content owns its semantics.
NibToastPosition has six top/bottom and left/center/right positions. NibToastPositionX exposes alignment, isTop, and enterOffset. Left/right stacks enter horizontally; centered stacks enter vertically. Position is a stack anchor, not a per-item coordinate. The manager caps visible items per position.
Make repeated operations deliberate
A repeated id uses onDuplicateTrigger: shake, ignore, or replace. Shake calls attention to the existing item; ignore keeps it unchanged; replace updates content and restarts its timer. The example uses one unique id per owner and compares replacement with ignoring a second save.
Choose ids for the represented operation, not an unbounded new notification for each retry. The returned id can be passed to dismissNibToast. Different ids produce separate items. A visual duplicate policy does not make a backend operation idempotent.
Separate undo from presentation
duration defaults to four seconds. Duration.zero makes a persistent notification; the demo starts there for inspection. A nonzero value schedules dismissal. actionLabel and onAction add an application action. Closing a toast does not undo anything by itself; the demo explicitly records the reversal and dismisses its id.
showCloseButton controls the close affordance. dismissible controls swipe dismissal. onDismiss observes removal. Keep lasting error or operation state in the page instead of relying on a short-lived toast as the only place to read or resolve it.
Dismiss only what you own
dismissNibToast(id) closes one item. dismissAllNibToasts() closes the global manager’s items, including notifications from other parts of the app. The explicit global button demonstrates that API; use it only when clearing all app notifications is intended.
The example dismisses its own id during disposal and guards callbacks with mounted. NibToaster registers and unregisters its overlay, but does not create a separate manager. Account for route removal, timers, and context changes in the application. Keep event history bounded.
Verify the real notification viewport
The toast captures inherited theme from its caller when available. animated defaults to false; transition controls optional entrance and removal. Success and warning accents are fixed semantic colors in this package; changing the primary accent does not recolor those outcomes.
Widget tests cover duplicate policy, action callbacks, both dismiss helpers, and cleanup. Physical swipe feel, screen-reader announcements, and narrow stacking remain platform checks. A toast that says Saved reflects the application’s claim; this demo verifies no production storage service.