如何在Flutter中更改BottomSheet的背景颜色? [英] How to change the background color of BottomSheet in Flutter?

查看:139
本文介绍了如何在Flutter中更改BottomSheet的背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When I use the showModalBottomSheet method to pop up a bottomSheet, how to make the background color transparent. because I needed the rounded corners, I knew that changing the canvasColor in the materialApp would do the trick, but other widgets would also change colors.

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

I tried to embed it in the theme, but it didn't work

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,
            ),
        ),
    );
});

推荐答案

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

Just add this in your top level ThemeData. This will solve your problem

bottomSheetTheme:BottomSheetThemeData(backgroundColor:Colors.black54)

这篇关于如何在Flutter中更改BottomSheet的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