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:
Lizandro Guarnizo
2026-08-24 16:45:42 -05:00
co-authored by Claude Opus 5
parent 06a89df690
commit 8631e6f729
86 changed files with 5470 additions and 5291 deletions
@@ -1,3 +1,5 @@
import 'dart:math' as math;
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:professional_repository/professional_repository.dart';
@@ -24,27 +26,76 @@ class ProfessionalListBloc
emit(ProfessionalListLoading());
final users = await _userRepository.getUsersProfessionalActive();
final professionals =
await _firebaseProfessionalRepository.getProfessionalInfo();
final hasSearchParams = event.search != null ||
event.city != null ||
event.lat != null ||
event.lng != null;
final professionalInfoMap = {for (var doc in professionals) doc.id: doc};
if (!hasSearchParams) {
final professionals =
await _firebaseProfessionalRepository.getProfessionalInfo();
final usersMap = users
.map((user) => UserProfessional(
myUser: user,
professionalInfo: professionalInfoMap[user.id]!,
final professionalInfoMap = {for (var doc in professionals) doc.id: doc};
final usersMap = users
.where((user) => professionalInfoMap.containsKey(user.id))
.map((user) => UserProfessional(
myUser: user,
professionalInfo: professionalInfoMap[user.id]!,
))
.toList();
emit(ProfessionalListSuccess(users: usersMap));
return;
}
final usersDir = {for (var u in users) u.id: u};
final professionals = await _firebaseProfessionalRepository.searchProfessionals(
search: event.search,
city: event.city,
lat: event.lat,
lng: event.lng,
);
final usersMap = professionals
.where((p) => usersDir.containsKey(p.id))
.map((p) => UserProfessional(
myUser: usersDir[p.id]!,
professionalInfo: p,
distanceKm: (event.lat != null && event.lng != null)
? _haversineKm(event.lat!, event.lng!, p.latitude, p.longitude)
: null,
))
.toList();
emit(ProfessionalListSuccess(users: usersMap));
}
double? _haversineKm(double lat1, double lng1, double lat2, double lng2) {
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));
}
}
class UserProfessional {
final MyUser myUser;
final ProfessionalEntity professionalInfo;
final double? distanceKm;
UserProfessional({required this.myUser, required this.professionalInfo});
UserProfessional({
required this.myUser,
required this.professionalInfo,
this.distanceKm,
});
@override
String toString() {
@@ -8,8 +8,18 @@ abstract class ProfessionalListEvent extends Equatable {
}
class ProfessionalListFetch extends ProfessionalListEvent {
const ProfessionalListFetch();
final String? search;
final String? city;
final double? lat;
final double? lng;
const ProfessionalListFetch({this.search, this.city, this.lat, this.lng});
@override
List<Object> get props => [];
List<Object> get props => [
search ?? '',
city ?? '',
lat ?? 0,
lng ?? 0,
];
}