【问题标题】:Flutter StreamBuilder only for ListView and GridView?Flutter StreamBuilder 仅适用于 ListView 和 GridView?
【发布时间】:2019-06-18 21:48:02
【问题描述】:

除了 ListView 和 GridView 之外的其他小部件是否可以使用 StreamBuilder...?

比方说ChoiceChip?为什么 ChoiceChip 没有构建器?

【问题讨论】:

  • 您可以在 StreamBuilder 中使用任何小部件
  • @diegoveloper 是的,流中的任何小部件都是可能的。但我有一个流,想从这个流中构建 ChoiceChip。但是没有ChoiceChip builder。

标签: flutter


【解决方案1】:

是的。我们可以将任何其他小部件与 Stream 一起使用 见官方docs

StreamBuilder(
    stream: bloc.allMovies,
    builder: (context, AsyncSnapshot<ItemModel> snapshot) {
      if (snapshot.hasData) {
        return Text("data incoming");
      } else if (snapshot.hasError) {
        return Text(snapshot.error.toString());
      }
      return Center(child: CircularProgressIndicator());
    },
  )

 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-23
    • 2020-10-20
    • 1970-01-01
    • 2020-10-01
    • 1970-01-01
    • 2019-06-10
    • 1970-01-01
    • 2020-04-29
    相关资源
    最近更新 更多