feat: (broken) implement route map and address autocomplete widgets with associated infrastructure testing scripts

This commit is contained in:
ElPoyo
2026-06-05 11:10:32 +02:00
parent 8c01a21728
commit 21d7bc8b87
40 changed files with 21078 additions and 30 deletions
+17 -4
View File
@@ -15,8 +15,13 @@ List<LatLng> safeDecodePolyline(String encoded) {
result |= (b & 0x1f) << shift;
shift += 5;
} while (b >= 0x20);
int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
// Dart Web bitwise operations (~ and >>) can cause 32-bit unsigned wrap-around
// Using arithmetic avoids the issue where lat becomes 42995.xxxx (offset by 2^32)
int dlat = (result & 1) != 0 ? -((result >> 1) + 1) : (result >> 1);
lat += dlat;
// Correction manuelle au cas où un wrap unsigned 32-bit s'est produit
if (lat > 2147483647) lat -= 4294967296;
shift = 0;
result = 0;
@@ -26,15 +31,23 @@ List<LatLng> safeDecodePolyline(String encoded) {
result |= (b & 0x1f) << shift;
shift += 5;
} while (b >= 0x20);
int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
int dlng = (result & 1) != 0 ? -((result >> 1) + 1) : (result >> 1);
lng += dlng;
if (lng > 2147483647) lng -= 4294967296;
double finalLat = lat / 1e5;
double finalLng = lng / 1e5;
double finalLat = (lat / 1e5).clamp(-90.0, 90.0);
double finalLng = (lng / 1e5).clamp(-180.0, 180.0);
poly.add(LatLng(finalLat, finalLng));
}
return poly;
} catch (e) {
// ignore: avoid_print
print('[POLYLINE] Erreur décodage: $e');
return [];
}
}
@@ -17,7 +17,15 @@ class RouteMapWidget extends StatelessWidget {
});
List<LatLng> _decode(String encoded) {
return safeDecodePolyline(encoded);
final pts = safeDecodePolyline(encoded);
// DEBUG: afficher dans la console du navigateur
// ignore: avoid_print
print('[MAP DEBUG] encoded length=${encoded.length}, decoded ${pts.length} points');
if (pts.isNotEmpty) {
// ignore: avoid_print
print('[MAP DEBUG] first=${pts.first.latitude},${pts.first.longitude} last=${pts.last.latitude},${pts.last.longitude}');
}
return pts;
}
LatLngBounds? _computeBounds(List<List<LatLng>> allPoints) {
@@ -92,15 +92,9 @@ class _AddressAutocompleteFieldState extends State<AddressAutocompleteField> {
separatorBuilder: (_, __) =>
const Divider(height: 1, indent: 16),
itemBuilder: (ctx, i) {
return ListTile(
dense: true,
leading: const Icon(Icons.location_on_outlined, size: 18),
title: Text(
_suggestions[i],
style: const TextStyle(fontSize: 13),
overflow: TextOverflow.ellipsis,
),
onTap: () {
return GestureDetector(
behavior: HitTestBehavior.opaque,
onPanDown: (_) {
widget.controller.text = _suggestions[i];
widget.controller.selection = TextSelection.fromPosition(
TextPosition(offset: _suggestions[i].length),
@@ -109,6 +103,15 @@ class _AddressAutocompleteFieldState extends State<AddressAutocompleteField> {
_removeOverlay();
_focusNode.unfocus();
},
child: ListTile(
dense: true,
leading: const Icon(Icons.location_on_outlined, size: 18),
title: Text(
_suggestions[i],
style: const TextStyle(fontSize: 13),
overflow: TextOverflow.ellipsis,
),
),
);
},
),