- Agrega getters patientLat/patientLng al ProfessionalsProvider - Calcula distancia Haversine entre la ubicación del paciente y el consultorio del profesional, mostrándola en azul (ej: "1.3 km" o "800 m") en la card - Muestra la dirección del consultorio (icono de tienda) en ambos layouts: horizontal (compact) y vertical (grid) - Distancia solo visible cuando el paciente tiene coordenadas registradas Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
661 lines
24 KiB
Dart
661 lines
24 KiB
Dart
import 'dart:async';
|
|
import 'dart:math' as math;
|
|
import 'package:flutter/material.dart';
|
|
import 'package:prosapp_web_app/models/location_preferences.dart';
|
|
import 'package:prosapp_web_app/models/usuario_profesional.dart';
|
|
import 'package:prosapp_web_app/providers/professionals_provider.dart';
|
|
import 'package:prosapp_web_app/providers/theme_provider.dart';
|
|
import 'package:prosapp_web_app/services/navigation_service.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
class ProfessionalsView extends StatefulWidget {
|
|
const ProfessionalsView({super.key});
|
|
|
|
@override
|
|
State<ProfessionalsView> createState() => _ProfessionalsViewState();
|
|
}
|
|
|
|
class _ProfessionalsViewState extends State<ProfessionalsView> {
|
|
String _search = '';
|
|
Timer? _debounce;
|
|
final _controller = TextEditingController();
|
|
|
|
@override
|
|
void dispose() {
|
|
_debounce?.cancel();
|
|
_controller.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
void _onSearchChanged(String value) {
|
|
setState(() => _search = value);
|
|
_debounce?.cancel();
|
|
_debounce = Timer(const Duration(milliseconds: 450), () {
|
|
context.read<ProfessionalsProvider>().getProfessionals(search: value);
|
|
});
|
|
}
|
|
|
|
void _clearSearch() {
|
|
_controller.clear();
|
|
_onSearchChanged('');
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final provider = context.watch<ProfessionalsProvider>();
|
|
final isDark = context.watch<ThemeProvider>().isDark;
|
|
|
|
final filtered = provider.professionals;
|
|
|
|
final cardBg = isDark ? const Color(0xFF1E293B) : Colors.white;
|
|
final border = isDark ? const Color(0xFF334155) : const Color(0xFFE5E7EB);
|
|
final inputFill = isDark ? const Color(0xFF0F172A) : const Color(0xFFF1F5F9);
|
|
final hintColor = isDark ? const Color(0xFF64748B) : const Color(0xFF94A3B8);
|
|
|
|
return Column(
|
|
children: [
|
|
// ── Barra de búsqueda ──
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(0, 0, 0, 14),
|
|
child: TextField(
|
|
controller: _controller,
|
|
onChanged: _onSearchChanged,
|
|
style: TextStyle(
|
|
color: isDark ? Colors.white : const Color(0xFF111827),
|
|
fontSize: 14,
|
|
),
|
|
decoration: InputDecoration(
|
|
hintText: 'Buscar por nombre, profesión o ciudad...',
|
|
hintStyle: TextStyle(color: hintColor, fontSize: 13),
|
|
prefixIcon:
|
|
const Icon(Icons.search, color: Color(0xFF42A4EF), size: 20),
|
|
suffixIcon: _search.isNotEmpty
|
|
? IconButton(
|
|
icon: Icon(Icons.close, size: 18, color: hintColor),
|
|
onPressed: _clearSearch,
|
|
)
|
|
: null,
|
|
filled: true,
|
|
fillColor: inputFill,
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
borderSide: BorderSide(color: border),
|
|
),
|
|
enabledBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
borderSide: BorderSide(color: border),
|
|
),
|
|
focusedBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
borderSide:
|
|
const BorderSide(color: Color(0xFF42A4EF), width: 2),
|
|
),
|
|
contentPadding:
|
|
const EdgeInsets.symmetric(vertical: 13, horizontal: 4),
|
|
),
|
|
),
|
|
),
|
|
|
|
// ── Lista / grid / estados ──
|
|
Expanded(
|
|
child: provider.isLoading
|
|
? const Center(child: CircularProgressIndicator())
|
|
: filtered.isEmpty
|
|
? _EmptyState(isDark: isDark, search: _search)
|
|
: LayoutBuilder(
|
|
builder: (context, constraints) {
|
|
final w = constraints.maxWidth;
|
|
final cols = w >= 1200
|
|
? 4
|
|
: w >= 800
|
|
? 3
|
|
: w >= 500
|
|
? 2
|
|
: 1;
|
|
|
|
return GridView.builder(
|
|
padding: EdgeInsets.zero,
|
|
gridDelegate:
|
|
SliverGridDelegateWithFixedCrossAxisCount(
|
|
crossAxisCount: cols,
|
|
crossAxisSpacing: 12,
|
|
mainAxisSpacing: 12,
|
|
childAspectRatio: cols == 1 ? 2.4 : 0.78,
|
|
),
|
|
itemCount: filtered.length,
|
|
itemBuilder: (context, i) => _ProfCard(
|
|
data: filtered[i],
|
|
isDark: isDark,
|
|
cardBg: cardBg,
|
|
border: border,
|
|
compact: cols == 1,
|
|
patientLat: provider.patientLat,
|
|
patientLng: provider.patientLng,
|
|
onTap: () async {
|
|
final result = await NavigationService
|
|
.navigateToFuture(
|
|
'/dashboard/calendar/${filtered[i].user.id}',
|
|
);
|
|
if (context.mounted) {
|
|
Navigator.pop(context, [
|
|
filtered[i],
|
|
result[0] as DateTime,
|
|
result[1] as TimeOfDay,
|
|
]);
|
|
}
|
|
},
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
// ── Card ─────────────────────────────────────────────────────────────────────
|
|
|
|
double? _haversineKm(double? lat1, double? lng1, double? lat2, double? lng2) {
|
|
if (lat1 == null || lng1 == null || lat2 == null || lng2 == null) return null;
|
|
if (lat2 == 0.0 && lng2 == 0.0) return null;
|
|
const r = 6371.0;
|
|
final dLat = (lat2 - lat1) * math.pi / 180;
|
|
final dLng = (lng2 - lng1) * math.pi / 180;
|
|
final a = math.sin(dLat / 2) * math.sin(dLat / 2) +
|
|
math.cos(lat1 * math.pi / 180) * math.cos(lat2 * math.pi / 180) *
|
|
math.sin(dLng / 2) * math.sin(dLng / 2);
|
|
return r * 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a));
|
|
}
|
|
|
|
String _formatDistance(double km) {
|
|
if (km < 1) return '${(km * 1000).round()} m';
|
|
return '${km.toStringAsFixed(1)} km';
|
|
}
|
|
|
|
class _ProfCard extends StatelessWidget {
|
|
final UsuarioProfesional data;
|
|
final bool isDark;
|
|
final Color cardBg;
|
|
final Color border;
|
|
final bool compact;
|
|
final double? patientLat;
|
|
final double? patientLng;
|
|
final VoidCallback onTap;
|
|
|
|
const _ProfCard({
|
|
required this.data,
|
|
required this.isDark,
|
|
required this.cardBg,
|
|
required this.border,
|
|
required this.compact,
|
|
required this.onTap,
|
|
this.patientLat,
|
|
this.patientLng,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final textPrimary = isDark ? Colors.white : const Color(0xFF111827);
|
|
final textSecondary =
|
|
isDark ? const Color(0xFF94A3B8) : const Color(0xFF6B7280);
|
|
final hasPic =
|
|
data.user.picture != null && data.user.picture!.isNotEmpty;
|
|
final score = data.averageScore;
|
|
final pm = data.professionalInfo.paymentMethods;
|
|
|
|
final profLat = data.professionalInfo.latitude;
|
|
final profLng = data.professionalInfo.longitude;
|
|
final distKm = _haversineKm(patientLat, patientLng, profLat, profLng);
|
|
final hasOffice = data.professionalInfo.locationPreferences != LocationPreferences.delivery;
|
|
final address = data.professionalInfo.address;
|
|
|
|
if (compact) {
|
|
// Fila horizontal en pantallas pequeñas
|
|
return Material(
|
|
color: cardBg,
|
|
borderRadius: BorderRadius.circular(14),
|
|
child: InkWell(
|
|
onTap: onTap,
|
|
borderRadius: BorderRadius.circular(14),
|
|
child: Container(
|
|
padding: const EdgeInsets.all(14),
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(14),
|
|
border: Border.all(color: border),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
_Avatar(hasPic: hasPic, picture: data.user.picture, name: data.user.name, size: 60),
|
|
const SizedBox(width: 14),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Text(data.user.name,
|
|
style: TextStyle(
|
|
fontSize: 15,
|
|
fontWeight: FontWeight.w700,
|
|
color: textPrimary)),
|
|
const SizedBox(height: 3),
|
|
if (data.professionalInfo.profession.isNotEmpty)
|
|
Text(data.professionalInfo.profession,
|
|
style: TextStyle(
|
|
fontSize: 12,
|
|
color: const Color(0xFF42A4EF),
|
|
fontWeight: FontWeight.w500)),
|
|
const SizedBox(height: 4),
|
|
Row(children: [
|
|
_StarRow(score: score),
|
|
const SizedBox(width: 10),
|
|
if (data.user.city != null && data.user.city!.isNotEmpty)
|
|
Row(children: [
|
|
Icon(Icons.location_on_outlined,
|
|
size: 11, color: textSecondary),
|
|
const SizedBox(width: 2),
|
|
Text(data.user.city!,
|
|
style: TextStyle(
|
|
fontSize: 11, color: textSecondary)),
|
|
]),
|
|
if (distKm != null) ...[
|
|
const SizedBox(width: 8),
|
|
Icon(Icons.near_me_outlined, size: 11, color: const Color(0xFF42A4EF)),
|
|
const SizedBox(width: 2),
|
|
Text(_formatDistance(distKm),
|
|
style: const TextStyle(fontSize: 11, color: Color(0xFF42A4EF), fontWeight: FontWeight.w600)),
|
|
],
|
|
]),
|
|
if (hasOffice && address.isNotEmpty) ...[
|
|
const SizedBox(height: 3),
|
|
Row(children: [
|
|
Icon(Icons.store_outlined, size: 11, color: textSecondary),
|
|
const SizedBox(width: 2),
|
|
Flexible(
|
|
child: Text(address,
|
|
style: TextStyle(fontSize: 11, color: textSecondary),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis),
|
|
),
|
|
]),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
Icon(Icons.chevron_right, color: textSecondary, size: 20),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
// Tarjeta vertical (grid)
|
|
return Material(
|
|
color: cardBg,
|
|
borderRadius: BorderRadius.circular(16),
|
|
child: InkWell(
|
|
onTap: onTap,
|
|
borderRadius: BorderRadius.circular(16),
|
|
child: Container(
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(16),
|
|
border: Border.all(color: border),
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
// ── Header con avatar ──
|
|
Container(
|
|
height: 90,
|
|
decoration: BoxDecoration(
|
|
gradient: LinearGradient(
|
|
colors: isDark
|
|
? [const Color(0xFF1E3A5F), const Color(0xFF0D1B3E)]
|
|
: [const Color(0xFFDBEAFE), const Color(0xFFBFDBFE)],
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
),
|
|
borderRadius: const BorderRadius.vertical(
|
|
top: Radius.circular(16)),
|
|
),
|
|
child: Stack(
|
|
clipBehavior: Clip.none,
|
|
children: [
|
|
// Score badge
|
|
Positioned(
|
|
top: 10,
|
|
right: 10,
|
|
child: Container(
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 8, vertical: 4),
|
|
decoration: BoxDecoration(
|
|
color: Colors.black.withOpacity(0.25),
|
|
borderRadius: BorderRadius.circular(20),
|
|
),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
const Icon(Icons.star_rounded,
|
|
color: Colors.amber, size: 13),
|
|
const SizedBox(width: 3),
|
|
Text(
|
|
score.toStringAsFixed(1),
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 11,
|
|
fontWeight: FontWeight.w700),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
// Avatar centrado en la parte inferior del header
|
|
Positioned(
|
|
bottom: -28,
|
|
left: 0,
|
|
right: 0,
|
|
child: Center(
|
|
child: _Avatar(
|
|
hasPic: hasPic,
|
|
picture: data.user.picture,
|
|
name: data.user.name,
|
|
size: 56,
|
|
border: true,
|
|
isDark: isDark,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
|
|
// ── Contenido ──
|
|
Expanded(
|
|
child: Padding(
|
|
padding: const EdgeInsets.fromLTRB(12, 36, 12, 12),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
// Nombre
|
|
Text(
|
|
data.user.name,
|
|
textAlign: TextAlign.center,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: TextStyle(
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w700,
|
|
color: textPrimary,
|
|
),
|
|
),
|
|
|
|
// Profesión
|
|
if (data.professionalInfo.profession.isNotEmpty) ...[
|
|
const SizedBox(height: 3),
|
|
Text(
|
|
data.professionalInfo.profession,
|
|
textAlign: TextAlign.center,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: const TextStyle(
|
|
fontSize: 11,
|
|
color: Color(0xFF42A4EF),
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
],
|
|
|
|
// Ciudad
|
|
if (data.user.city != null &&
|
|
data.user.city!.isNotEmpty) ...[
|
|
const SizedBox(height: 4),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(Icons.location_on_outlined,
|
|
size: 11, color: textSecondary),
|
|
const SizedBox(width: 2),
|
|
Flexible(
|
|
child: Text(
|
|
data.user.city!,
|
|
style: TextStyle(
|
|
fontSize: 11, color: textSecondary),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
|
|
// Distancia al consultorio
|
|
if (distKm != null) ...[
|
|
const SizedBox(height: 4),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
const Icon(Icons.near_me_outlined, size: 11, color: Color(0xFF42A4EF)),
|
|
const SizedBox(width: 3),
|
|
Text(_formatDistance(distKm),
|
|
style: const TextStyle(
|
|
fontSize: 11,
|
|
color: Color(0xFF42A4EF),
|
|
fontWeight: FontWeight.w600)),
|
|
],
|
|
),
|
|
],
|
|
|
|
// Dirección del consultorio
|
|
if (hasOffice && address.isNotEmpty) ...[
|
|
const SizedBox(height: 4),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(Icons.store_outlined, size: 11, color: textSecondary),
|
|
const SizedBox(width: 3),
|
|
Flexible(
|
|
child: Text(
|
|
address,
|
|
style: TextStyle(fontSize: 11, color: textSecondary),
|
|
textAlign: TextAlign.center,
|
|
maxLines: 2,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
|
|
const Spacer(),
|
|
|
|
// Métodos de pago
|
|
if (pm.datafono || pm.nequi || pm.transferencia) ...[
|
|
const Divider(height: 16),
|
|
Wrap(
|
|
alignment: WrapAlignment.center,
|
|
spacing: 4,
|
|
runSpacing: 4,
|
|
children: [
|
|
if (pm.datafono)
|
|
_PayChip(
|
|
label: 'Datáfono',
|
|
icon: Icons.credit_card_outlined,
|
|
isDark: isDark),
|
|
if (pm.nequi)
|
|
_PayChip(
|
|
label: 'Nequi',
|
|
icon: Icons.phone_android_outlined,
|
|
isDark: isDark),
|
|
if (pm.transferencia)
|
|
_PayChip(
|
|
label: 'Transferencia',
|
|
icon: Icons.account_balance_outlined,
|
|
isDark: isDark),
|
|
],
|
|
),
|
|
] else
|
|
Text('Sin métodos de pago',
|
|
style: TextStyle(
|
|
fontSize: 10, color: textSecondary)),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
// ── Widgets auxiliares ────────────────────────────────────────────────────────
|
|
|
|
class _Avatar extends StatelessWidget {
|
|
final bool hasPic;
|
|
final String? picture;
|
|
final String name;
|
|
final double size;
|
|
final bool border;
|
|
final bool isDark;
|
|
|
|
const _Avatar({
|
|
required this.hasPic,
|
|
required this.picture,
|
|
required this.name,
|
|
required this.size,
|
|
this.border = false,
|
|
this.isDark = false,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
width: size,
|
|
height: size,
|
|
decoration: BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
color: const Color(0xFF42A4EF).withOpacity(0.15),
|
|
border: border
|
|
? Border.all(
|
|
color: isDark ? const Color(0xFF1E293B) : Colors.white,
|
|
width: 3)
|
|
: null,
|
|
),
|
|
child: ClipOval(
|
|
child: hasPic
|
|
? FadeInImage.assetNetwork(
|
|
placeholder: 'loader.gif',
|
|
image: picture!,
|
|
fit: BoxFit.cover,
|
|
)
|
|
: Center(
|
|
child: Text(
|
|
name.isNotEmpty ? name[0].toUpperCase() : '?',
|
|
style: TextStyle(
|
|
color: const Color(0xFF42A4EF),
|
|
fontSize: size * 0.38,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _StarRow extends StatelessWidget {
|
|
final double score;
|
|
const _StarRow({required this.score});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
const Icon(Icons.star_rounded, color: Colors.amber, size: 14),
|
|
const SizedBox(width: 3),
|
|
Text(score.toStringAsFixed(1),
|
|
style: const TextStyle(
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.w600,
|
|
color: Colors.amber)),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class _PayChip extends StatelessWidget {
|
|
final String label;
|
|
final IconData icon;
|
|
final bool isDark;
|
|
|
|
const _PayChip(
|
|
{required this.label, required this.icon, required this.isDark});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 3),
|
|
decoration: BoxDecoration(
|
|
color: const Color(0xFF42A4EF).withOpacity(0.08),
|
|
borderRadius: BorderRadius.circular(6),
|
|
border: Border.all(
|
|
color: const Color(0xFF42A4EF).withOpacity(0.25)),
|
|
),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Icon(icon, size: 10, color: const Color(0xFF42A4EF)),
|
|
const SizedBox(width: 3),
|
|
Text(label,
|
|
style: const TextStyle(
|
|
fontSize: 9,
|
|
color: Color(0xFF42A4EF),
|
|
fontWeight: FontWeight.w600)),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _EmptyState extends StatelessWidget {
|
|
final bool isDark;
|
|
final String search;
|
|
const _EmptyState({required this.isDark, required this.search});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final textPrimary = isDark ? Colors.white : const Color(0xFF111827);
|
|
final textSecondary =
|
|
isDark ? const Color(0xFF94A3B8) : const Color(0xFF6B7280);
|
|
return Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(Icons.person_search_outlined,
|
|
size: 64, color: textSecondary.withOpacity(0.4)),
|
|
const SizedBox(height: 16),
|
|
Text(
|
|
search.isNotEmpty
|
|
? 'Sin resultados para "$search"'
|
|
: 'No hay profesionales disponibles',
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w600,
|
|
color: textPrimary),
|
|
),
|
|
const SizedBox(height: 6),
|
|
Text(
|
|
search.isNotEmpty
|
|
? 'Intenta con otro nombre o profesión'
|
|
: 'Aún no hay profesionales activos en tu ciudad',
|
|
style: TextStyle(fontSize: 13, color: textSecondary),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|