小编典典

如何在Flutter中更改BottomSheet的背景颜色?

flutter

屏幕截图

当我使用showModalBottomSheet方法弹出bottomSheet时,如何使背景色透明。因为我需要圆角,所以我知道在materialApp中更改canvasColor可以解决问题,但是其他小部件也可以更改颜色。

我试图将其嵌入主题中,但是没有用

showModalBottomSheet < Null > (context: context, builder: (BuildContext context) {
    return Theme(
        data: Theme.of(context).copyWith(canvasColor: Colors.orange),
        child: Material(
            borderRadius: BorderRadius.only(topLeft: Radius.circular(16.0), topRight: Radius.circular(16.0)),
            child: Container(
                color: Colors.purple,
            ),
        ),
    );
});

阅读 925

收藏
2020-08-13

共1个答案

小编典典

只需将其添加到顶级ThemeData中即可。这样可以解决你的问题

bottomSheetTheme: BottomSheetThemeData(backgroundColor: Colors.black54)

2020-08-13