BLoC Integration
The Chromia UI example app uses flutter_bloc for state management, specifically for theme switching and brand management.Installation
Add the required dependencies to yourpubspec.yaml:
Theme Management with BLoC
Component State Management
For managing component-level state, you can use BLoC, Cubit, or simpleStatefulWidget:
Using StatefulWidget (Simple Cases)
Using Cubit (Complex Cases)
Brand Switching Example
Here’s how to implement brand switching in your app:Other State Management Solutions
Provider
Riverpod
Best Practices
Keep theme state at the app level
Keep theme state at the app level
Theme configuration should be managed at the highest level of your app to ensure consistent theming across all screens.
Use Cubits for simple state
Use Cubits for simple state
For straightforward state management like theme switching, use Cubits instead of full Blocs.
Separate concerns
Separate concerns
Keep theme management separate from business logic. Create dedicated state management for UI concerns vs. data concerns.
Persist theme preferences
Persist theme preferences
Use
shared_preferences or hive to persist user theme choices:Related Resources
Theming Guide
Learn more about Chromia UI theming
Example App
View the full BLoC implementation
