[英]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:现在,这是更好的方法:
USE CASE 2:用例 2:
A Login page with Components:带有组件的登录页面:
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.