首页 > 解决方案 > 无法更改 SingChildScroll 视图中的列轴对齐方式

问题描述

我想在列内的小部件之间添加间距,而不对每个 SizedBox 进行硬编码并给它们一定的高度,我想直接在列上设置它但没有对齐选项起作用,我做错了什么?这是什么原因造成的?

@override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Submit Your Order'),
      ),
      body: SingleChildScrollView(
        child: Padding(
          padding: EdgeInsets.all(20.0),
          child: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.spaceAround, // doesnt work
              children: [
                InformationField(
                  label: 'Phone Number',
                  hintText: 'Type Your Phone Number',
                ),
                InformationField(
                  label: 'Name',
                  hintText: 'Type Your Name',
                ),
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    InformationField(
                      label: 'Adress',
                      hintText: 'Neighborhood/City',
                    ),
                    SizedBox(
                      height: 5.0,
                    ),
                    RowInformationField()
                  ],
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }

标签: flutterdartalignmentsinglechildscrollview

解决方案


如果您正在使用SingleChildScrollView,请不要指望mainAxisAlignment工作。我建议您将其替换为CustomScrollView以达到您想要的结果。


推荐阅读