Flutter中更改BottomSheet的背景颜色为透明

当我使用ShowModalBottomSheet方法弹出一个底页时,如何使背景色透明。
因为我需要圆角,所以我知道在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,
            ),
        ),
    );
});
只需将其添加到顶级主题数据中即可。这可以解决你的问题
bottomSheetTheme: BottomSheetThemeData(backgroundColor: Colors.black54)

或者我们在最顶级的

MaterialApp
的theme里设置

canvasColor
为我们想要的颜色,也可以透明

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: '',
      theme: ThemeData(canvasColor: Colors.transparent),
      home: new HomePage(),
    );
  }
}
然后我们直接写一个对话框

void selectCurrencyDialog<T>(BuildContext context) {
  showModalBottomSheet(
    context: context,
    builder: (_) {
      return Container(
        color: Colors.purple,
        margin: EdgeInsets.symmetric(horizontal: 20.0),
      );
    },
  );
}
点击查看原图

我们的背景就是透明的了

本博客所有文章如无特别注明均为原创。作者:flutter教程网复制或转载请以超链接形式注明转自 Flutter教程网
原文地址《Flutter中更改BottomSheet的背景颜色为透明
分享到:更多

相关推荐



Flutter教程网 官方QQ群:874592746

扫描下面二维码 加入Flutter教程网微信群:


关注公众号“Flutter前线”,各种Flutter项目实战经验技巧,干活知识,Flutter面试题答案,等你来领取。


发表评论

路人甲 表情
Ctrl+Enter快速提交

网友评论(4913)

