在使用showModalBottomSheet這個控件時,想要設置圓角,可以在內容widget設置不管用,然後直接看這個控件的實現原理,準備看到到底什麼鬼!一看有個shape屬性,感覺有戲!果然設置完畢後,成功了。
注意:一定不要設置builder中的背景顏色,否則會覆蓋導致不能顯示出圓角!
showModalBottomSheet
- shape可以設置成自己想要的形狀!通常直接設置圓角即可
- isScrollControlled:是否時全屏還是半屏
- isDismissible:外部是否可以點擊,false不可以點擊,true可以點擊,點擊後消失
- backgroundColor : 通常可以設置白色和透明,
以下代碼:
showModalBottomSheet(
context: context,
isScrollControlled:false,
backgroundColor: Colors.white,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(10))),
builder: (BuildContext context) {
return Container(
height:50,//對話框高度就是此高度
child: Center(child: Text("居中文字")),
);
});