Give `StreamBuilder` ability to be lossless

This issue has been created since 2022-09-22.

The documentation for StreamBuilder clearly states that the builder isn't called 1-to-1 with the Stream and that its intention is to just display the latest snapshot. However that doesn't stop people from assuming that it is 1-to-1 as evidenced in the StackOverflow answer here: https://stackoverflow.com/questions/64167602/create-list-view-with-stream-builder?newreg=44e616311fef471588b8f25184be3a6a.

I suspect the name of the class and its signature communicates that it may behave different than it does. A more proper name may have been LatestSnapshotBuilder. The punishment for using the API incorrectly is too high in this case. Imagine shipping a product that behaves correctly on your internet then a user that has a fast internet connection uses it and data is missing from the list.

Since the fail case is so dire I think we should have an escape valve in the API design, a bool that guarantees that StreamBuilder calls the builder 1-to-1 with the stream events. We could rename the class but that would probably be too disruptive.

Proposed API:

  const StreamBuilder({
    super.key,
    this.initialData,
    super.stream,
    required this.builder,
    bool isLossless = false,  // <-- new parameter
  });
bernaferrari wrote this answer on 2022-09-23

You should check the "swallow error" property from StreamBuilder/FutureBuilder, maybe isLossless could be made on the same way, a global variable, so users can override everywhere instead individually.

sarannng wrote this answer on 2022-09-26

Hi, @gaaclarke, I would like to work on this fix. If you can assign this to me it would be great. Thanks.

gaaclarke wrote this answer on 2022-09-26

Hey @sarannng, sounds good. Feel free to ping me for a PR review. It should be a fun fix. I'm not going to assign it to you since the team typically doesn't do that for PRs like this. You are free to fix the issue though.

sarannng wrote this answer on 2022-09-27

Hi @gaaclarke, just to clarify, all I need to do is add isLossLess parameter to StreamBuilder, right?

gaaclarke wrote this answer on 2022-09-27

That's correct, and make it work with tests showing it works of course.

goderbauer wrote this answer on 2022-09-27

How is the isLossless param supposed to work? If the stream provides updates more frequently then the framerate you still wouldn't see each entry on screen.

gaaclarke wrote this answer on 2022-09-27

How is the isLossless param supposed to work? If the stream provides updates more frequently then the framerate you still wouldn't see each entry on screen.

Right, but we'd play all the updates we've received from the Stream, even if that meant wasted building of things that will just be replaced before they are viewed. The implementation now is throwing them away. The isLossless argument would make the sample code from the stackoverflow link in the description work.

The important thing is, does the Stream represent atomic state, or does it represent partial state. Right now StreamBuilder works with atomic state Streams, but doesn't for partial state.

Even if no one used isLossless it would be worth implementing it imo since it would be another opportunity to communicate the semantics of StreamBuilder, and the only communication that happens in code.

More Details About Repo
Owner Name flutter
Repo Name flutter
Full Name flutter/flutter
Language Dart
Created Date 2015-03-06
Updated Date 2022-10-05
Star Count 145512
Watcher Count 3569
Fork Count 23398
Issue Count 11205

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
Scrap the ADR and start anew 0 2022-09-01 2022-09-15
Find a good solution for bloated lock files 8 2022-08-27 2022-09-15
Full prj-spec compatibility 0 2022-08-25 2022-09-15
Getting an error on a function 4 2021-06-29 2022-08-16
All issues have been wiped 0 2021-05-31 2022-09-12
Speed-up devnet initializations 1 2022-01-19 2022-09-02
Using Generics as return value type in Service-Endpoint leads to exception 1 2021-12-20 2022-10-03
Syntax HL for code blocks not working 2 2021-02-25 2022-09-03
Touch ring is working on the new version, but mouse wheel is zooming instead of rolling. 0 2021-03-01 2022-09-27
No compatible USB Bluetooth 4.0 device found 2 2020-10-28 2022-10-05
Unable to read data from characteristics. 1 2021-12-28 2022-10-05
Multiple definitions in HLIL SSA 2 2021-12-30 2022-10-02
Validate does not detect missing field in required 3 2020-10-07 2022-09-08
How to bundle paths? 4 2020-05-15 2022-08-29
Dereferencing caches last used `$ref` 3 2020-10-12 2022-08-29
[Question] How to disable plugin on large file? 2 2022-04-22 2022-09-28
Tradução para portugues 4 2022-08-31 2022-09-02
Update CI for deployment policies under semantic versioning 5 2021-12-06 2022-10-02
Rhino Issue: 1 2021-12-23 2021-12-22
Set specific "package.json" in the repo as main file 3 2022-07-11 2022-10-02
Add optional snapTo property in versionGroups 13 2022-07-11 2022-10-02
feat:1、执行器由手动添加改为自动注册;2、移除执行器延迟性 2 2021-12-03 2022-08-09
setInterval doesn't wake CPU in deep sleep 1 2020-01-12 2022-09-22
Clicking a server node fails to retrieve its data 3 2021-07-18 2022-09-24
Exception in com.haulmont.cuba.web.widgets.CubaButton during generate tenant group by tenant admin 0 2021-01-26 2022-10-04
[Testing] Add the ability to run tests in faster than normal time 0 2022-09-27 2022-10-03
Plans for supporting glTF export? 10 2019-09-21 2022-09-24
[Bug]: install error json file 0 2022-07-09 2022-08-27
Realm android permissions 2 2022-02-15 2022-10-02
www.darich.shop 1 2021-10-14 2022-01-16
Empty strings parsed as \"\" 3 2022-02-02 2022-09-16
I18nManager.isRTL returns undefined instead of boolean? 3 2022-07-24 2022-09-17
[v0.18 regression] Shadow rules in different StyleSheet objects no longer combine 4 2022-07-28 2022-09-17
MapPluginExtensionsDelegate#flyTo crashes with cameraForCoordinates and frequent padding updates 5 2022-02-10 2022-09-17
New Kotlin plugin doesn't work, but examples work fine 2 2021-05-12 2022-08-02
pretrained model of resnet50 2 2021-09-21 2022-09-18
File transfering for ESP32-C3 1 2022-04-02 2022-08-08
Uart on Teensy 4/4.1 act differently between 7.24 and 7.30B0 9 2022-04-02 2022-09-13
SCK in use after soft reboot on Feather m4 Express 2 2022-04-04 2022-09-01
Adafruit Feather RP2040 with rp2040 - Fails to create uart on D24 and D25 11 2022-04-02 2022-07-25
feature request: change graph update rate 2 2021-01-07 2022-10-02
can't export dns zone 3 2022-08-23 2022-09-22
How can I default this to dark mode? & also default to list mode? 1 2021-10-18 2022-09-20
How to use custom backbone pretrained on my own Dataset(not ImageNet)? 1 2021-05-26 2022-10-05
Flaky `IsValidIndex(cid)` assertion hit on `iso-stress bulider 1 2022-03-25 2022-10-04
Downloading Multiple Large Files Fails 1 2022-01-10 2022-08-16
Select Default Profile do not actually open gitbash. After relaunch, on startup, it just keeps open PowerShell 2 2021-05-12 2022-07-25
chore(deps): bump metascraper-image from 5.22.5 to 5.24.2 2 2021-08-24 2022-08-28
Add support for starting a CCS node with the FTR 1 2022-02-07 2022-08-25
JIT: limitations in hoisting (loop invariant code motion) 12 2020-05-02 2022-09-07