[英]How to show custom dialog at the top center of the screen in flutter?
I am going to show a custom dialog at the top center of the screen.我将在屏幕顶部中心显示一个自定义对话框。
I've attached a screenshot .我附上了截图。
How can I accomplish this?我怎样才能做到这一点? Default position of Dialog is center of the screen.
Dialog 的默认 position 是屏幕的中心。
showDialog(
context: context,
builder: (BuildContext context) {
return alert;
},
);
You can use Align and Material widget.您可以使用对齐和材质小部件。 (
Alignment.topCenter
) ie (
Alignment.topCenter
)即
void showCustomDialog(BuildContext context, String message) {
showDialog(
barrierDismissible: false,
context: context,
builder: (BuildContext cxt) {
return Align(
alignment: Alignment.topCenter,
child: Padding(
padding: EdgeInsets.all(16),
child: Material(
color: Colors.green,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15)),
child: Padding(
padding: EdgeInsets.all(16),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
children: [
InkWell(
onTap: () {
Navigator.of(context).pop();
},
child: Image.asset("assets/close.png")),
SizedBox(width: 16),
Expanded(
child: Text(
message,
style: TextStyle(
color: Colors.white,
),
),
),
],
),
],
),
),
),
),
);
},
);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.