Overview
PantallaRestauranteCubit manages the state for the restaurant details screen, handling the loading and display of a specific restaurant’s information.
Source: lib/presentacion/pantalla_restaurante/pantalla_restaurante_cubit.dart
Purpose
This Cubit provides state management for:- Loading a specific restaurant’s details from Firestore
- Displaying restaurant information, contact details, and specialties
- Managing loading and error states for the details screen
- Providing data for navigation to reservation features
State Classes
Source:lib/presentacion/pantalla_restaurante/pantalla_restaurante_estados_de_cubit.dart
PantallaRestauranteInicial
Initial state when the screen first loads.PantallaRestauranteCargando
Loading state while fetching restaurant details.cargarDatosNegocio() execution.
PantallaRestauranteExitoso
Success state with loaded restaurant details.negocio: Complete restaurant data including name, contact info, specialty, description
PantallaRestauranteConError
Error state when loading fails.mensaje: Error description in Spanish
Methods
cargarDatosNegocio()
Loads a specific restaurant’s details from Firestore.negocioId(optional): ID of the restaurant to load
- Emits
PantallaRestauranteCargando - Validates that
negocioIdis provided - Calls
NegocioRepositorio.obtenerNegocioPorId(negocioId) - On success: Emits
PantallaRestauranteExitosowith restaurant data - On error: Emits
PantallaRestauranteConErrorwith error message
Dependencies
Constructor
NegocioRepositorio: For fetching restaurant data by ID
Dependency Injection
Registered in GetIt service locator:Usage in UI
Screen Integration
Source:lib/presentacion/pantalla_restaurante/pantalla_restaurante_screen.dart
State Handling
Navigation Flow
Receiving the Restaurant ID
The screen receivesnegocioId via route navigation:
Passing ID to Child Screens
The loaded restaurant ID is passed to other features:State Flow Diagram
Error Handling
Validation Errors
| Error | Cause | Message |
|---|---|---|
| Missing ID | negocioId is null or empty | ”ID de negocio no proporcionado” |
| Not found | Restaurant doesn’t exist in Firestore | ”Restaurante no encontrado” |
| Network error | Firestore unavailable | ”Error al cargar datos del restaurante: …” |
Fallback Behavior
When in error or loading state, the UI displays default values:- Name: “Restaurante”
- Specialty: “Gastronomía”
Data Usage
Displayed Information
From theNegocio entity:
Testing
Unit Test Example
See Also
Restaurant Details
User guide for the restaurant details screen
Negocio Entity
Complete restaurant data structure
NegocioRepositorio
Repository methods for restaurant data
PantallaInicioCubit
Related: Restaurant listing state