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
@@ -114,11 +114,19 @@ class _ProfessionalListScreenState extends State<ProfessionalListScreen> {
void _loadProfessions() {
professionRepository.getProfessions().then((Professions element) {
if (!mounted) return;
setState(() {
_professions = element.professions;
_filteredProfessions = _professions;
_isLoading = false;
});
}).catchError((e) {
// Without this the shimmer never stopped and the dropdown stayed empty.
if (!mounted) return;
setState(() => _isLoading = false);
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('No se pudieron cargar las profesiones')),
);
});
}
@@ -238,13 +246,33 @@ class _ProfessionalListScreenState extends State<ProfessionalListScreen> {
}
_body(ProfessionalListState state) {
if (state is ProfessionalListFailure) {
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 la lista', textAlign: TextAlign.center),
const SizedBox(height: 16),
OutlinedButton(
onPressed: () => bloc.add(const ProfessionalListFetch()),
child: const Text('Reintentar'),
),
],
),
),
);
}
if (state is ProfessionalListSuccess) {
final List<UserProfessional> filteredUsers;
// TODO: encaso de filtro dañado
// if (_searchController.text.isNotEmpty) {
filteredUsers = state.users
.where((element) => removeDiacritics(element.myUser.name!)
.where((element) => removeDiacritics(element.myUser.name ?? '')
.toLowerCase()
.contains(removeDiacritics(_searchController.text.toLowerCase())))
.where((user) =>