I'm afraid this isn't possible. However, that's my code for the SnackBar
:
displaySnackBar(String message, BuildContext context) {
final snackBar = SnackBar(
duration: Duration(milliseconds: 2000),
behavior: SnackBarBehavior.fixed,
content: Text(message, style: TextStyle(color: Colors.black, fontWeight: FontWeight.normal)),
backgroundColor: Colors.white
);
Scaffold.of(context).showSnackBar(snackBar);
}
It works very fine. The only problem: I want to add a simple shadow behind it. The behavior
must be fixed
.
Solution 1: Darshan
With default SnackBar
widget and behavior.fixed
, you may not be able to put a shadow effect. But you can achieve that using this plugin. It has an example of shadow at top of the bar:
Hope this helps.
Solution 2: Bassam
The answer: This is currently (without using a plugin) not possible.
Solution 3: Ataberk
If it is very important for someone you can use a plugin or similar effect can be achieved with BottomSheet. I know it is not actual SnackBar but you can implement needed SnackBar features by hand.
BottomSheet idea is below. You can add needed features by hand.
Scaffold.of(context).showBottomSheet(
(context) => Stack(
alignment: Alignment.bottomCenter,
children: [
GestureDetector(
onTap: () {
Navigator.pop(context);
},
child: Container(
height: double.infinity,
width: double.infinity,
color: Colors.black.withOpacity(.3)),
),
Container(
height: MediaQuery.of(context).size.height * .6,
width: double.infinity,
margin: EdgeInsets.symmetric(horizontal: 8),
padding: EdgeInsets.all(16),
decoration: BoxDecoration(
color: backgroundAccentColor,
boxShadow: boxShadow,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(12),
topRight: Radius.circular(12))),
child: Text("Add new card"),
),
],
),
backgroundColor: Colors.transparent);