如何在颤振中固定列的顶部位置?

时间:2020-09-10 03:20:54

标签: flutter

如果我在列中添加小部件,则该列的顶部将向上。(图2)

有什么办法固定列的顶部?(图3)enter image description here

图片1

Column(
  crossAxisAlignment: CrossAxisAlignment.center
  mainAxisAlignment: MainAxisAlignment.center
  children: <Widget>[
    Text("Test1")
  ]
)

picture2

Column(
  crossAxisAlignment: CrossAxisAlignment.center
  mainAxisAlignment: MainAxisAlignment.center
  children: <Widget>[
    Text("Test1"),
    Text("Test2")
  ]
)

2 个答案:

答案 0 :(得分:1)

从上面的图片重新创建了您想要的:

制作两个Expanded小部件,然后让第二个Expanded小部件放入Column,在其中放置Text s小部件:

   return Scaffold(
      body: Column(
        children: [
          Expanded(
            child: SizedBox(),
          ),
          Expanded(
            child: SizedBox.expand(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Text(
                    'Test 1',
                    style: TextStyle(
                      fontSize: 20,
                      color: Colors.red,
                    ),
                  ),
                  Text(
                    'Test 2',
                    style: TextStyle(
                      fontSize: 20,
                      color: Colors.red,
                    ),
                  ),
                  Text(
                    'Test 3',
                    style: TextStyle(
                      fontSize: 20,
                      color: Colors.red,
                    ),
                  ),
                ],
              ),
            ),
          ),
        ],
      ),
    );

结果: enter image description here

答案 1 :(得分:-1)

使用 mainAxisAlignment:MainAxisAlignment.start