我如何在一列中有2个小部件,其中1个是可滚动的列?

问题描述 投票:0回答:1

所以我在列中有两个小部件,一个是Container(顶部小部件),另一个是Column(应该可滚动的底部小部件),但是Column未被视为可滚动的如下图所示:

Result snippet

这是代码中的ContainerColumn

<Widget>[
    topBar, // Container
    Container(
      color: Colors.transparent,
      child: SingleChildScrollView(
        child: Column( // Column in container
          children: <Widget>[
            Text(
              "Test",
              style: TextStyle(fontSize: 50),
            ),
            Text(
              "Test",
              style: TextStyle(fontSize: 50),
            ),
            Text(
              "Test",
              style: TextStyle(fontSize: 50),
            ),
            // Insert Other Text Widgets below            
          ],
        ),
      ),
    )
  ]

topBar在哪里:

Container(
    margin: EdgeInsets.all(0),
    padding: EdgeInsets.fromLTRB(20, 0, 20, 0),
    child: Text(
      'Top Container',
      style: TextStyle(
          color: Colors.white,
          fontWeight: FontWeight.bold,
          fontSize: 25.0
      ),
    ),
);

我已经尝试使用类似问题中提到的ListView,但它具有相同的作用。

[我怀疑这是因为它试图超越父容器,后者不能滚动,但我不知道该如何克服。


UPDATE

为了澄清,我想做的是使用带有固定顶部栏的ScrollView,我也不想栏也滚动。

在Android上只是创建两种布局的一种情况,一种是内部带有ScrollView的布局。但是我猜测Flutter的处理方式有所不同,而且似乎无法绕开它。

flutter dart flutter-layout
1个回答
0
投票

如果将第二个Column包装在Expanded中,它将尝试占据尽可能多的空间,然后Column中的溢出元素将滚动。这应该可以解决您的问题。示例:

Column(
  children: <Widget>[
    topBar, // Container
    Expanded(
      child: Container(
        color: Colors.transparent,
        child: SingleChildScrollView(
          child: Column(
            // Column in container
            children: <Widget>[
              for (int i = 0; i < 30; i++)
                Text(
                  "Test",
                  style: TextStyle(fontSize: 50),
                ),
            ],
          ),
        ),
      ),
    )
  ],
),
© www.soinside.com 2019 - 2024. All rights reserved.