Overview
PantallaInicioCubit manages the state for the restaurant selection screen (home screen), handling the loading and display of all available restaurants in the system.
Source: lib/presentacion/pantalla_inicio/pantalla_inicio_cubit.dart
Purpose
This Cubit provides state management for:- Loading all registered restaurants from Firestore
- Displaying restaurant list to customers
- Handling loading and error states
- Managing business owner authentication flows
State Classes
Source:lib/presentacion/pantalla_inicio/pantalla_inicio_estados_de_cubit.dart
PantallaInicioInicial
Initial state when the screen first loads.PantallaInicioCargando
Loading state while fetching restaurants from Firestore.cargarNegocios() execution.
PantallaInicioExitoso
Success state with loaded restaurant list.negocios: List of all available restaurants
PantallaInicioConError
Error state when loading fails.mensaje: Error description in Spanish
Methods
cargarNegocios()
Loads all restaurants from Firestore.- Emits
PantallaInicioCargando - Calls
NegocioRepositorio.obtenerTodosLosNegocios() - On success: Emits
PantallaInicioExitosowith restaurant list - On error: Emits
PantallaInicioConErrorwith error message
Dependencies
Constructor
NegocioRepositorio: For fetching restaurant data
Dependency Injection
Registered in GetIt service locator:Usage in UI
Screen Integration
Source:lib/presentacion/pantalla_inicio/pantalla_inicio_screen.dart
State Handling
State Flow Diagram
Error Handling
Common Errors
| Error | Cause | User Message |
|---|---|---|
| Network error | No internet connection | ”Error al cargar restaurantes: Network error” |
| Firestore error | Database unavailable | ”Error al cargar restaurantes: Firestore error” |
| Empty list | No restaurants in database | Shows “No hay restaurantes disponibles” |
Retry Strategy
Users can retry by:- Pulling down to refresh the list
- Tapping a “Reintentar” button (if implemented)
Performance Considerations
Caching
Currently, this Cubit does not cache restaurant data. Each screen load fetches fresh data from Firestore. Future improvement opportunity:Firestore Reads
Each call tocargarNegocios() reads all restaurant documents from Firestore. For large datasets, consider:
- Pagination
- Incremental loading
- Firestore query limits
Testing
Unit Test Example
See Also
Restaurant Selection
User guide for the restaurant selection screen
Negocio Entity
Restaurant data structure
NegocioRepositorio
Repository for loading restaurants
State Management Guide
BLoC/Cubit patterns in this project