[英]Flutter 2 Streambuilders in Column
I have 2 streambuilders that I want to display, both with a Listview builder inside them.我有 2 个要显示的流构建器,其中都有一个 Listview 构建器。 I want to put both those streambuilders in a scrollabe column but it just won't work.
我想将这两个流构建器放在一个滚动列中,但它不起作用。 I tried wrapping them in an Expanded or Flexible and I just can't figure it out.
我尝试将它们包装在 Expanded 或 Flexible 中,但我无法弄清楚。 The problem when using the expanded widget is that even if the widget doesn't have any children, it still takes in a big part of the screen.
使用扩展小部件时的问题是,即使小部件没有任何子部件,它仍然占据屏幕的很大一部分。 When for example streambuilder 1 doesn't have data, it still uses a proportion of the screen.
例如,当 streambuilder 1 没有数据时,它仍然使用屏幕的一部分。 Thanks in advance!
提前致谢!
This is my code briefly:这是我的代码:
SingleChildScrollView(
child: Column(
children: [
Expanded(
child: StreamBuilder(
stream: stream1,
builder: (context, snapshot) {
return ListView.builder();
},
),
),
Expanded(
child: StreamBuilder(
stream: stream2,
builder: (context, snapshot) {
return ListView.builder();
},
),
),
],
),
),
SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Expanded(
child: StreamBuilder(
stream: stream1,
builder: (context, snapshot) {
return ListView(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
children: firstList(),
),
},
),
),
Expanded(
child: StreamBuilder(
stream: stream2,
builder: (context, snapshot) {
return ListView(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
children: secondList(),
),
},
),
),
],
),
)
You can make the ListView widget never scrollable by setting physics property to physics: NeverScrollableScrollPhysics()
, and With shrinkWrap: true,
you can change this behavior so that the ListView only occupies the space it needs (it will still scroll when there more items).您可以通过将physics 属性设置为
physics: NeverScrollableScrollPhysics()
来使ListView 小部件永不滚动,并且使用shrinkWrap: true,
您可以更改此行为,以便ListView 仅占用它需要的空间(当有更多项目时,它仍会滚动) . its make two diferent StreamBuilder widget in a single scrollable.它在单个可滚动中制作两个不同的 StreamBuilder 小部件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.