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
+40
View File
@@ -0,0 +1,40 @@
import 'dart:convert';
import 'package:http/http.dart' as http;
class NominatimGeocoder {
static Future<String?> reverseGeocodeCity(double lat, double lng) async {
final uri = Uri.parse(
'https://nominatim.openstreetmap.org/reverse'
'?format=json&lat=$lat&lon=$lng&zoom=10&addressdetails=1',
);
final res = await http.get(
uri,
headers: {'User-Agent': 'ProsApp/1.0 (prosapp.co)'},
);
final data = jsonDecode(res.body) as Map<String, dynamic>;
final address = data['address'] as Map<String, dynamic>?;
return address?['city'] as String? ??
address?['town'] as String? ??
address?['municipality'] as String? ??
address?['county'] as String?;
}
static Future<(double lat, double lng)?> forwardGeocodeCity(
String cityName) async {
final uri = Uri.parse(
'https://nominatim.openstreetmap.org/search'
'?format=json&limit=1&q=${Uri.encodeQueryComponent(cityName)}',
);
final res = await http.get(
uri,
headers: {'User-Agent': 'ProsApp/1.0 (prosapp.co)'},
);
final data = jsonDecode(res.body) as List;
if (data.isEmpty) return null;
final first = data.first as Map<String, dynamic>;
final lat = double.tryParse(first['lat']?.toString() ?? '');
final lng = double.tryParse(first['lon']?.toString() ?? '');
if (lat == null || lng == null) return null;
return (lat, lng);
}
}
+8 -1
View File
@@ -1,8 +1,15 @@
import 'package:flutter/material.dart';
extension TimeOfDayExtension on TimeOfDay {
/// Adds the given offset, carrying minutes into hours.
///
/// Without the carry, adding a minute-based step (e.g. 45) would leave the
/// hour untouched and produce values like "8:90", which makes [isBefore]
/// loops run forever. The hour is intentionally NOT wrapped at 24 so that
/// comparisons against an end-of-day bound still terminate.
TimeOfDay add({int hour = 0, int minute = 0}) {
return replacing(hour: this.hour + hour, minute: this.minute + minute);
final totalMinutes = (this.hour + hour) * 60 + this.minute + minute;
return TimeOfDay(hour: totalMinutes ~/ 60, minute: totalMinutes % 60);
}
int compareTo(TimeOfDay other) {
+4 -3
View File
@@ -2,13 +2,14 @@ import 'package:flutter/material.dart';
import 'package:prosappco/utils/time_of_day_extension.dart';
class TimeOfDayUtils {
static List<TimeOfDay> genRanges(TimeOfDay timeStart, TimeOfDay timeEnd) {
static List<TimeOfDay> genRanges(TimeOfDay timeStart, TimeOfDay timeEnd,
{int stepMinutes = 30}) {
final step = stepMinutes.clamp(5, 480);
List<TimeOfDay> ranges = [];
TimeOfDay current = timeStart;
while (current.isBefore(timeEnd)) {
ranges.add(current);
// Sumar 2 horas al objeto DateTime
current = current.add(hour: 2);
current = current.add(minute: step);
}
return ranges;
}
+48
View File
@@ -0,0 +1,48 @@
/// Compares dotted numeric versions, e.g. "1.0.14" vs "1.0.2".
///
/// Returns a negative number when [a] is older than [b], 0 when they are
/// equivalent, and a positive number when [a] is newer. Missing segments count
/// as 0, so "1.0" and "1.0.0" are equivalent. Returns null when either side
/// cannot be parsed.
int? compareVersions(String? a, String? b) {
final left = _segments(a);
final right = _segments(b);
if (left == null || right == null) return null;
final length = left.length > right.length ? left.length : right.length;
for (var i = 0; i < length; i++) {
final l = i < left.length ? left[i] : 0;
final r = i < right.length ? right[i] : 0;
if (l != r) return l - r;
}
return 0;
}
/// Whether [current] is strictly older than [minimum].
///
/// Deliberately fails open: a missing or unparseable value returns false, so a
/// backend misconfiguration can never lock users out of the app behind the
/// blocking "you must update" dialog. Equal or newer versions are fine too — a
/// build ahead of the configured minimum is not out of date.
bool isUpdateRequired(String? current, String? minimum) {
final result = compareVersions(current, minimum);
if (result == null) return false;
return result < 0;
}
List<int>? _segments(String? version) {
if (version == null) return null;
final trimmed = version.trim();
if (trimmed.isEmpty) return null;
// Tolerate build suffixes such as "1.0.14+14" or "1.0.14-beta".
final core = trimmed.split(RegExp(r'[+\-]')).first;
final parts = core.split('.');
final segments = <int>[];
for (final part in parts) {
final value = int.tryParse(part.trim());
if (value == null) return null;
segments.add(value);
}
return segments.isEmpty ? null : segments;
}