Toast & Snackbar

Loading preview

Starting the Flutter app

A showcase of Flutter's built-in toast messages and snackbars

Get the source

Add it to your project

Copies the Dart source into your app, so you own it. Flutter SDK only, no extra packages.

First time? Run dart pub global activate fluttertemplates_dev, or read the CLI guide.

How it works

_showSnackBar is the single helper, taking behavior, duration, backgroundColor, textColor and an optional action. textColor is applied through a TextStyle on the content, so the ‘Colored Snackbar’ call really sets white text. ‘Show Multiple’ schedules three messages with Future.delayed, and ScaffoldMessenger queues them one after another instead of stacking. The Undo and Cancel actions only display a second snackbar.

Adapting it

  • Move _showSnackBar into a BuildContext extension so any screen can call it.
  • Put your restore logic in the SnackBarAction onPressed, and call hideCurrentSnackBar first if new messages should replace old ones.