fix: port 7 web features and repair the endless-loading screens
Root cause behind most "stuck loading" reports: the backend changed shape (schedules became an array, location_preferences a string) while the mobile parser still hard-cast to Map/int. The TypeError was swallowed by a silent catch that returned null, and screens only handled the success state, so a parse failure rendered as a permanent spinner. Same class of bug appeared across service lists via non-null map lookups and a total absence of request timeouts. Ported from prosappweb: - in-app suggestions (POST /suggestions) - policies/terms from GET /settings/policies - configurable appointment length (slot_duration_minutes) - block/unblock calendar slots (POST /services/block) - GPS city detection on the profile (Nominatim) - server-side professional search with haversine distance - retry cooldown after a rejected professional application Reliability: - parse schedules array (day_of_week 0=Mon) and string location_preferences - read times as wall clock, so 08:00 stays 08:00 across timezones - carry minutes into hours in TimeOfDay.add; a minute-based step used to loop forever and freeze the calendar (covered by test/time_slots_test.dart) - semver update check instead of string equality, which blocked every build that did not exactly match the configured version - request timeouts across all repositories - surface HTTP >= 400 instead of reporting failed writes as success - error states with retry instead of an indefinite shimmer Includes pre-existing uncommitted work from the UI redesign. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
06a89df690
commit
8631e6f729
@@ -6,6 +6,7 @@ import 'package:intl/intl.dart';
|
||||
import 'package:professional_repository/professional_repository.dart';
|
||||
import 'package:prosappco/blocs/service_bloc/service_bloc.dart';
|
||||
import 'package:prosappco/screens/service/professional_service_screen.dart';
|
||||
import 'package:prosappco/utils/time_of_day_extension.dart';
|
||||
import 'package:prosappco/utils/time_of_day_utils.dart';
|
||||
import 'package:service_repository/service_repository.dart';
|
||||
import 'package:table_calendar/table_calendar.dart';
|
||||
@@ -44,6 +45,7 @@ class _ProfessionalCalendarScreenState
|
||||
List<ServiceEntity>? _services;
|
||||
CalendarFormat _calendarFormat = CalendarFormat.month;
|
||||
bool isLoading = false;
|
||||
bool _loadFailed = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -54,9 +56,17 @@ class _ProfessionalCalendarScreenState
|
||||
}
|
||||
|
||||
void _loadServices() {
|
||||
setState(() => _loadFailed = false);
|
||||
serviceRepository
|
||||
.getServicesForProfessionalforCalendar(widget.userProfessional.id)
|
||||
.then((services) => setState(() => _services = services));
|
||||
.then((services) {
|
||||
if (!mounted) return;
|
||||
setState(() => _services = services);
|
||||
}).catchError((e) {
|
||||
if (!mounted) return;
|
||||
// Never fall back to an empty list: booked slots would render as free.
|
||||
setState(() => _loadFailed = true);
|
||||
});
|
||||
}
|
||||
|
||||
void _onDaySelected(DateTime day, DateTime focusedDay) {
|
||||
@@ -87,18 +97,33 @@ class _ProfessionalCalendarScreenState
|
||||
child: BlocConsumer<ServiceBloc, ServiceState>(
|
||||
listener: (context, state) {
|
||||
if (state is CreateServiceLoading) isLoading = true;
|
||||
if (state is CreateServiceFailure) isLoading = false;
|
||||
if (state is CreateServiceFailure) {
|
||||
isLoading = false;
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('No se pudo completar la acción')),
|
||||
);
|
||||
}
|
||||
if (state is CreateServiceSuccess || state is ServiceStatusUpdated) {
|
||||
isLoading = false;
|
||||
_loadServices();
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
return ListView(
|
||||
padding: const EdgeInsets.only(bottom: 32),
|
||||
children: [
|
||||
_calendarCard(context),
|
||||
_dayHeader(context, schedule, slots.length, occupied, available),
|
||||
if (slots.isEmpty)
|
||||
_emptyState(context)
|
||||
else
|
||||
..._slotCards(context, slots, state),
|
||||
if (_loadFailed)
|
||||
_loadErrorState(context)
|
||||
else ...[
|
||||
_dayHeader(
|
||||
context, schedule, slots.length, occupied, available),
|
||||
if (slots.isEmpty)
|
||||
_emptyState(context)
|
||||
else
|
||||
..._slotCards(context, slots, state),
|
||||
],
|
||||
],
|
||||
);
|
||||
},
|
||||
@@ -337,9 +362,7 @@ class _ProfessionalCalendarScreenState
|
||||
for (final event in _services!) {
|
||||
if (today.toString() == event.day && time == event.range1Hour1) {
|
||||
if (event.userId == event.professionalId) {
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(const SnackBar(content: Text('Horario ocupado por ti')));
|
||||
_confirmUnblock(event.id!, time);
|
||||
} else {
|
||||
Navigator.push(
|
||||
context,
|
||||
@@ -353,6 +376,35 @@ class _ProfessionalCalendarScreenState
|
||||
}
|
||||
}
|
||||
|
||||
void _confirmUnblock(String serviceId, TimeOfDay time) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (dialogContext) => AlertDialog(
|
||||
title: const Text('Desbloquear horario'),
|
||||
content: Text(
|
||||
'¿Quieres liberar el horario de las '
|
||||
'${ScheduleEntity.getFormatTime(time)} '
|
||||
'del ${DateFormat('dd-MM-yyyy').format(today)}?',
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialogContext),
|
||||
child: const Text('Cancelar'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(dialogContext);
|
||||
context
|
||||
.read<ServiceBloc>()
|
||||
.add(UpdateServiceStatus(serviceId, ServiceStatus.cancelled));
|
||||
},
|
||||
child: const Text('Desbloquear'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _onAvailable(BuildContext context, TimeOfDay time, ServiceState state) {
|
||||
showDialog(
|
||||
context: context,
|
||||
@@ -387,7 +439,8 @@ class _ProfessionalCalendarScreenState
|
||||
createdAt: DateTime.now().toIso8601String(),
|
||||
description: '',
|
||||
range1Hour1: time,
|
||||
range1Hour2: time.replacing(hour: time.hour + 2),
|
||||
range1Hour2: time.add(
|
||||
minute: widget.userProfessional.slotDurationMinutes),
|
||||
rate: '0',
|
||||
location: ServiceLocationPreferences.office,
|
||||
status: ServiceStatus.selfBooked,
|
||||
@@ -395,11 +448,61 @@ class _ProfessionalCalendarScreenState
|
||||
},
|
||||
child: const Text('Reservar'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(dialogContext);
|
||||
context.read<ServiceBloc>().add(
|
||||
BlockSlot(day: today.toString(), hour1: time),
|
||||
);
|
||||
},
|
||||
child: const Text('Bloquear horario'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _loadErrorState(BuildContext context) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.fromLTRB(16, 12, 16, 0),
|
||||
padding: const EdgeInsets.symmetric(vertical: 40, horizontal: 24),
|
||||
decoration: BoxDecoration(
|
||||
color: context.card,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: context.shadowSm,
|
||||
blurRadius: 12,
|
||||
offset: const Offset(0, 2))
|
||||
],
|
||||
),
|
||||
child: Column(children: [
|
||||
Container(
|
||||
width: 64,
|
||||
height: 64,
|
||||
decoration: BoxDecoration(
|
||||
color: _kOccupied.withOpacity(0.1), shape: BoxShape.circle),
|
||||
child: const Icon(Icons.wifi_off_outlined,
|
||||
size: 32, color: _kOccupied),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text('No se pudo cargar tu agenda',
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: context.muted)),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
'No mostramos horarios para evitar que reserves\nsobre una cita ya agendada.',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(fontSize: 13, color: context.subtle, height: 1.5)),
|
||||
const SizedBox(height: 16),
|
||||
OutlinedButton(
|
||||
onPressed: _loadServices, child: const Text('Reintentar')),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _emptyState(BuildContext context) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.fromLTRB(16, 12, 16, 0),
|
||||
@@ -451,13 +554,17 @@ class _ProfessionalCalendarScreenState
|
||||
if (s == null || !s.enabled || s.range1Hour1 == null || s.range2Hour2 == null) {
|
||||
return [];
|
||||
}
|
||||
final stepMinutes = widget.userProfessional.slotDurationMinutes;
|
||||
if (s.continuousDay) {
|
||||
return TimeOfDayUtils.genRanges(s.range1Hour1!, s.range2Hour2!);
|
||||
return TimeOfDayUtils.genRanges(s.range1Hour1!, s.range2Hour2!,
|
||||
stepMinutes: stepMinutes);
|
||||
}
|
||||
if (s.range1Hour2 == null || s.range2Hour1 == null) return [];
|
||||
return [
|
||||
...TimeOfDayUtils.genRanges(s.range1Hour1!, s.range1Hour2!),
|
||||
...TimeOfDayUtils.genRanges(s.range2Hour1!, s.range2Hour2!),
|
||||
...TimeOfDayUtils.genRanges(s.range1Hour1!, s.range1Hour2!,
|
||||
stepMinutes: stepMinutes),
|
||||
...TimeOfDayUtils.genRanges(s.range2Hour1!, s.range2Hour2!,
|
||||
stepMinutes: stepMinutes),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -1,101 +1,225 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:injector/injector.dart';
|
||||
import 'package:prosappco/blocs/authentication_bloc/authentication_bloc.dart';
|
||||
import 'package:prosappco/blocs/my_user_bloc/my_user_bloc.dart';
|
||||
import 'package:prosappco/blocs/professional_bloc/professional_bloc.dart';
|
||||
import 'package:prosappco/screens/professional/professional_form_screen.dart';
|
||||
import 'package:setting_repository/setting_repository.dart';
|
||||
|
||||
class ProfessionalDeniedScreen extends StatelessWidget {
|
||||
class ProfessionalDeniedScreen extends StatefulWidget {
|
||||
const ProfessionalDeniedScreen({super.key});
|
||||
|
||||
@override
|
||||
State<ProfessionalDeniedScreen> createState() =>
|
||||
_ProfessionalDeniedScreenState();
|
||||
}
|
||||
|
||||
class _ProfessionalDeniedScreenState extends State<ProfessionalDeniedScreen> {
|
||||
final settingRepository = Injector.appInstance.get<SettingRepository>();
|
||||
SettingEntity? _settings;
|
||||
bool _loadingSettings = true;
|
||||
bool _isResetting = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
settingRepository.getSettings().then((value) {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_settings = value;
|
||||
_loadingSettings = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void _confirmRetry() {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (dialogContext) => AlertDialog(
|
||||
title: const Text('Volver a registrarme'),
|
||||
content: const Text(
|
||||
'Esta acción reiniciará tu solicitud de profesional y no se puede deshacer. '
|
||||
'¿Deseas continuar?',
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialogContext),
|
||||
child: const Text('Cancelar'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(dialogContext);
|
||||
context
|
||||
.read<ProfessionalBloc>()
|
||||
.add(const ResetProfessionalApplicationEvent());
|
||||
},
|
||||
child: const Text('Continuar'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 28, vertical: 40),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
width: 88,
|
||||
height: 88,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFFFEBEE),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(Icons.cancel_outlined, color: Color(0xFFE53935), size: 48),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
const Text(
|
||||
'Solicitud rechazada',
|
||||
style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold, color: Color(0xFF1A1A2E)),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
const Text(
|
||||
'Tu solicitud para convertirte en profesional no fue aprobada. Esto puede deberse a información incompleta o documentación no válida.',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(fontSize: 14, color: Colors.grey, height: 1.5),
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFFFF3E0),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: const Color(0xFFFFCC02).withOpacity(0.4)),
|
||||
),
|
||||
return BlocListener<ProfessionalBloc, ProfessionalState>(
|
||||
listener: (context, state) {
|
||||
if (state is ResetProfessionalApplicationLoading) {
|
||||
setState(() => _isResetting = true);
|
||||
} else if (state is ResetProfessionalApplicationSuccess) {
|
||||
setState(() => _isResetting = false);
|
||||
Navigator.of(context).pushReplacement(
|
||||
CupertinoPageRoute(builder: (_) => const ProfessionalFormScreen()),
|
||||
);
|
||||
} else if (state is ProfessionalStateFailure) {
|
||||
setState(() => _isResetting = false);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('No se pudo reiniciar la solicitud')),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: BlocBuilder<MyUserBloc, MyUserState>(
|
||||
builder: (context, myUserState) {
|
||||
final rejectedAt = myUserState.user?.rejectedAt;
|
||||
// Backend currently ships rejection_wait_days = 0 (no cooldown).
|
||||
// 7 is only the fallback when /settings could not be read.
|
||||
final waitDays = _settings?.rejectionWaitDays?.toInt() ?? 7;
|
||||
|
||||
// Fail-open, same as the web: if we cannot tell when the rejection
|
||||
// happened, assume the wait already elapsed. Locking someone out of
|
||||
// re-applying forever is worse than letting them retry early.
|
||||
final daysElapsed = rejectedAt != null
|
||||
? DateTime.now().difference(rejectedAt).inDays
|
||||
: waitDays;
|
||||
|
||||
final daysLeft = (waitDays - daysElapsed).clamp(0, waitDays);
|
||||
final canRetry = !_loadingSettings && daysLeft == 0;
|
||||
|
||||
return Scaffold(
|
||||
body: SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 28, vertical: 40),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: const [
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.info_outline, color: Color(0xFFF57C00), size: 20),
|
||||
SizedBox(width: 8),
|
||||
Text('¿Qué puedo hacer?', style: TextStyle(fontWeight: FontWeight.w600, color: Color(0xFFF57C00))),
|
||||
],
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
width: 88,
|
||||
height: 88,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFFFEBEE),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(Icons.cancel_outlined,
|
||||
color: Color(0xFFE53935), size: 48),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
const Text(
|
||||
'Solicitud rechazada',
|
||||
style: TextStyle(
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Color(0xFF1A1A2E)),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
const Text(
|
||||
'Tu solicitud para convertirte en profesional no fue aprobada. Esto puede deberse a información incompleta o documentación no válida.',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(fontSize: 14, color: Colors.grey, height: 1.5),
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFFFF3E0),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(
|
||||
color: const Color(0xFFFFCC02).withOpacity(0.4)),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: const [
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.info_outline,
|
||||
color: Color(0xFFF57C00), size: 20),
|
||||
SizedBox(width: 8),
|
||||
Text('¿Qué puedo hacer?',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFFF57C00))),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 12),
|
||||
_BulletPoint(text: 'Verifica que todos tus datos sean correctos'),
|
||||
_BulletPoint(
|
||||
text: 'Asegúrate de haber adjuntado los documentos requeridos'),
|
||||
_BulletPoint(
|
||||
text: 'Vuelve a registrarte como profesional con la información actualizada'),
|
||||
_BulletPoint(text: 'Contacta a soporte si crees que fue un error'),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton.icon(
|
||||
onPressed: (canRetry && !_isResetting) ? _confirmRetry : null,
|
||||
icon: _isResetting
|
||||
? const SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2, color: Colors.white),
|
||||
)
|
||||
: const Icon(Icons.refresh),
|
||||
label: const Text('Volver a registrarme'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF42A4EF),
|
||||
foregroundColor: Colors.white,
|
||||
disabledBackgroundColor: Colors.grey.shade300,
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12)),
|
||||
elevation: 0,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (!canRetry && !_loadingSettings) ...[
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'Podrás volver a intentarlo en $daysLeft día${daysLeft == 1 ? '' : 's'}',
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(fontSize: 12, color: Colors.grey),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 12),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: () => context
|
||||
.read<AuthenticationBloc>()
|
||||
.add(AuthenticationLogoutRequested()),
|
||||
icon: const Icon(Icons.logout),
|
||||
label: const Text('Cerrar sesión'),
|
||||
style: OutlinedButton.styleFrom(
|
||||
foregroundColor: Colors.grey,
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12)),
|
||||
side: const BorderSide(color: Colors.grey),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 12),
|
||||
_BulletPoint(text: 'Verifica que todos tus datos sean correctos'),
|
||||
_BulletPoint(text: 'Asegúrate de haber adjuntado los documentos requeridos'),
|
||||
_BulletPoint(text: 'Vuelve a registrarte como profesional con la información actualizada'),
|
||||
_BulletPoint(text: 'Contacta a soporte si crees que fue un error'),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton.icon(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
icon: const Icon(Icons.refresh),
|
||||
label: const Text('Volver a registrarme'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF42A4EF),
|
||||
foregroundColor: Colors.white,
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
elevation: 0,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: () => context.read<AuthenticationBloc>().add(AuthenticationLogoutRequested()),
|
||||
icon: const Icon(Icons.logout),
|
||||
label: const Text('Cerrar sesión'),
|
||||
style: OutlinedButton.styleFrom(
|
||||
foregroundColor: Colors.grey,
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
side: const BorderSide(color: Colors.grey),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ class _ProfessionalFormScreenState extends State<ProfessionalFormScreen> {
|
||||
PlatformFile? _certificadoPdfFile;
|
||||
List<PlatformFile>? _especializacionesPdfFiles = [];
|
||||
|
||||
bool _isSubmitting = false;
|
||||
|
||||
late final AuthBloc authBloc;
|
||||
|
||||
@override
|
||||
@@ -50,7 +52,37 @@ class _ProfessionalFormScreenState extends State<ProfessionalFormScreen> {
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider<AuthBloc>(
|
||||
create: (context) => authBloc,
|
||||
child: Scaffold(
|
||||
child: BlocListener<ProfessionalBloc, ProfessionalState>(
|
||||
listener: (context, professionalState) {
|
||||
if (professionalState is SendProfessionalToReviewLoading) {
|
||||
setState(() => _isSubmitting = true);
|
||||
} else if (professionalState is SendProfessionalToReviewSuccess) {
|
||||
setState(() => _isSubmitting = false);
|
||||
|
||||
// The picture upload only runs once the application actually landed.
|
||||
final user = context.read<MyUserBloc>().state.user;
|
||||
if (user != null) {
|
||||
context.read<ProfileBloc>().add(UpdateUserInfo(
|
||||
myUser: user.copyWith(proState: ProState.pending),
|
||||
filePicture: _imageFile?.path));
|
||||
}
|
||||
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Información enviada a revisión')),
|
||||
);
|
||||
Navigator.pop(context);
|
||||
} else if (professionalState is SendProfessionalToReviewFailure) {
|
||||
setState(() => _isSubmitting = false);
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text(
|
||||
'No se pudo enviar tu solicitud. Revisa tu conexión e inténtalo de nuevo.')),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Perfil profesional'),
|
||||
),
|
||||
@@ -247,9 +279,20 @@ class _ProfessionalFormScreenState extends State<ProfessionalFormScreen> {
|
||||
horizontal: 15,
|
||||
),
|
||||
child: FilledButton(
|
||||
onPressed: () {
|
||||
onPressed: _isSubmitting
|
||||
? null
|
||||
: () {
|
||||
final userId =
|
||||
context.read<MyUserBloc>().state.user!.id;
|
||||
context.read<MyUserBloc>().state.user?.id;
|
||||
|
||||
if (userId == null) {
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text(
|
||||
'No se pudo identificar tu usuario, vuelve a iniciar sesión')));
|
||||
return;
|
||||
}
|
||||
|
||||
final String? cedulaPdfPath = _cedulaPdfFile?.path;
|
||||
final String? certificadoPdfPath =
|
||||
@@ -300,20 +343,6 @@ class _ProfessionalFormScreenState extends State<ProfessionalFormScreen> {
|
||||
specializationsPictures:
|
||||
especializacionesPdfPaths,
|
||||
));
|
||||
|
||||
final myUser =
|
||||
state.user!.copyWith(proState: ProState.pending);
|
||||
|
||||
context.read<ProfileBloc>().add(UpdateUserInfo(
|
||||
myUser: myUser, filePicture: _imageFile?.path));
|
||||
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Información enviada a revisión')),
|
||||
);
|
||||
|
||||
Navigator.pop(context);
|
||||
},
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||
@@ -325,19 +354,27 @@ class _ProfessionalFormScreenState extends State<ProfessionalFormScreen> {
|
||||
child: Container(
|
||||
alignment: Alignment.center,
|
||||
width: double.infinity,
|
||||
child: const Text(
|
||||
'Enviar a revisión',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
),
|
||||
),
|
||||
child: _isSubmitting
|
||||
? const SizedBox(
|
||||
height: 22,
|
||||
width: 22,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2, color: Colors.white),
|
||||
)
|
||||
: const Text(
|
||||
'Enviar a revisión',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
),
|
||||
),
|
||||
),
|
||||
)),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -51,7 +51,9 @@ class _ProfessionalProfileScreenState
|
||||
final _rateController = TextEditingController();
|
||||
|
||||
Schedules schedules = Schedules.empty;
|
||||
int _slotDurationMinutes = 120;
|
||||
bool isInit = false;
|
||||
bool _isSaving = false;
|
||||
|
||||
double _longitudeController = 0;
|
||||
double _latitudeController = 0;
|
||||
@@ -78,7 +80,28 @@ class _ProfessionalProfileScreenState
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
return BlocListener<ProfessionalProfileBloc, ProfessionalProfileState>(
|
||||
listener: (context, saveState) {
|
||||
if (saveState is UpdateProfessionalInfoLoading) {
|
||||
setState(() => _isSaving = true);
|
||||
} else if (saveState is UpdateProfessionalInfoSuccess) {
|
||||
setState(() => _isSaving = false);
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Información actualizada correctamente')),
|
||||
);
|
||||
} else if (saveState is UpdateProfessionalInfoFailure) {
|
||||
setState(() => _isSaving = false);
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text(
|
||||
'No se pudo guardar. Revisa tu conexión e inténtalo de nuevo.')),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Scaffold(
|
||||
backgroundColor: context.bg,
|
||||
appBar: AppBar(
|
||||
title: const Text('Perfil Profesional'),
|
||||
@@ -102,9 +125,32 @@ class _ProfessionalProfileScreenState
|
||||
);
|
||||
}
|
||||
}
|
||||
if (state is ProfessionalStateFailure) {
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.error_outline, size: 40, color: context.subtle),
|
||||
const SizedBox(height: 12),
|
||||
const Text('No se pudo cargar tu perfil profesional'),
|
||||
const SizedBox(height: 16),
|
||||
OutlinedButton(
|
||||
onPressed: () => context
|
||||
.read<ProfessionalBloc>()
|
||||
.add(const UpdateProfessionalEvent(isProModeActive: true)),
|
||||
child: const Text('Reintentar'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return const Center(child: Text('Vuelve atrás'));
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -128,6 +174,7 @@ class _ProfessionalProfileScreenState
|
||||
deliveryValue = true;
|
||||
}
|
||||
_rateController.text = proInfo.rate;
|
||||
_slotDurationMinutes = proInfo.slotDurationMinutes;
|
||||
loadFinish = true;
|
||||
}
|
||||
|
||||
@@ -261,23 +308,39 @@ class _ProfessionalProfileScreenState
|
||||
color: _kPrimary)),
|
||||
),
|
||||
),
|
||||
child: _scheduleRows(context),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_slotDurationDropdown(context),
|
||||
const SizedBox(height: 8),
|
||||
_scheduleRows(context),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: ElevatedButton(
|
||||
onPressed: _save,
|
||||
onPressed: _isSaving ? null : _save,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: _kPrimary,
|
||||
foregroundColor: Colors.white,
|
||||
disabledBackgroundColor: _kPrimary.withOpacity(0.5),
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12)),
|
||||
elevation: 0,
|
||||
),
|
||||
child: const Text('Guardar cambios',
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w700)),
|
||||
child: _isSaving
|
||||
? const SizedBox(
|
||||
height: 20,
|
||||
width: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2, color: Colors.white),
|
||||
)
|
||||
: const Text('Guardar cambios',
|
||||
style:
|
||||
TextStyle(fontSize: 16, fontWeight: FontWeight.w700)),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
@@ -481,6 +544,37 @@ class _ProfessionalProfileScreenState
|
||||
]);
|
||||
}
|
||||
|
||||
Widget _slotDurationDropdown(BuildContext context) {
|
||||
const options = [15, 20, 30, 45, 60, 90, 120];
|
||||
final value = options.contains(_slotDurationMinutes)
|
||||
? _slotDurationMinutes
|
||||
: 120;
|
||||
return DropdownButtonFormField<int>(
|
||||
value: value,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Duración de cada cita',
|
||||
prefixIcon: Icon(Icons.timer_outlined, color: context.muted),
|
||||
filled: true,
|
||||
fillColor: context.isDark
|
||||
? Colors.white.withOpacity(0.05)
|
||||
: Colors.black.withOpacity(0.04),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
),
|
||||
items: options
|
||||
.map((m) => DropdownMenuItem(
|
||||
value: m,
|
||||
child: Text(m < 60 ? '$m min' : '${m ~/ 60}h${m % 60 == 0 ? '' : ' ${m % 60}min'}'),
|
||||
))
|
||||
.toList(),
|
||||
onChanged: (v) {
|
||||
if (v != null) setState(() => _slotDurationMinutes = v);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _scheduleRows(BuildContext context) {
|
||||
final days = <_DayEntry>[
|
||||
_DayEntry('Lunes', schedules.monday),
|
||||
@@ -585,14 +679,12 @@ class _ProfessionalProfileScreenState
|
||||
schedules: schedules,
|
||||
ratePreferences: rateValue,
|
||||
rate: _rateController.text,
|
||||
slotDurationMinutes: _slotDurationMinutes,
|
||||
));
|
||||
context.read<ProfessionalProfileBloc>().add(
|
||||
UpdateProfessionalBannerInfo(fileBanner: _imageFile?.path));
|
||||
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Información actualizada correctamente')),
|
||||
);
|
||||
if (_imageFile != null) {
|
||||
context.read<ProfessionalProfileBloc>().add(
|
||||
UpdateProfessionalBannerInfo(fileBanner: _imageFile!.path));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user