A flutter plugin for displaying snackbars with the newest material design on desktop and mobile.
- Material design (with material motion).
- Designed for desktop and mobile.
- Snackbar queue for stacking snackbars.
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].
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,
),
),
);
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.
To empty the snackbar queue use:
MaterialSnackBarMessenger.of(context).emptyQueue();
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 ➡