答案 0 :(得分:20)
我认为最好的方法是使用带有垂直RoundedRectangleBorder
的{{1}},并只设置其BorderRadius
属性:
top
为左上角和右上角使用单独的半径会更加冗长且容易出错。
答案 1 :(得分:19)
这是所需的modalBottomSheet函数。
void _modalBottomSheetMenu(){
showModalBottomSheet(
context: context,
builder: (builder){
return new Container(
height: 350.0,
color: Colors.transparent, //could change this to Color(0xFF737373),
//so you don't have to change MaterialApp canvasColor
child: new Container(
decoration: new BoxDecoration(
color: Colors.white,
borderRadius: new BorderRadius.only(
topLeft: const Radius.circular(10.0),
topRight: const Radius.circular(10.0))),
child: new Center(
child: new Text("This is a modal sheet"),
)),
);
}
);
}
此工作中最重要的部分是,在MaterialApp中,将canvasColor设置为透明,如下所示。
return new MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Tasks',
theme: new ThemeData(
primarySwatch: Colors.teal,
canvasColor: Colors.transparent,
),
home: new TasksHomePage(),
);
}
我测试了代码并且工作正常,因为我还在克隆Google Tasks应用程序,该应用程序将在我的github中开源。
答案 2 :(得分:18)
showModalBottomSheet(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(
top: Radius.circular(20),
),
),
clipBehavior: Clip.antiAliasWithSaveLayer,
)
答案 3 :(得分:13)
我没有像其他答案所建议的那样覆盖应用程序的整个主题(在应用程序的各个部分中引起了问题),我决定看一下showModalBottomSheet
的实现并亲自找到问题。事实证明,所需要做的只是将模态的主要代码包装在包含Theme
技巧的canvasColor: Colors.transparent
小部件中。我还使自定义半径以及模态本身的颜色变得更加容易。
您可以使用pub上的package或包含相同代码的gist。不要忘记导入正确的包/文件。
showRoundedModalBottomSheet(
context: context,
radius: 20.0, // This is the default
color: Colors.white, // Also default
builder: (context) => ???,
);
答案 4 :(得分:11)
我有此代码,对我来说很好。请检查并告诉我您的意见。
showBottomSheet(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(
top: Radius.circular(20),
),
),
context: context,
builder: (context) => Container(
height: 250,
child: new Container(
decoration: new BoxDecoration(
color: Theme.of(context).primaryColor,
borderRadius: new BorderRadius.only(
topLeft: const Radius.circular(20.0),
topRight: const Radius.circular(20.0))),
child: new Center(
child: new Text("This is a modal sheet"),
)),
))
答案 5 :(得分:3)
您可以在 RoundedRectangleBorder
中添加一个 showModalBottomSheet
小部件:
showModalBottomSheet<void>(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10.0),
topRight: Radius.circular(10.0)
),
),
)
答案 6 :(得分:2)
把以前所有的答案放在一起,我可以达到最好的结果。
showModalBottomSheet(
context: context,
backgroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(topLeft: Radius.circular(15.0), topRight: Radius.circular(15.0)),
),
builder: (context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
ListTile(
leading: Icon(Icons.email),
title: Text('Send email'),
onTap: () {
print('Send email');
},
),
ListTile(
leading: Icon(Icons.phone),
title: Text('Call phone'),
onTap: () {
print('Call phone');
},
),
],
);
});
答案 7 :(得分:2)
showModalBottomSheet(
backgroundColor: Colors.transparent,
context: context,
builder: (ctx) {
return Container(
decoration: BoxDecoration(
color: Colors.green, // or some other color
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10.0),
topRight: Radius.circular(10.0)
)
);
});
答案 8 :(得分:1)
您现在可以简单地设置shape
参数。
示例:
showModalBottomSheet(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(10.0)),
),
context: context,
builder: (context) => MyBottomSheet(),
);
答案 9 :(得分:0)
回答了一个相关问题
您可以在角落{{1}中添加角点,并根据其中的内容扩展db.collection.aggregate([
{
$match: {
$expr: {
$eq: [
{
$strLenCP: "$word"
},
6
]
}
}
}
]);
(不限于屏幕的一半大小) )
查看答案here
答案 10 :(得分:0)
您也可以在装饰容器中设置 borderRadius。
showModalBottomSheet(
context: context,
builder: (builder){
return Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: const Radius.circular(15.0),
topRight: const Radius.circular(15.0))),
child: Center(
child: Text("This is a modal sheet"),
),
);
}
);