无法居中对齐“列小部件”子级

时间:2019-06-06 03:56:20

标签: flutter

我想将“专栏”的子级小部件与横轴中心对齐。 我尝试使用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,
    );
  }

1 个答案:

答案 0 :(得分:0)

您应该尝试 mainAxisAlignment: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,
  );
}