扑。 listview.builder上面的小部件与其他内容一起滚动?

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

我想在列表视图的顶部添加一个信息框,而不是修复它,我希望它在页面向下滚动的同时滚动内容。相反,我所经历的是,无论我尝试做什么,它始终处于固定位置。

我的代码:

return new Column(children: <Widget>[

                new Text('I want to be scrollable as well with other content as well'), // I want widget or widgets here to be part of the scroll instead of them being fixed.
                new Expanded(


                  child: ListView.builder(
                    itemBuilder: (BuildContext context, int index) {
                      return index >= state.posts.length
                          ? BottomLoader()
                          : PostWidget(post: state.posts[index]);
                    },
                    itemCount: state.hasReachedMax
                        ? state.posts.length
                        : state.posts.length + 1,
                    controller: _scrollController,
                  ),
                ),
              ]);

这有可能实现吗?

flutter
1个回答
1
投票

我想你可以在0位置返回你的Text小部件或任何其他小部件?

return new Column(children: <Widget>[

                new Text('I want to be scrollable as well with other content as well'), // I want widget or widgets here to be part of the scroll instead of them being fixed.
                new Expanded(


                  child: ListView.builder(
                    itemBuilder: (BuildContext context, int index) {
                      if (index == 0) {
                        return Text('Your widget');
                      else { 
                        return index >= state.posts.length
                            ? BottomLoader()
                            : PostWidget(post: state.posts[index]);
                      }
                    },
                    itemCount: state.hasReachedMax
                        ? state.posts.length
                        : state.posts.length + 1,
                    controller: _scrollController,
                  ),
                ),
              ]);
© www.soinside.com 2019 - 2024. All rights reserved.