gpt4 book ai didi

Flutter:如何使对话框的按钮居中?

转载 作者:行者123 更新时间:2023-12-03 03:16:00 28 4
gpt4 key购买 nike

我的对话框有问题,按钮不会居中,即使我已经有了

mainAxisAlignment: MainAxisAlignment.center, 
crossAxisAlignment: CrossAxisAlignment.center

在里面。我的代码:

actions: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width * 0.20,
child: RaisedButton(
child: new Text(
'Save',
style: TextStyle(color: Colors.white),
),
color: Color(0xFF121A21),
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0),
),
onPressed: () {
saveIssue();
Navigator.of(context).pop();
},
),
),
SizedBox(
width: MediaQuery.of(context).size.width * 0.01,
),
Container(
width: MediaQuery.of(context).size.width * 0.20,
child: RaisedButton(
child: new Text(
'Cancel',
style: TextStyle(color: Colors.white),
),
color: Color(0xFF121A21),
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0),
),
onPressed: () {
Navigator.of(context).pop();
},
),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.02,
),
],
)
],

我的界面:

Link for my UI

最佳答案

根据source code , 使用 ButtonBar 强制对齐,所以如果你想改变对齐方式,你应该用 ButtonBarTheme 包裹 AlertDialog

class TestDialog extends StatelessWidget {
const TestDialog({Key key}) : super(key: key);

@override
Widget build(BuildContext context) {
return ButtonBarTheme(
data: ButtonBarThemeData(alignment: MainAxisAlignment.center),
child: AlertDialog(
content: Text("CONTENT_CONTENT_CONTENT_CONTENT_CONTENT_CONTENT_CONTENT_CONTENT_CONTENT_CONTENT_CONTENT_CONTENT_CONTENT_CONTENT_CONTENT_CONTENT_CONTENT_"),
actions: <Widget>[
Row(
mainAxisSize: MainAxisSize.max,
//mainAxisAlignment: MainAxisAlignment.center,
//crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width * 0.20,
child: RaisedButton(
child: new Text(
'Save',
style: TextStyle(color: Colors.white),
),
color: Color(0xFF121A21),
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0),
),
onPressed: () {
Navigator.of(context).pop();
},
),
),
SizedBox(
width: MediaQuery.of(context).size.width * 0.01,
),
Container(
width: MediaQuery.of(context).size.width * 0.20,
child: RaisedButton(
child: new Text(
'Cancel',
style: TextStyle(color: Colors.white),
),
color: Color(0xFF121A21),
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0),
),
onPressed: () {
Navigator.of(context).pop();
},
),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.02,
),
],
)
],
)
);
}
}

结果:

enter image description here

关于Flutter:如何使对话框的按钮居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58534455/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com