我正在尝试使用一个警报对话框,该对话框的中心是按钮,但是该按钮一直显示在警报框的右侧。
这是警报框的代码:
class Dialog extends StatelessWidget {
String title;
String content;
Dialog(this.title, this.content);
TextStyle textStyle = TextStyle (color: Colors.black);
@override
Widget build(BuildContext context) {
return BackdropFilter(
filter: ImageFilter.blur(sigmaX: 6, sigmaY: 6),
child: AlertDialog(
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(10)),
),
title: new Text(title,style: textStyle,),
content: new Text(content, style: textStyle,),
actions: <Widget>[
Align(
alignment: Alignment.center,
child: RaisedButton(
color: Colors.lightBlue[900],
child: Text("OK"),
onPressed: () {
Navigator.of(context).pop();
},
),
)
],
));
}
}
有人可以帮我把这个按钮放在中心吗? 最佳答案
像这样重构你的actions
actions: <Widget>[
Container(
width: double.maxFinite,
alignment: Alignment.center,
child: RaisedButton(
color: Colors.lightBlue[900],
child: Text("OK"),
onPressed: () {
Navigator.of(context).pop();
},
),
)
],
关于flutter - 在Flutter AlertDialog中按钮未对准中心,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/64160518/