Data Flow & State Management
Relevant source files
The following files were used as context for generating this wiki page:
The Fikak application utilizes a structured data flow and state management architecture to ensure a predictable and scalable user experience. The system is built upon the Flutter framework, leveraging asynchronous streams and provider-based state propagation to handle user interactions, remote data fetching, and local persistence.
The core of the data flow revolves around a unidirectional architecture where events trigger state transitions, which in turn update the UI. This ensures that the application state remains synchronized across different views and modules.
State Management Architecture
The application employs a reactive state management approach. Key states, such as user authentication and product listings, are managed through dedicated providers that notify listeners of any changes.
Authentication State
The authentication state is managed globally to control access to protected routes and features. It transitions between several discrete states: Initial, Loading, Authenticated, and Unauthenticated.
Data Flow Logic
Data flows through the system starting from external API responses, passing through data models, and eventually reaching the UI layer via providers.
Network Layer and API Interaction
The ApiClient serves as the centralized gateway for all HTTP requests. It handles headers, authentication tokens, and error parsing.
| Component | Responsibility |
|---|---|
| ApiClient | Manages Dio/Http instances and base URLs |
| Interceptors | Attaches Bearer tokens to outgoing requests |
| Transformers | Converts raw JSON into typed DTOs |
Sources: lib/core/network/api_client.dart
Model Transformation
Raw JSON data is transformed into immutable Dart objects using factory constructors. This ensures type safety throughout the application logic.
State Synchronization
The application ensures that local state remains consistent with the backend using the following mechanisms:
- Optimistic Updates: UI updates immediately on user action while the network request executes in the background.
- Provider Overrides: Used during testing to inject mock states into the widget tree.
- Error Handling: Centralized catch blocks in providers update the state with error messages, which are then displayed via SnackBars or Error Widgets.
Data Model Fields: Product
| Field | Type | Description |
|---|---|---|
| id | String | Unique identifier for the product |
| name | String | Display name of the item |
| price | Double | Cost in local currency |
| imageUrl | String | Link to the product thumbnail |
Sources: lib/features/home/data/models/product_model.dart
Conclusion
The data flow and state management in fikak_app are designed for reliability and maintainability. By separating the networking layer, the data modeling, and the state propagation, the application achieves a clean separation of concerns. This architecture allows for easy debugging and scaling as new features are added to the platform.