Architecture wise if i need to delegate error handling to a common component how to do this.
The approach i tried for now is as follows:
- Used an inherited widget in order to share a screen state (loading, error, displaying_data)
- Used a wrapper widget with a stack that shows the current screen and returns an overlay on top of it if the state is loading/ error
- For each screen i need to subscribe to the stream showing the data
- the screen is initially showing the loading widget,
- when data is returned screen state is updated to displaying_data, wrapper widget displays the content without the loading overlay.
I have a problem with this approach if I am using stream builders instead of subscribing to streams,
I get this error
"setState() or markNeedsBuild() called during build.
This MyInheritedWidget widget cannot be marked as needing to build because the framework is already in the process of building widgets. A widget can be marked as needing to be built during the build phase only if one of its ancestors is currently building. This exception is allowed because the framework builds parent widgets before children, which means a dirty descendant will always be built. Otherwise, the framework might not visit this widget during this build phase.
The widget on which setState() or markNeedsBuild() was called was:
MyInheritedWidget(state: MyInheritedWidgetState#dfaac)
The widget which was currently being built when the offending call was made was:
StreamBuilder<List<TypeListingModel>>(dirty, state: _StreamBuilderBaseState<List<TypeListingModel>, AsyncSnapshot<List<TypeListingModel>>>#8e379)"
which makes sense
since the widget is in the build process and what i am doing is forcing it to rebuild,
Can any one share what it would be like if i want to handle error in a more generic way than just showing it per screen ?
Thanks