import 'dart:async'; import 'dart:convert'; import 'package:http/http.dart' as http; import '../../config/const.dart'; import '../../models/map/route/route_response.dart'; import '../../models/utils/api_response.dart'; class RoutesAPI { Future> getRoute(String startLat,String startLon,String endLat,String endLon) async { var statusCode = -1; String start='$startLat,$startLon'; String end='$endLat,$endLon'; final queryParameters = {'destination': start,'origin':end, 'key': apiKey}; return await http.get(Uri.https('maps.googleapis.com', 'maps/api/directions/json', queryParameters), headers: { 'Content-type': 'application/json', 'Accept': 'application/json' }).then((data) async { statusCode = data.statusCode; if (data.statusCode == 200 || data.statusCode == 201) { final jsonData = json.decode(data.body); RouteResponse address = RouteResponse.fromJson(jsonData); return APIResponse(statusCode: statusCode, data: address); } return APIResponse(statusCode: statusCode, errorMessage: 'Please check your info'); }).catchError((e) => APIResponse( statusCode: statusCode, errorMessage: e.toString())); } }