From 360f88777b0e0c194a350081f36a3d19a4b76969 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Sun, 12 Jul 2026 17:42:43 -0500 Subject: [PATCH] fix: add 30s timeout to API calls and catchError fallback on schedule load Without a timeout, a hanging backend request left the schedule page showing an infinite spinner forever. Timeout ensures any hung request fails fast and the spinner resolves. The catchError fallback in schedule_view handles the edge case where getProfessional rejects unexpectedly. Co-Authored-By: Claude Sonnet 4.6 --- lib/services/api_service.dart | 10 ++++++---- lib/ui/views/schedule_view.dart | 3 +++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/services/api_service.dart b/lib/services/api_service.dart index baf4d5e..e7c78da 100644 --- a/lib/services/api_service.dart +++ b/lib/services/api_service.dart @@ -30,8 +30,10 @@ class ApiService { throw Exception(body['message'] ?? 'Error ${res.statusCode}'); } + static const _timeout = Duration(seconds: 30); + Future get(String path) async { - final res = await http.get(Uri.parse('$baseUrl$path'), headers: await _headers()); + final res = await http.get(Uri.parse('$baseUrl$path'), headers: await _headers()).timeout(_timeout); return _parse(res); } @@ -40,7 +42,7 @@ class ApiService { Uri.parse('$baseUrl$path'), headers: await _headers(), body: jsonEncode(body), - ); + ).timeout(_timeout); return _parse(res); } @@ -49,12 +51,12 @@ class ApiService { Uri.parse('$baseUrl$path'), headers: await _headers(), body: jsonEncode(body), - ); + ).timeout(_timeout); return _parse(res); } Future delete(String path) async { - final res = await http.delete(Uri.parse('$baseUrl$path'), headers: await _headers()); + final res = await http.delete(Uri.parse('$baseUrl$path'), headers: await _headers()).timeout(_timeout); return _parse(res); } diff --git a/lib/ui/views/schedule_view.dart b/lib/ui/views/schedule_view.dart index 7e0cec9..d67b211 100644 --- a/lib/ui/views/schedule_view.dart +++ b/lib/ui/views/schedule_view.dart @@ -1,3 +1,4 @@ +import 'package:prosapp_web_app/models/profesional.dart'; import 'package:prosapp_web_app/models/usuario.dart'; import 'package:prosapp_web_app/providers/auth_provider.dart'; import 'package:prosapp_web_app/providers/professional_form_provider.dart'; @@ -39,6 +40,8 @@ class _ScheduleViewState extends State { professionalFormProvider.clear(); proProvider.getProfessional(authProvider.user!.id).then((value) { professionalFormProvider.setProfesional(value); + }).catchError((_) { + professionalFormProvider.setProfesional(Profesional.empty()); }); profileFormProvider.user = authProvider.user;