Material snackbar

A flutter plugin for displaying snackbars with the newest material design on desktop and mobile.

style: effective dart CodeFactor

Features

showcase

Usage

First, add the material_snackbar package to your pubspec dependencies.

To import material_snackbar:

import 'package:material_snackbar/material_snackbar.dart';

For displaying a material snackbar you need to obtain the MaterialSnackbarMessengerState of the current BuildContext by using MaterialSnackBarMessenger.of.

Material snackbar

Here is an example how to display a simple snackbar.

MaterialSnackBarMessenger.of(context).showSnackBar(
  snackbar: MaterialSnackbar(
    content: Text('Deleted 142 important documents'),
  ),
);

Use actionBuilder to add an action button that can dismiss the snackbar.

MaterialSnackBarMessenger.of(context).showSnackBar(
  snackbar: MaterialSnackbar(
    content: Text('Deleted 142 important documents.'),
    actionBuilder: (context, close) => TextButton(
      child: Text('DISMISS'),
      onPressed: close,
    ),
  ),
);

Snackbar queue

When you show multiple snackbars they are not displayed all at one time. They are added to the snackbar queue and are displayed individually after the previously shown snackbar.

snackbar queue

To empty the snackbar queue use:

MaterialSnackBarMessenger.of(context).emptyQueue();

Faster ⚡

When you just need a normal snackbar you can use snack() to save time.

 MaterialSnackBarMessenger.of(context).snack(
   'I am speed',
   actionText: 'REPLY',
   onAction: () => print('Speeeed'),
 );

For more examples see the example tab ➡

Libraries

material_snackbar
A package for displaying snackbars following the newest material guidelines for desktop, web, ios and android. [...]
material_snackbar_web
route
snackbar
snackbar_messenger