fix: repair the booking flow end to end
ci-651288 / run (push) Waiting to run
ci-946620 / run (push) Waiting to run

Verified the real contracts against the backend before changing anything.

Chat (three defects, one root cause):
- every chat endpoint is keyed by the chat id, not the service id. The app
  called POST /chat/start, threw away the id it returned and kept using the
  service id, so every later request 404'd.
- messages arrive as {data, meta}; reading the body as a bare list threw and
  surfaced as an empty conversation.
- the bloc created the chat and then never emitted ChatLoaded (the else hung
  off `if (chat == null)`), leaving a permanent spinner. Sending a message
  emitted nothing at all, so it vanished until reopening.
Messages now render optimistically and roll back if the send fails, and the
screen distinguishes "loading" from "could not open" with a retry.

Appointments:
- a null range1_hour2 parsed as 00:00, so new appointments were born
  "Caducado" and every action was hidden. It now falls back to the start time.
- service requests validate the HTTP status and tolerate an empty body: a 4xx
  was treated as success and a 204 as failure.
- creating a service with no id in the response no longer reports success and
  navigates to a service that does not exist.
- dispatching LoadService from build() looped forever on failure; the three
  detail screens now load once and offer a retry.

Ratings:
- both sides read userScored, so only one of the two could ever rate. The
  client side now reads professionalScored.
- the screen closed before the request finished, killing the provider mid
  flight while addComment swallowed every error. It now waits for confirmation.
- score/reputation parsing tolerates integers and numeric strings instead of
  emptying the review list.

Also: guarded map lookups in ScoreBloc, a nullable name in the search list,
and error states with retry where a failure used to shimmer forever.

Verified against the backend: `accepted` is the status the API expects, so the
suspected spelling bug was a false alarm and was left alone.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-08-24 20:47:54 -05:00
co-authored by Claude Opus 5
parent 8c6e2ae024
commit 389f876cfa
17 changed files with 444 additions and 153 deletions
+33 -8
View File
@@ -57,7 +57,8 @@ class _UserServiceScreenState extends State<UserServiceScreen> {
@override
Widget build(BuildContext context) {
return BlocProvider<ServiceBloc>(
create: (context) => Injector.appInstance.get<ServiceBloc>(),
create: (context) => Injector.appInstance.get<ServiceBloc>()
..add(LoadService(widget.serviceId)),
child: Scaffold(
appBar: AppBar(
title: const Text('Servicio'),
@@ -275,12 +276,10 @@ class _UserServiceScreenState extends State<UserServiceScreen> {
}
},
);
} else if (state is CreateServiceFailure) {
return _loadErrorState(context);
} else {
BlocProvider.of<ServiceBloc>(context)
.add(LoadService(widget.serviceId));
return const Center(
child: CircularProgressIndicator(),
);
return const Center(child: CircularProgressIndicator());
}
},
),
@@ -288,6 +287,32 @@ class _UserServiceScreenState extends State<UserServiceScreen> {
);
}
/// Dispatching LoadService from build() turned any failure into an endless
/// request loop: fail -> rebuild -> request -> fail. Errors now get an
/// explicit retry instead of a permanent spinner.
Widget _loadErrorState(BuildContext context) {
return Center(
child: Padding(
padding: const EdgeInsets.all(24),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(Icons.error_outline, size: 40, color: Colors.grey),
const SizedBox(height: 12),
const Text('No se pudo cargar el servicio',
textAlign: TextAlign.center),
const SizedBox(height: 16),
OutlinedButton(
onPressed: () => BlocProvider.of<ServiceBloc>(context)
.add(LoadService(widget.serviceId)),
child: const Text('Reintentar'),
),
],
),
),
);
}
Widget customMessageStatus(ServiceEntity service) {
DateTime serviceDate = DateTime.parse(service.day);
DateTime now = DateTime.now();
@@ -404,7 +429,7 @@ class _UserServiceScreenState extends State<UserServiceScreen> {
}
if (service.status == ServiceStatus.completed &&
service.userScored == false) {
service.professionalScored == false) {
return Stack(
alignment: AlignmentDirectional.topCenter,
clipBehavior: Clip.none,
@@ -479,7 +504,7 @@ class _UserServiceScreenState extends State<UserServiceScreen> {
}
if (service.status == ServiceStatus.completed &&
service.userScored == true) {
service.professionalScored == true) {
return Stack(
alignment: AlignmentDirectional.topCenter,
clipBehavior: Clip.none,