Implementing the Segmented State Pattern
So far, we have mostly been working with various implementations of the component that connects the Model to the View. We briefly looked at the state and even made it more life-like by handling progress and error via the isProcessing
and error
fields. Having distinct states for progress, error, and value is a very common pattern and it has even been given a name – the Segmented State Pattern or the Triple Pattern (https://docs.flutter.dev/data-and-backend/state-mgmt/options#triple-pattern-segmented-state-pattern). While there is a library with this name, I think that this name is very suitable for the pattern itself, regardless of how it is implemented.
While our implementation works for our example and does the job, in reality, it introduces quite some architectural problems. Let’s talk about them.
First of all, it is a good idea and practice to make the existence of an invalid state that is not explicitly handled impossible...