diff --git a/lib/ui/views/dashboard_view.dart b/lib/ui/views/dashboard_view.dart index 11b70f4..bccf8e9 100644 --- a/lib/ui/views/dashboard_view.dart +++ b/lib/ui/views/dashboard_view.dart @@ -270,10 +270,6 @@ class _DashboardViewState extends State { } Future _requestService() async { - if (_currentAddress.isEmpty) { - NotificationsService.showSnackBarError('Mueve el mapa para seleccionar tu dirección'); - return; - } if (_professional == null) { NotificationsService.showSnackBarError('Selecciona un profesional'); return; @@ -282,6 +278,20 @@ class _DashboardViewState extends State { NotificationsService.showSnackBarError('Selecciona fecha y hora'); return; } + + final profPrefs = _professional!.professionalInfo.locationPreferences; + final isOfficeOnly = profPrefs == LocationPreferences.office; + + // Dirección solo requerida cuando el profesional hace domicilios + if (!isOfficeOnly && _currentAddress.isEmpty) { + NotificationsService.showSnackBarError('Mueve el mapa para seleccionar tu dirección'); + return; + } + + final serviceLocation = isOfficeOnly + ? ServiceLocationPreferences.office + : ServiceLocationPreferences.delivery; + setState(() => _requesting = true); try { final service = Service( @@ -290,10 +300,10 @@ class _DashboardViewState extends State { professionalScored: false, userId: user!.id, userScored: false, - address: _currentAddress, + address: isOfficeOnly ? _professional!.professionalInfo.address : _currentAddress, aditionalAddress: '', - latitude: _mapCenter.latitude, - longitude: _mapCenter.longitude, + latitude: isOfficeOnly ? _professional!.professionalInfo.latitude : _mapCenter.latitude, + longitude: isOfficeOnly ? _professional!.professionalInfo.longitude : _mapCenter.longitude, day: _selectedDay.toString(), createdAt: DateTime.now().toIso8601String(), description: '', @@ -301,7 +311,7 @@ class _DashboardViewState extends State { range1Hour2: _selectedHour!.add(hour: 2), rate: '', status: ServiceStatus.pending, - location: ServiceLocationPreferences.delivery, + location: serviceLocation, ); await ApiService.instance.post('/services', service.toDocument()); NotificationsService.showSnackbar('Servicio solicitado exitosamente'); @@ -559,33 +569,72 @@ class _DashboardViewState extends State { ), const SizedBox(height: 10), - // Dirección actual - if (_currentAddress.isNotEmpty) - Container( - padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8), - margin: const EdgeInsets.only(bottom: 10), - decoration: BoxDecoration( - color: isDark - ? const Color(0xFF42A4EF).withOpacity(0.12) - : const Color(0xFFF0F8FF), - borderRadius: BorderRadius.circular(8), - border: Border.all(color: const Color(0xFF42A4EF).withOpacity(0.35)), - ), - child: Row( - children: [ - const Icon(Icons.location_on, size: 16, color: Color(0xFF42A4EF)), - const SizedBox(width: 8), - Expanded( - child: Text( - _currentAddress, - style: TextStyle(fontSize: 12, color: textColor), - maxLines: 2, - overflow: TextOverflow.ellipsis, - ), + // Dirección: solo relevante cuando el profesional hace domicilios + Builder(builder: (context) { + final prefs = _professional?.professionalInfo.locationPreferences; + final isOffice = prefs == LocationPreferences.office; + if (isOffice) { + // Mostrar dirección del consultorio del profesional + final profAddress = _professional?.professionalInfo.address ?? ''; + if (profAddress.isNotEmpty) { + return Container( + padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8), + margin: const EdgeInsets.only(bottom: 10), + decoration: BoxDecoration( + color: isDark + ? const Color(0xFF42A4EF).withOpacity(0.08) + : const Color(0xFFF0F8FF), + borderRadius: BorderRadius.circular(8), + border: Border.all(color: const Color(0xFF42A4EF).withOpacity(0.25)), ), - ], - ), - ), + child: Row( + children: [ + const Icon(Icons.store_outlined, size: 16, color: Color(0xFF42A4EF)), + const SizedBox(width: 8), + Expanded( + child: Text( + 'Consultorio: $profAddress', + style: TextStyle(fontSize: 12, color: textColor), + maxLines: 2, + overflow: TextOverflow.ellipsis, + ), + ), + ], + ), + ); + } + return const SizedBox.shrink(); + } + // Domicilio o ambos: mostrar dirección del cliente + if (_currentAddress.isNotEmpty) { + return Container( + padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8), + margin: const EdgeInsets.only(bottom: 10), + decoration: BoxDecoration( + color: isDark + ? const Color(0xFF42A4EF).withOpacity(0.12) + : const Color(0xFFF0F8FF), + borderRadius: BorderRadius.circular(8), + border: Border.all(color: const Color(0xFF42A4EF).withOpacity(0.35)), + ), + child: Row( + children: [ + const Icon(Icons.location_on, size: 16, color: Color(0xFF42A4EF)), + const SizedBox(width: 8), + Expanded( + child: Text( + _currentAddress, + style: TextStyle(fontSize: 12, color: textColor), + maxLines: 2, + overflow: TextOverflow.ellipsis, + ), + ), + ], + ), + ); + } + return const SizedBox.shrink(); + }), // Profesional GestureDetector( @@ -670,7 +719,8 @@ class _DashboardViewState extends State { const SizedBox(height: 12), // Aviso ciudad no disponible - if (!_cityAvailable && _detectedCity.isNotEmpty) + if (!_cityAvailable && _detectedCity.isNotEmpty && + _professional?.professionalInfo.locationPreferences != LocationPreferences.office) Container( width: double.infinity, margin: const EdgeInsets.only(bottom: 10), @@ -707,8 +757,9 @@ class _DashboardViewState extends State { ), ), - // Warning: dirección fuera de la ciudad del usuario - if (_cityMismatch && _detectedCity.isNotEmpty) + // Warning: dirección fuera de la ciudad del usuario (solo en modo domicilio) + if (_cityMismatch && _detectedCity.isNotEmpty && + _professional?.professionalInfo.locationPreferences != LocationPreferences.office) Container( width: double.infinity, margin: const EdgeInsets.only(bottom: 10), @@ -748,7 +799,11 @@ class _DashboardViewState extends State { SizedBox( width: double.infinity, child: ElevatedButton( - onPressed: (_requesting || !_cityAvailable || _cityMismatch) ? null : _requestService, + onPressed: _requesting + ? null + : (_professional?.professionalInfo.locationPreferences == LocationPreferences.office + ? _requestService + : (!_cityAvailable || _cityMismatch ? null : _requestService)), style: ElevatedButton.styleFrom( backgroundColor: const Color(0xFF42A4EF), foregroundColor: Colors.white,