gpt4 book ai didi

flutter - 无法居中对齐列小部件子项

转载 作者:IT王子 更新时间:2023-10-29 07:18:41 26 4
gpt4 key购买 nike

我想将我的 Column 的子部件与横轴的中心对齐。我尝试使用 Column 的 crossAxisAlignment 属性来执行此操作,但它不起作用。我怎样才能解决这个问题?

 @override Widget build(BuildContext context) {

Container buttonView = Container(
padding: EdgeInsets.only(top: 30.0, left: 35.0, right: 35.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,

children: <Widget>[

DropdownButton<String>(
...
),
SizedBox(height: 20.0),
DropdownButton<String>(
...
],
));

return Scaffold(

body: buttonView,
);
}

最佳答案

你应该尝试ma​​inAxisAlignment: MainAxisAlignment.center,下面是快照,

    @override Widget build(BuildContext context) {

Container buttonView = Container(
padding: EdgeInsets.only(top: 30.0, left: 35.0, right: 35.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center, // <---- try this property

children: <Widget>[

DropdownButton<String>(
...
),
SizedBox(height: 20.0),
DropdownButton<String>(
...
],
));

return Scaffold(

body: buttonView,
);
}

关于flutter - 无法居中对齐列小部件子项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56470707/

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