之前用Scaffold
的showModalBottomSheet
方法實(shí)現(xiàn)了一個半屏幕彈窗.后來需求調(diào)整,要改成背景完全透明
的.
Future<T> showModalBottomSheet<T>({
@required BuildContext context,
@required WidgetBuilder builder,
Color backgroundColor,
double elevation,
ShapeBorder shape,
Clip clipBehavior,
bool isScrollControlled = false,
bool useRootNavigator = false,
bool isDismissible = true,
})
showModalBottomSheet
的backgroundColor
參數(shù)確實(shí)是可以修改整體的背景顏色, 但即使設(shè)置為Colors.transparent
也是自帶半透明的黑,而且不能完全透明.
試了幾個方案還是沒有解決,例如包裹opacity/用route設(shè)置barrier顏色/XXX.
開始搜索吧,百度一下沒什么靠譜的答案,在stackoverflow上有幾個類似的提問,下面是兩個最接近的.
- https://stackoverflow.com/questions/52663445/flutter-show-bottomsheet-transparency
- https://stackoverflow.com/questions/51204179/how-to-change-the-background-color-of-bottomsheet-in-flutter
但是仍然沒有解決.
感覺自己思維被局限在這一個showModalBottomSheet
方法里了.
喝口水冷靜冷靜,換個思路,換個dialog實(shí)現(xiàn)起來很簡潔嘛
showGeneralDialog(
context: context,
barrierDismissible:true,
barrierLabel: '',
barrierColor: Colors.transparent,
transitionDuration: Duration(milliseconds: 200),
pageBuilder: (BuildContext context, Animation<double> animation,Animation<double> secondaryAnimation) {
return Scaffold(backgroundColor: Colors.transparent, body:yourWidget);
})
LGTM : )