Edmund Tam
Sep 4, 2018 · 1 min read

Thank you very much! The complex version does clear up some of my questions (the per-product BLoC is inspiring). Now when I try to implement the pattern in my Flutter application, I see the following challenges:

  1. How does the RefreshIndicator widget fit into this model? Its onRefresh method expects me to return a Future which must complete when the refresh operation is finished. But I have no idea how it can combine with the current implementation using the BLoC pattern.
  2. It looks like at the end we’ll need to not only listen to the item list, but a series of states: Loading (data init for the first time, maybe show full screen circular progress), Loaded (with item list), Error (with error details to be shown on UI), and Refreshing (similar to loading, but this action is triggered by RefreshIndicator, so shouldn’t cover the screen with the circular progress indicator). If I use a different stream to deliver the state I’ll probably end with nested StreamBuilders, which doesn’t seem a good idea (isn’t we need to take care of the disposal of the inner builder when the other one is being rebuilt? Can it be done without a second stateful widget?). Otherwise the only way would be to wrap all the needed stuff into multiple “state” classes (LoadingState, LoadedState, ErrorState, RefreshingState etc), or one state class with various states.

    Edmund Tam

    Written by