sync changes
This commit is contained in:
@@ -667,8 +667,22 @@ class ApiService {
|
||||
|
||||
return ScooterOrder.fromJson(response.data);
|
||||
} on DioException catch (e) {
|
||||
_handleDioError(e);
|
||||
return null;
|
||||
if (e.response?.statusCode == 400) {
|
||||
final data = e.response?.data;
|
||||
|
||||
if (data is Map && data['message'] is List) {
|
||||
final firstError = data['message'][0]['message'].toString();
|
||||
|
||||
if (firstError.contains("Wrong start zone")) {
|
||||
throw WrongZoneException(message: "Некорректная зона для начала поездки.");
|
||||
}
|
||||
}
|
||||
|
||||
if (data is Map && data['message'] is String) {}
|
||||
} else {
|
||||
_handleDioError(e);
|
||||
}
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -684,8 +698,22 @@ class ApiService {
|
||||
}
|
||||
return null;
|
||||
} on DioException catch (e) {
|
||||
_handleDioError(e);
|
||||
return null;
|
||||
if (e.response?.statusCode == 400) {
|
||||
final data = e.response?.data;
|
||||
|
||||
if (data is Map && data['message'] is List) {
|
||||
final firstError = data['message'][0]['message'].toString();
|
||||
|
||||
if (firstError.contains("Wrong start zone")) {
|
||||
throw WrongZoneException(message: "Некорректная зона для начала поездки.");
|
||||
}
|
||||
}
|
||||
|
||||
if (data is Map && data['message'] is String) {}
|
||||
} else {
|
||||
_handleDioError(e);
|
||||
}
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -762,8 +790,8 @@ class ApiService {
|
||||
if (data is Map && data['message'] is List) {
|
||||
final firstError = data['message'][0]['message'].toString();
|
||||
|
||||
if (firstError.contains("Wrong zone")) {
|
||||
throw WrongZoneException(message: firstError);
|
||||
if (firstError.contains("Wrong start zone")) {
|
||||
throw WrongZoneException(message: "Некорректная зона для завершения поездки.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -55,32 +55,47 @@ class GeocodingRemoteDataSource {
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<MasstransitRoute>?> getPedestrianRoutes(Point userPosition,
|
||||
Point targetPosition) async {
|
||||
final (session, resultFuture) = await YandexPedestrian.requestRoutes(
|
||||
points: [
|
||||
RequestPoint(
|
||||
point: userPosition, requestPointType: RequestPointType.wayPoint),
|
||||
RequestPoint(point: targetPosition,
|
||||
requestPointType: RequestPointType.wayPoint)
|
||||
],
|
||||
fitnessOptions: FitnessOptions(avoidSteep: false, avoidStairs: false),
|
||||
timeOptions: TimeOptions()
|
||||
);
|
||||
|
||||
Future<List<MasstransitRoute>?> getPedestrianRoutes(
|
||||
Point userPosition,
|
||||
Point targetPosition,
|
||||
) async {
|
||||
try {
|
||||
|
||||
print("From: ${userPosition.latitude}, ${userPosition.longitude}");
|
||||
print("To: ${targetPosition.latitude}, ${targetPosition.longitude}");
|
||||
|
||||
final (session, resultFuture) = await YandexPedestrian.requestRoutes(
|
||||
points: [
|
||||
RequestPoint(point: userPosition, requestPointType: RequestPointType.wayPoint),
|
||||
RequestPoint(point: targetPosition, requestPointType: RequestPointType.wayPoint)
|
||||
],
|
||||
fitnessOptions: const FitnessOptions(avoidSteep: false, avoidStairs: false),
|
||||
timeOptions: const TimeOptions()
|
||||
);
|
||||
|
||||
final result = await resultFuture;
|
||||
|
||||
final distance = result.routes?.first.metadata.weight.walkingDistance.value;
|
||||
if (result.routes == null || result.routes!.isEmpty) {
|
||||
print("Маршруты не найдены: список пуст или null");
|
||||
return [];
|
||||
}
|
||||
|
||||
print("Дистанция до самоката: $distance");
|
||||
final route = result.routes!.first;
|
||||
|
||||
final distance = route.metadata.weight.walkingDistance?.value;
|
||||
|
||||
if (distance != null) {
|
||||
print("Дистанция до самоката: $distance м");
|
||||
} else {
|
||||
print("Дистанция не найдена в метаданных маршрута");
|
||||
}
|
||||
|
||||
return result.routes;
|
||||
|
||||
} catch (e) {
|
||||
print('Error: $e');
|
||||
} catch (e, stack) {
|
||||
print('Pedestrian route error: $e');
|
||||
print('Stack trace: $stack');
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user