我将在屏幕顶部中心显示一个自定义对话框。
我已附上屏幕截图。
我怎样才能做到这一点?对话框的默认位置是屏幕的中心。
showDialog(
context: context,
builder: (BuildContext context) {
return alert;
},
);
Run Code Online (Sandbox Code Playgroud)
您可以使用对齐和材质小部件。(Alignment.topCenter) IE
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,
),
),
),
],
),
],
),
),
),
),
);
},
);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8629 次 |
| 最近记录: |