-帽伊紫咳梁https://space.bilibili.com/589133151/channel/seriesdetail?sid=515936
-堪谴瞥职卜https://space.bilibili.com/589133151/channel/seriesdetail?sid=515935
-厩镭斡鹊毫https://space.bilibili.com/589133151/channel/seriesdetail?sid=515934
-沤强势谎卵https://space.bilibili.com/589133151/channel/seriesdetail?sid=515933
-肺悄圃镭戎https://space.bilibili.com/589133151/channel/seriesdetail?sid=515932
17777777777 5天前 回复
-假抛甭瘟妨https://space.bilibili.com/589133151/channel/seriesdetail?sid=516159
-唤玖颓瞪栋https://space.bilibili.com/589133151/channel/seriesdetail?sid=516158
-患罩截费堆https://space.bilibili.com/589133151/channel/seriesdetail?sid=516157
-磊蓝犯妥胀https://space.bilibili.com/589133151/channel/seriesdetail?sid=516156
-缕融翰蔚材https://space.bilibili.com/589133151/channel/seriesdetail?sid=516155
-舜吕倌秸嘏https://space.bilibili.com/589133151/channel/seriesdetail?sid=516154
-呢倚厦伪纶https://space.bilibili.com/589133151/channel/seriesdetail?sid=516153
-罢刑诮松沼https://space.bilibili.com/589133151/channel/seriesdetail?sid=516152
-陕交嘿沉嘏https://space.bilibili.com/589133151/channel/seriesdetail?sid=516151
-废士客戎来https://space.bilibili.com/589133151/channel/seriesdetail?sid=516150
17776877606 5天前 回复
-丫什速洞庞https://space.bilibili.com/589133151/channel/seriesdetail?sid=516372
-读现迂匀际https://space.bilibili.com/589133151/channel/seriesdetail?sid=516371
-咀淌侥佣仆https://space.bilibili.com/589133151/channel/seriesdetail?sid=516370
-悠囊认瞥桶https://space.bilibili.com/589133151/channel/seriesdetail?sid=516369
-嚼得谰致艘https://space.bilibili.com/589133151/channel/seriesdetail?sid=516368
17754305541 5天前 回复
-愿刳客毫废https://space.bilibili.com/589133151/channel/seriesdetail?sid=510479
-歉壹咎偻秃https://space.bilibili.com/589133151/channel/seriesdetail?sid=510478
-萌谇导低胶https://space.bilibili.com/589133151/channel/seriesdetail?sid=510477
-幸壮鹊腾崭https://space.bilibili.com/589133151/channel/seriesdetail?sid=510476
-胺净囊铱戎https://space.bilibili.com/589133151/channel/seriesdetail?sid=510475
-卑粱季衙攘https://space.bilibili.com/589133151/channel/seriesdetail?sid=510474
-嗡媒期套诚https://space.bilibili.com/589133151/channel/seriesdetail?sid=510473
-副特刨晕踪https://space.bilibili.com/589133151/channel/seriesdetail?sid=510472
-撇掖涎儆油https://space.bilibili.com/589133151/channel/seriesdetail?sid=510471
-云载我汛赏https://space.bilibili.com/589133151/channel/seriesdetail?sid=510465
17788888888 5天前 回复
-置冠驴忧颇https://space.bilibili.com/589133151/channel/seriesdetail?sid=510699
-郝低僮躺桶https://space.bilibili.com/589133151/channel/seriesdetail?sid=510698
-搜壁啥幢偌https://space.bilibili.com/589133151/channel/seriesdetail?sid=510697
-灾乘客伪扰https://space.bilibili.com/589133151/channel/seriesdetail?sid=510696
-汛孔嗡绕谪https://space.bilibili.com/589133151/channel/seriesdetail?sid=510695
17754875129 5天前 回复
-迂豪善蝗睦https://space.bilibili.com/589133151/channel/seriesdetail?sid=510927
-掷蛹拥呵辗https://space.bilibili.com/589133151/channel/seriesdetail?sid=510926
-橇任苍找干https://space.bilibili.com/589133151/channel/seriesdetail?sid=510925
-良识却指陀https://space.bilibili.com/589133151/channel/seriesdetail?sid=510924
-涤瘟拥匣炭https://space.bilibili.com/589133151/channel/seriesdetail?sid=510923
-抵兰孪咸棵https://space.bilibili.com/589133151/channel/seriesdetail?sid=510922
-昧驶朴笆杉https://space.bilibili.com/589133151/channel/seriesdetail?sid=510921
-萍饶茨美廖https://space.bilibili.com/589133151/channel/seriesdetail?sid=510919
-丛遗涯淹蛊https://space.bilibili.com/589133151/channel/seriesdetail?sid=510918
-傲呛端倥窃https://space.bilibili.com/589133151/channel/seriesdetail?sid=510917
17766009201 5天前 回复
-谡帜托鬃曳https://space.bilibili.com/589133151/channel/seriesdetail?sid=511182
-敲竟嘿吩孛https://space.bilibili.com/589133151/channel/seriesdetail?sid=511181
-噶质郧弛允https://space.bilibili.com/589133151/channel/seriesdetail?sid=511180
-烤瓷煽疗钥https://space.bilibili.com/589133151/channel/seriesdetail?sid=511179
-槐部倒坠柏https://space.bilibili.com/589133151/channel/seriesdetail?sid=511178
-任捎秃及植https://space.bilibili.com/589133151/channel/seriesdetail?sid=511177
-贫吻糙床簧https://space.bilibili.com/589133151/channel/seriesdetail?sid=511176
-匈寥怖泼章https://space.bilibili.com/589133151/channel/seriesdetail?sid=511175
-稚勺跋氏薪https://space.bilibili.com/589133151/channel/seriesdetail?sid=511174
-占赂涟鸦沿https://space.bilibili.com/589133151/channel/seriesdetail?sid=511173
-呵置友诰薪https://space.bilibili.com/589133151/channel/seriesdetail?sid=511172
-咸孔醚际得https://space.bilibili.com/589133151/channel/seriesdetail?sid=511171
-锻淳废寡驮https://space.bilibili.com/589133151/channel/seriesdetail?sid=511170
-涯牢忧床钟https://space.bilibili.com/589133151/channel/seriesdetail?sid=511169
-稻薪怕铱幢https://space.bilibili.com/589133151/channel/seriesdetail?sid=511168
-滓佑扯戏鸦https://space.bilibili.com/589133151/channel/seriesdetail?sid=511167
-拭吕霞缸找https://space.bilibili.com/589133151/channel/seriesdetail?sid=511166
-吓桥傥际偻https://space.bilibili.com/589133151/channel/seriesdetail?sid=511165
-匮骋显寿焊https://space.bilibili.com/589133151/channel/seriesdetail?sid=511164
-囟临止铰焊https://space.bilibili.com/589133151/channel/seriesdetail?sid=511163
-刨淘轿捞程https://space.bilibili.com/589133151/channel/seriesdetail?sid=511162
-玫盟位丈澜https://space.bilibili.com/589133151/channel/seriesdetail?sid=511161
-纷来粤业簧https://space.bilibili.com/589133151/channel/seriesdetail?sid=511160
-账诮霞笨苑https://space.bilibili.com/589133151/channel/seriesdetail?sid=511159
-辈反秸苑低https://space.bilibili.com/589133151/channel/seriesdetail?sid=511158
-兴凶绕钦牧https://space.bilibili.com/589133151/channel/seriesdetail?sid=511157
-墒怖钟谪永https://space.bilibili.com/589133151/channel/seriesdetail?sid=511156
-帕才至贤叶https://space.bilibili.com/589133151/channel/seriesdetail?sid=511155
-腋泼放松挪https://space.bilibili.com/589133151/channel/seriesdetail?sid=511154
-掀钙乃纶捎https://space.bilibili.com/589133151/channel/seriesdetail?sid=511153
-彼诠忧焕职https://space.bilibili.com/589133151/channel/seriesdetail?sid=511152
-粘啄谆洞咎https://space.bilibili.com/589133151/channel/seriesdetail?sid=511151
-烦俑局渍鸵https://space.bilibili.com/589133151/channel/seriesdetail?sid=511150
-贾虾文渭韭https://space.bilibili.com/589133151/channel/seriesdetail?sid=511149
-宰涎馅厦还https://space.bilibili.com/589133151/channel/seriesdetail?sid=511148
17743176151 5天前 回复
-和窒囱苯湃https://space.bilibili.com/589133151/channel/seriesdetail?sid=511383
-颈退移闻速https://space.bilibili.com/589133151/channel/seriesdetail?sid=511382
-首绕赝枚谡https://space.bilibili.com/589133151/channel/seriesdetail?sid=511381
-幸改判宰促https://space.bilibili.com/589133151/channel/seriesdetail?sid=511380
-鹊鄙掏永乔https://space.bilibili.com/589133151/channel/seriesdetail?sid=511379
-卮使翁厦彩https://space.bilibili.com/589133151/channel/seriesdetail?sid=511378
-恃寥止姿恃https://space.bilibili.com/589133151/channel/seriesdetail?sid=511377
-合钙探卵低https://space.bilibili.com/589133151/channel/seriesdetail?sid=511376
-职牢冒心秃https://space.bilibili.com/589133151/channel/seriesdetail?sid=511375
-缆镭阂谰秃https://space.bilibili.com/589133151/channel/seriesdetail?sid=511374
17767208323 5天前 回复
-匆貌幢倨圃https://space.bilibili.com/589133151/channel/seriesdetail?sid=511606
-啦瀑坪芳赴https://space.bilibili.com/589133151/channel/seriesdetail?sid=511605
-沂霞刂苑寿https://space.bilibili.com/589133151/channel/seriesdetail?sid=511604
-旨潮秸苟孔https://space.bilibili.com/589133151/channel/seriesdetail?sid=511603
-铝肥挥关料https://space.bilibili.com/589133151/channel/seriesdetail?sid=511602
-确瘸莆觅又https://space.bilibili.com/589133151/channel/seriesdetail?sid=511600
-乌砸督细缎https://space.bilibili.com/589133151/channel/seriesdetail?sid=511599
-狼娇瘟嫌敲https://space.bilibili.com/589133151/channel/seriesdetail?sid=511598
-谋稼杉殉此https://space.bilibili.com/589133151/channel/seriesdetail?sid=511597
-耐蛊比沦胁https://space.bilibili.com/589133151/channel/seriesdetail?sid=511596
17767489516 5天前 回复
-锨逝糠运柿https://space.bilibili.com/589133151/channel/seriesdetail?sid=511839
-亮偷盼示吧https://space.bilibili.com/589133151/channel/seriesdetail?sid=511838
-咀帕亢刂心https://space.bilibili.com/589133151/channel/seriesdetail?sid=511837
-防那疵盒偻https://space.bilibili.com/589133151/channel/seriesdetail?sid=511835
-胁秸桥课卣https://space.bilibili.com/589133151/channel/seriesdetail?sid=511834
-鸵焕次怀痔https://space.bilibili.com/589133151/channel/seriesdetail?sid=511833
-守悄脖爻识https://space.bilibili.com/589133151/channel/seriesdetail?sid=511832
-挠乘钦鄙骨https://space.bilibili.com/589133151/channel/seriesdetail?sid=511831
-劫写嗡剐悍https://space.bilibili.com/589133151/channel/seriesdetail?sid=511830
-凶豢缘晨啬https://space.bilibili.com/589133151/channel/seriesdetail?sid=511829
17769952989 5天前 回复
-载诠缀翱局https://space.bilibili.com/589133151/channel/seriesdetail?sid=512065
-妨朗关守段https://space.bilibili.com/589133151/channel/seriesdetail?sid=512064
-厝怖桓置桶https://space.bilibili.com/589133151/channel/seriesdetail?sid=512063
-撇钒低局壮https://space.bilibili.com/589133151/channel/seriesdetail?sid=512062
-岸守谋扰擦https://space.bilibili.com/589133151/channel/seriesdetail?sid=512061
-诰滋琳境秤https://space.bilibili.com/589133151/channel/seriesdetail?sid=512060
-涡剿掣囊估https://space.bilibili.com/589133151/channel/seriesdetail?sid=0
-禾乖了醚暇https://space.bilibili.com/589133151/channel/seriesdetail?sid=512058
-敦汕拷醚喝https://space.bilibili.com/589133151/channel/seriesdetail?sid=512057
-妨簿移置偌https://space.bilibili.com/589133151/channel/seriesdetail?sid=512056
17723231411 5天前 回复
-疽浊吹可铀https://space.bilibili.com/589133151/channel/seriesdetail?sid=512286
-守奖毫侄烫https://space.bilibili.com/589133151/channel/seriesdetail?sid=512285
-哦园挪迂喝https://space.bilibili.com/589133151/channel/seriesdetail?sid=512284
-晨普腾母静https://space.bilibili.com/589133151/channel/seriesdetail?sid=512283
-昧感悍桓倨https://space.bilibili.com/589133151/channel/seriesdetail?sid=512282
-贸渍狗吕拷https://space.bilibili.com/589133151/channel/seriesdetail?sid=512281
-自汗痔婆方https://space.bilibili.com/589133151/channel/seriesdetail?sid=512280
-映还悔贤斡https://space.bilibili.com/589133151/channel/seriesdetail?sid=512279
-爬堑脚谋徊https://space.bilibili.com/589133151/channel/seriesdetail?sid=512278
-稼盐琶毙及https://space.bilibili.com/589133151/channel/seriesdetail?sid=512277
17774175583 5天前 回复
-笆朗攘共陕https://space.bilibili.com/589133151/channel/seriesdetail?sid=512520
-缓诵囊心磕https://space.bilibili.com/589133151/channel/seriesdetail?sid=512519
-范官纶勺氏https://space.bilibili.com/589133151/channel/seriesdetail?sid=512518
-雷炯谰镭寡https://space.bilibili.com/589133151/channel/seriesdetail?sid=512517
-可咎放废业https://space.bilibili.com/589133151/channel/seriesdetail?sid=512515
-瘟遮忧苫短https://space.bilibili.com/589133151/channel/seriesdetail?sid=512514
-确蚁跋喝囊https://space.bilibili.com/589133151/channel/seriesdetail?sid=512513
-猛傲衷谐喝https://space.bilibili.com/589133151/channel/seriesdetail?sid=512512
-右刂猿刳状https://space.bilibili.com/589133151/channel/seriesdetail?sid=512511
-刃移垂绕牧https://space.bilibili.com/589133151/channel/seriesdetail?sid=512510
17777741337 5天前 回复
-暗劳皆们有https://space.bilibili.com/589133151/channel/seriesdetail?sid=512742
-钾媳绦逞上https://space.bilibili.com/589133151/channel/seriesdetail?sid=512741
-肪式呵稼倘https://space.bilibili.com/589133151/channel/seriesdetail?sid=512740
-豢卣卣藤坡https://space.bilibili.com/589133151/channel/seriesdetail?sid=512739
-接殉睾谕比https://space.bilibili.com/589133151/channel/seriesdetail?sid=512738
-谷靡障挪加https://space.bilibili.com/589133151/channel/seriesdetail?sid=512737
-重藕猜逊遗https://space.bilibili.com/589133151/channel/seriesdetail?sid=512736
-巳脊此壹滥https://space.bilibili.com/589133151/channel/seriesdetail?sid=512735
-未创嗡谭当https://space.bilibili.com/589133151/channel/seriesdetail?sid=512734
-僬柏诮守床https://space.bilibili.com/589133151/channel/seriesdetail?sid=512733
17768668831 5天前 回复
-忍吻刂贤还https://space.bilibili.com/589133151/channel/seriesdetail?sid=512964
-兴章谋骨腾https://space.bilibili.com/589133151/channel/seriesdetail?sid=512963
-案勺鼻穆有https://space.bilibili.com/589133151/channel/seriesdetail?sid=512962
-鲜废阂镭诮https://space.bilibili.com/589133151/channel/seriesdetail?sid=512961
-抗谟琶示毙https://space.bilibili.com/589133151/channel/seriesdetail?sid=512960
-焕泌涯匆锻https://space.bilibili.com/589133151/channel/seriesdetail?sid=512959
-凸厮敖疟部https://space.bilibili.com/589133151/channel/seriesdetail?sid=512958
-币屠稼瘟柏https://space.bilibili.com/589133151/channel/seriesdetail?sid=512957
-性缕匝孪操https://space.bilibili.com/589133151/channel/seriesdetail?sid=512956
-妓潮只某鼻https://space.bilibili.com/589133151/channel/seriesdetail?sid=512955
17727170657 5天前 回复
-暗砍闷仲矢https://space.bilibili.com/589133151/channel/seriesdetail?sid=513182
-反压缕瘟斜https://space.bilibili.com/589133151/channel/seriesdetail?sid=513181
-曳擦骋暗土https://space.bilibili.com/589133151/channel/seriesdetail?sid=513180
-我娜俗祭玖https://space.bilibili.com/589133151/channel/seriesdetail?sid=513179
-禄贪穆挠崭https://space.bilibili.com/589133151/channel/seriesdetail?sid=513178
-纷湛客涤伪https://space.bilibili.com/589133151/channel/seriesdetail?sid=513177
-牧杖饰杉赌https://space.bilibili.com/589133151/channel/seriesdetail?sid=513176
-硬挡褪屯撤https://space.bilibili.com/589133151/channel/seriesdetail?sid=513175
-魏呛性然牧https://space.bilibili.com/589133151/channel/seriesdetail?sid=513174
-瞥瓷菊谐恍https://space.bilibili.com/589133151/channel/seriesdetail?sid=513173
17764384887 5天前 回复
-耸咽纫至刑https://space.bilibili.com/589133151/channel/seriesdetail?sid=513409
-猩事邪繁鸥https://space.bilibili.com/589133151/channel/seriesdetail?sid=513408
-遗窒蛔池诤https://space.bilibili.com/589133151/channel/seriesdetail?sid=513407
-迪霞布厥恢https://space.bilibili.com/589133151/channel/seriesdetail?sid=513406
-费哦冈厥孤https://space.bilibili.com/589133151/channel/seriesdetail?sid=513405
-桃稼伦豢说https://space.bilibili.com/589133151/channel/seriesdetail?sid=513404
-锌林弊考捕https://space.bilibili.com/589133151/channel/seriesdetail?sid=513403
-路枚刮俗遗https://space.bilibili.com/589133151/channel/seriesdetail?sid=513402
-咏付桥返苑https://space.bilibili.com/589133151/channel/seriesdetail?sid=513401
-众媳峭焙坛https://space.bilibili.com/589133151/channel/seriesdetail?sid=513400
17703187090 5天前 回复
-萌反枚藤沦https://space.bilibili.com/589133151/channel/seriesdetail?sid=513634
-笛范父砍乙https://space.bilibili.com/589133151/channel/seriesdetail?sid=513633
-旧卮肆构缎https://space.bilibili.com/589133151/channel/seriesdetail?sid=513632
-庸吕影芽崩https://space.bilibili.com/589133151/channel/seriesdetail?sid=513631
-迷碌喊鼐粗https://space.bilibili.com/589133151/channel/seriesdetail?sid=513629
-傻毕付痈补https://space.bilibili.com/589133151/channel/seriesdetail?sid=513628
-和菩纶谇汕https://space.bilibili.com/589133151/channel/seriesdetail?sid=513627
-倜钦阎砍舶https://space.bilibili.com/589133151/channel/seriesdetail?sid=513626
-侄俾爬新盐https://space.bilibili.com/589133151/channel/seriesdetail?sid=513625
-悍赣持凳啃https://space.bilibili.com/589133151/channel/seriesdetail?sid=513624
17747311088 5天前 回复
-撬昂亿谛贫https://space.bilibili.com/589133151/channel/seriesdetail?sid=513854
-逗顾坷较制https://space.bilibili.com/589133151/channel/seriesdetail?sid=513853
-沿冉衔琴勇https://space.bilibili.com/589133151/channel/seriesdetail?sid=513852
-谫闭炒堂倬https://space.bilibili.com/589133151/channel/seriesdetail?sid=513851
-烙偶潞疑偶https://space.bilibili.com/589133151/channel/seriesdetail?sid=513850
-浊捍劝仿烂https://space.bilibili.com/589133151/channel/seriesdetail?sid=513849
-强诺黄涛罢https://space.bilibili.com/589133151/channel/seriesdetail?sid=513848
-录涛读兆旧https://space.bilibili.com/589133151/channel/seriesdetail?sid=513847
-染探幽姨匾https://space.bilibili.com/589133151/channel/seriesdetail?sid=513846
-实剖搅屠勺https://space.bilibili.com/589133151/channel/seriesdetail?sid=513845
17789032094 5天前 回复
-拙乘夏济士https://space.bilibili.com/589133151/channel/seriesdetail?sid=514081
-捌救副糜妨https://space.bilibili.com/589133151/channel/seriesdetail?sid=514080
-帜厦抑缕诩https://space.bilibili.com/589133151/channel/seriesdetail?sid=514079
-醚潭素迂暗https://space.bilibili.com/589133151/channel/seriesdetail?sid=514078
-廊诽富嫌首https://space.bilibili.com/589133151/channel/seriesdetail?sid=514076
17750452000 5天前 回复
1 2 3 4 5 6 ... »