简体   繁体   English

将多个 StreamBuilder 用于单个屏幕的不同部分(BLOC 模式)是不是个好主意?

[英]Is it bad idea to use multiple StreamBuilders for different parts of a single screen (BLOC pattern)?

USE CASE 1:用例 1:

Lets say I have a screen which displays 3 different lists, List-1, List-2, List-3 (display as horizontally scrollable lists).假设我有一个显示 3 个不同列表的屏幕,List-1、List-2、List-3(显示为可水平滚动的列表)。

The 3 lists are fetched from 3 different.network requests.这 3 个列表是从 3 个不同的网络请求中获取的。 And I am using BLOC pattern to contain all.network request inside and BLOC and then feed the result back to page using streams.我正在使用 BLOC 模式在内部包含 all.network 请求和 BLOC,然后使用流将结果反馈回页面。

Now, which is better way to do this:现在,这是更好的方法:

  1. Use Single StreamBuilder wrapping the whole state of page (all the 3 lists) and in Bloc load all 3.network request and send the updated State through stream.使用 Single StreamBuilder 包装整个 state 页面(所有 3 个列表)并在 Bloc 中加载所有 3.network 请求并通过 stream 发送更新的 State。
  2. Use 3 StreamBuilders for 3 lists listening to 3 Streams in the BLOC.将 3 个 StreamBuilder 用于 3 个列表,监听 BLOC 中的 3 个流。 So as each.network request completes only the corresponsing list Stream is triggered and built.因此,当每个网络请求完成时,只会触发和构建相应的列表 Stream。

USE CASE 2:用例 2:

A Login page with Components:带有组件的登录页面:

  1. User name and password textFields, where user name shows list of suggestions using Stack用户名和密码文本字段,其中用户名显示使用 Stack 的建议列表
  2. A submit button with support for CircularProgressIndicator within it.一个支持 CircularProgressIndicator 的提交按钮。

Using 1 StreamBuilder to wrap whole state or Use 2 StreamBuilders for 1 wrapping textFields and 1 StreamBuilder wrapping submit button.使用 1 个 StreamBuilder 包装整个 state 或使用 2 个 StreamBuilder 包装 1 个包装文本字段和 1 个 StreamBuilder 包装提交按钮。 So only Button will be rebuilt if Loading state changes.因此,如果 Loading state 发生变化,只会重建 Button。

Are there any tradeoffs or performance issues caused by having Multiple StreamBuilders in a single screen?在单个屏幕中使用多个 StreamBuilder 是否会导致权衡或性能问题?

UPDATE : Added another use case.更新:添加了另一个用例。

I would use different streams.我会使用不同的流。 First of all, looking into the "official" bloc examples, you will find multiple blocs for a page, for example filtering vs list.首先,查看“官方”bloc 示例,您会发现一个页面有多个 bloc,例如过滤与列表。

In your example, if you have 3.network requests, you may get 3 different answers at different times/speeds.在你的例子中,如果你有 3.network 请求,你可能会在不同的时间/速度下得到 3 个不同的答案。 So for UX, I would show what you get and not wait, until the last bit got transmitted所以对于 UX,我会展示你得到的,而不是等待,直到最后一位被传输

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM