2022-05-12 02:17:08 +05:30
import ' dart:convert ' ;
2022-05-24 20:43:41 +05:30
import ' package:flutter_polyline_points/flutter_polyline_points.dart ' ;
2022-09-22 20:36:56 +05:30
import ' package:get/get.dart ' ;
2022-05-24 20:43:41 +05:30
//import 'package:google_maps_webservice/directions.dart';
2022-05-12 02:17:08 +05:30
import ' package:http/http.dart ' as http ;
2022-07-09 22:51:34 +05:30
import ' package:rogapp/model/destination.dart ' ;
2022-09-22 20:36:56 +05:30
import ' package:rogapp/pages/destination/destination_controller.dart ' ;
2022-05-12 02:17:08 +05:30
2022-06-14 14:37:59 +05:30
import ' ../utils/const.dart ' ;
2023-10-06 16:25:21 +05:30
class DestinationService {
static Future < List < dynamic > > getDestinations ( int userId ) async {
2022-05-12 02:17:08 +05:30
List < dynamic > cats = [ ] ;
2023-08-16 14:53:32 +05:30
String serverUrl = ConstValues . currentServer ( ) ;
String url = " $ serverUrl /api/destinations/?user_id= $ userId " ;
2023-10-06 16:25:21 +05:30
//print('++++++++$url');
final http . Response response =
await http . get ( Uri . parse ( url ) , headers: < String , String > {
' Content-Type ' : ' application/json; charset=UTF-8 ' ,
} ) ;
2022-05-12 02:17:08 +05:30
if ( response . statusCode = = 200 ) {
cats = json . decode ( utf8 . decode ( response . bodyBytes ) ) ;
}
return cats ;
}
2023-10-06 16:25:21 +05:30
static Future < Map < String , dynamic > > deleteDestination ( int destId ) async {
2022-05-25 21:00:10 +05:30
Map < String , dynamic > cats = { } ;
2023-08-16 14:53:32 +05:30
String serverUrl = ConstValues . currentServer ( ) ;
String url = " $ serverUrl /api/delete_destination/?dest_id= $ destId " ;
2023-10-06 16:25:21 +05:30
//print('++++++++$url');
final http . Response response =
await http . get ( Uri . parse ( url ) , headers: < String , String > {
' Content-Type ' : ' application/json; charset=UTF-8 ' ,
} ) ;
2022-05-25 21:00:10 +05:30
if ( response . statusCode = = 200 ) {
cats = json . decode ( utf8 . decode ( response . bodyBytes ) ) ;
}
2023-10-06 16:25:21 +05:30
//print("####### ---- $cats");
2022-05-25 21:00:10 +05:30
return cats ;
}
2023-10-06 16:25:21 +05:30
static Future < int > updateOrder ( int actionId , int order , String dir ) async {
2022-05-12 02:17:08 +05:30
int cats = 0 ;
2023-08-16 14:53:32 +05:30
String serverUrl = ConstValues . currentServer ( ) ;
2023-10-06 16:25:21 +05:30
String url =
" $ serverUrl /api/updateorder/?user_action_id= $ actionId &order= $ order &dir= $ dir " ;
//print('++++++++$url');
final http . Response response =
await http . get ( Uri . parse ( url ) , headers: < String , String > {
' Content-Type ' : ' application/json; charset=UTF-8 ' ,
} ) ;
2022-05-12 02:17:08 +05:30
if ( response . statusCode = = 200 ) {
cats = json . decode ( utf8 . decode ( response . bodyBytes ) ) ;
}
return cats ;
}
2023-10-06 16:25:21 +05:30
static Future < List < PointLatLng > > ? getDestinationLine (
List < Destination > destinations , Map < String , dynamic > mtx ) async {
2022-05-24 20:43:41 +05:30
PolylinePoints polylinePoints = PolylinePoints ( ) ;
2022-07-10 23:50:43 +05:30
2023-10-06 16:25:21 +05:30
if ( destinations . isEmpty ) {
2022-07-10 23:50:43 +05:30
return [ ] ;
}
2023-10-06 16:25:21 +05:30
2022-07-10 23:50:43 +05:30
//print("##### @@@@@ ${destinations[0].lat}");
2023-10-06 16:25:21 +05:30
PointLatLng origin =
PointLatLng ( destinations [ 0 ] . lat ! , destinations [ 0 ] . lon ! ) ;
PointLatLng dest = PointLatLng ( destinations [ destinations . length - 1 ] . lat ! ,
destinations [ destinations . length - 1 ] . lon ! ) ;
2022-05-24 20:43:41 +05:30
List < PolylineWayPoint > wayPoints = [ ] ;
2023-10-06 16:25:21 +05:30
int i = 0 ;
for ( dynamic d in destinations ) {
if ( i = = 0 | | i = = ( destinations . length - 1 ) ) {
i + = 1 ;
2022-05-24 20:43:41 +05:30
continue ;
}
2022-07-09 22:51:34 +05:30
double la = d . lat ;
double ln = d . lon ;
2022-09-29 15:32:33 +05:30
int j = 0 ;
2023-10-06 16:25:21 +05:30
PolylineWayPoint pwp =
PolylineWayPoint ( location: " $ la , $ ln " , stopOver: false ) ;
2022-09-29 15:32:33 +05:30
2022-05-24 20:43:41 +05:30
//print("----- UUUUUU ${pwp}");
//PointLatLng wp = PointLatLng(d["Location"]["geometry"][0][1], d["Location"]["geometry"][0][0]);
wayPoints . add ( pwp ) ;
2023-10-06 16:25:21 +05:30
i + = 1 ;
2022-09-29 15:32:33 +05:30
j + = 4 ;
2022-05-24 20:43:41 +05:30
}
2022-09-22 20:36:56 +05:30
2023-10-06 16:25:21 +05:30
final DestinationController destinationController =
Get . find < DestinationController > ( ) ;
// int travMode = destinationController.travelMode.value;
// String mode = "WALKING";
// if (travMode == 1) {
// //_mode = TravelMode.driving;
// mode = "DRIVING";
// } else if (travMode == 2) {
// //_mode = TravelMode.transit;
// mode = "TRANSIT";
// }
2022-09-22 20:36:56 +05:30
2022-05-24 20:43:41 +05:30
//PolylineResult result = await polylinePoints.getRouteBetweenCoordinates("AIzaSyAUBI1ablMKuJwGj2-kSuEhvYxvB1A-mOE", PointLatLng(35.389282, 136.498027), PointLatLng(36.285848, 137.575186));
2023-10-06 16:25:21 +05:30
Map < String , dynamic > pl =
destinationController . matrix [ " routes " ] [ 0 ] [ " overview_polyline " ] ;
2022-09-29 15:32:33 +05:30
List < PointLatLng > result = polylinePoints . decodePolyline ( pl [ " points " ] ) ;
//List<PointLatLng> result = polylinePoints.decodePolyline("qkyvEq`z`Yp@DBMr@XL@Td@Eb@PREd@IFe@rKIzCY|GEvCBzCHvS@xC?HnBHtBHlBFnBFhGRtDVW~BE`@ICHLk@dE_ClPgAtHu@bFsAhPg@~Ge@bFaEtg@kEpi@oCd\\w@nIw@hGe@fBy@nBqAjC{@zBgBtFOd@M@Wv@i@`BQf@ITKCuE`@yDZqBRCHa@DKG_AHwBRiBR_Fp@y@LYBY]M@KJo@v@M@cAGoGN_Cx@}Cf@}@@mM~@qF`@gCLwBj@sBrAeAhAsAtCoF|MmAbD{@fBwAdBw@p@_Ax@BFOHAl@?`@MA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21 +05:30
2022-05-24 20:43:41 +05:30
//print("#####@@@@@ ${result.points}");
2022-09-29 15:32:33 +05:30
return result ;
2022-05-24 20:43:41 +05:30
}
2022-05-12 02:17:08 +05:30
}