How can I add a shadow to the border of modal bottom sheet? Here’s my code:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
useMaterial3: true,
bottomSheetTheme: const BottomSheetThemeData(
modalElevation: 1000.0,
elevation: 1000.0,
clipBehavior: Clip.hardEdge,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20),
topRight: Radius.circular(20))))),
home: TabBarDemo(),
);
}
}
class TabBarDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: ElevatedButton(
child: Text('Press'),
onPressed: () {
showModalBottomSheet(
barrierColor: Colors.transparent,
context: context,
builder: (context) {
return Container();
});
})),
);
}
}
Even though I’ve set the elevation
property, I don’t see any shadow on the border of the bottom sheet. Instead I see a plain border:
2
Answers
The shadow is controlled by setting either the
BottomSheetThemeData.modalElevation
property or theelevation
parameter in the call toshowModalBottomSheet
.BottomSheetThemeData.elevation
appears to do nothing in my example. The shadow is not prominent and not controllable as withBoxShadow
, but at least clipping works properly. In my question, the shadow was visible, but it was spread out because of the largemodalElevation
value.You can use boxShadow for this. Try this code.