簡體   English   中英

列中的 Flutter 2 Streambuilders

[英]Flutter 2 Streambuilders in Column

我有 2 個要顯示的流構建器,其中都有一個 Listview 構建器。 我想將這兩個流構建器放在一個滾動列中,但它不起作用。 我嘗試將它們包裝在 Expanded 或 Flexible 中,但我無法弄清楚。 使用擴展小部件時的問題是,即使小部件沒有任何子部件,它仍然占據屏幕的很大一部分。 例如,當 streambuilder 1 沒有數據時,它仍然使用屏幕的一部分。 提前致謝!

這是我的代碼:

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(),
           ),
          },
        ),
      ),
    ],
  ),
)

您可以通過將physics 屬性設置為physics: NeverScrollableScrollPhysics()來使ListView 小部件永不滾動,並且使用shrinkWrap: true,您可以更改此行為,以便ListView 僅占用它需要的空間(當有更多項目時,它仍會滾動) . 它在單個可滾動中制作兩個不同的 StreamBuilder 小部件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM