In the BLoC (Business Logic Component) state management pattern of Flutter Framework, there are typically few common states used to represent the different stages of data or UI changes.
Loading State
The loading state is used to indicate that the application or a specific feature is currently fetching data from an external source, such as an API or a database. This state is often displayed with a loading indicator or a progress bar to inform the user about the ongoing operation.
In Progress State
In progress state could be a loading state, but it could be transition between states of already loaded content. This state is implemented with different type of animations.
Another type that is in the middle is – when there are already loaded items and more content is in progress. In this case Loading with Tag (usually a string) is used.
Error State
An error state can be used to handle scenarios where an API call fails or an exception occurs. The error state can provide relevant error information to the user and allow for appropriate error handling.
Data/Content State
The data or content state represents the successful retrieval of data and its availability for presentation or manipulation. This state typically holds the fetched data and is responsible for rendering the appropriate UI components to display the content to the user. For example, it could be used to show a list of items fetched from an API.
Empty State
Many UIs have special UI for the case when
- the loading has finished
- there are no records in the database yet.
Initial State
The initial state represents the starting point of the application or a specific feature before any user interaction or data loading occurs. It usually indicates that the feature is in a neutral or idle state, waiting for user input or data to be fetched.
These states, provide a basic structure that is commonly used in Flutter applications leveraging the BLoC pattern. This enforces good practices and designs and makes you think about the else cases. I am offering you to continue reading – Why you need state management in Flutter.