How to add a margin or padding to a Snackbar?
Flutter team have updated the snackbar to match the material design in this PR. You can simply get the new behavior by setting
behavior: SnackBarBehavior.floating
Here is a sample code
final snackBar = SnackBar(
elevation: 6.0,
backgroundColor: Configs.current.COLORS_PRIMARY,
behavior: SnackBarBehavior.floating,
content: Text(
"Snack bar test",
style: TextStyle(color: Colors.white),
),
);
and the result will look like this
Not sure about margins. Round corner SnackBar can be created like:
Scaffold
.of(context)
.showSnackBar(
SnackBar(
content: Text(message),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20)))));
Use required border radius in above.
Update:
You can use floating SnackBar
to add default margins. Pass below to SnackBar
constructor:
Scaffold
.of(context)
.showSnackBar(
SnackBar(
content: Text(message),
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20)))));