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 ' ;
2022-05-12 02:17:08 +05:30
class DestinationService {
static Future < List < dynamic > > getDestinations ( int user_id ) async {
List < dynamic > cats = [ ] ;
2022-06-14 14:37:59 +05:30
String server_url = ConstValues . currentServer ( ) ;
String url = " ${ server_url } /api/destinations/?user_id= ${ user_id } " ;
//String url = "http://localhost:8100/api/destinations/?user_id=${user_id}";
2022-05-12 02:17:08 +05:30
final http . Response response = await http . get (
Uri . parse ( url ) ,
headers: < String , String > {
' Content-Type ' : ' application/json; charset=UTF-8 ' ,
}
) ;
if ( response . statusCode = = 200 ) {
cats = json . decode ( utf8 . decode ( response . bodyBytes ) ) ;
}
return cats ;
}
2022-05-25 21:00:10 +05:30
static Future < Map < String , dynamic > > deleteDestination ( int dest_id ) async {
Map < String , dynamic > cats = { } ;
2022-06-14 14:37:59 +05:30
String server_url = ConstValues . currentServer ( ) ;
String url = " ${ server_url } /api/delete_destination/?dest_id= ${ dest_id } " ;
//String url = "http://localhost:8100/api/delete_destination/?dest_id=${dest_id}";
2022-05-25 21:00:10 +05:30
final http . Response response = await http . get (
Uri . parse ( url ) ,
headers: < String , String > {
' Content-Type ' : ' application/json; charset=UTF-8 ' ,
}
) ;
if ( response . statusCode = = 200 ) {
cats = json . decode ( utf8 . decode ( response . bodyBytes ) ) ;
}
print ( " ####### ---- ${ cats } " ) ;
return cats ;
}
2022-05-12 02:17:08 +05:30
static Future < int > updateOrder ( int action_id , int order , String dir ) async {
int cats = 0 ;
2022-06-14 14:37:59 +05:30
String server_url = ConstValues . currentServer ( ) ;
String url = " ${ server_url } /api/updateorder/?user_action_id= ${ action_id } &order= ${ order } &dir= ${ dir } " ;
2022-07-09 22:51:34 +05:30
print ( " ---- url is ${ url } ----- " ) ;
2022-06-14 14:37:59 +05:30
//String url = "http://localhost:8100/api/updateorder/?user_action_id=${action_id}&order=${order}&dir=${dir}";
2022-05-12 02:17:08 +05:30
final http . Response response = await http . get (
Uri . parse ( url ) ,
headers: < String , String > {
' Content-Type ' : ' application/json; charset=UTF-8 ' ,
}
) ;
if ( response . statusCode = = 200 ) {
cats = json . decode ( utf8 . decode ( response . bodyBytes ) ) ;
}
return cats ;
}
2022-09-29 15:32:33 +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
if ( destinations . length < = 0 ) {
return [ ] ;
}
2022-05-24 20:43:41 +05:30
2022-07-10 23:50:43 +05:30
//print("##### @@@@@ ${destinations[0].lat}");
2022-07-09 22:51:34 +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 = [ ] ;
int i = 0 ;
for ( dynamic d in destinations ) {
if ( i = = 0 | | i = = ( destinations . length - 1 ) ) {
i + = 1 ;
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 ;
PolylineWayPoint pwp = PolylineWayPoint ( location: " ${ la } , ${ ln } " , stopOver: false ) ;
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 ) ;
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
final DestinationController destinationController = Get . find < DestinationController > ( ) ;
int trav_mode = destinationController . travelMode . value ;
2022-09-29 15:32:33 +05:30
String _mode = " WALKING " ;
2022-09-22 20:36:56 +05:30
if ( trav_mode = = 1 ) {
2022-09-29 15:32:33 +05:30
//_mode = TravelMode.driving;
_mode = " DRIVING " ;
2022-09-22 20:36:56 +05:30
}
else if ( trav_mode = = 2 ) {
2022-09-29 15:32:33 +05:30
//_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));
2022-09-29 15:32:33 +05:30
Map < String , dynamic > pl = destinationController . matrix [ " routes " ] [ 0 ] [ " overview_polyline " ] ;
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@?`@MAQCEAOIQSaBx@{Ah@eATsAHSB?d@A`D?f@IdWy@AS??V?|BCJ}@?cA?k@Au@wBqDuKQaACg@z@gELg@GK~@uEp@{A@q@y@CHwFHcG?KDqCDK^ABABEH{AE{B{@_Ho@uFIaBFQhBaC@SQSg@k@g@q@Yw@qA{De@}B]uDCsAMEWDqAFu@@^A@TDjA@vDA`CETK|AEtAIFY@o@ALpBZ~HBlCBn@EDGPu@pASJO`@Qf@?ROr@K?qDLHnEUTsDNkENYB{Ab@I^?zA}CrCkBfBw@t@@LwA`Bo@r@eGvD}BrAGGuAj@[?i@rBVi@P}@T?F?^MxDuBhDsBzAcAn@s@zCgDAI~A{A|CsC?{A?UHItA_@DCXC~J_@TUIoEvDKTm@?Y^iALIb@k@f@aAE}AA_BC{@\\Cv@CxAEj@ExCwDDc@CYFANCh@WHEIIRQhB}B|C_E\\w@Hq@JE?a@O}CGkAIwEGmDEmDAKLA^?A}@C{@?e@E_DFQNi@LcB\\eBPsADGKOEWBOH[GCPs@Pq@\\cANs@^q@jAu@fCqAf@]HCXoCV_BVmAZmBVcDBeCCgDAaB?s@RE?aCCaEAyHAoDd@EJiD@_@AaAj@A\\A?Gp@@r@oBXm@LQ?IEy@Fy@tA[n@Gj@Tz@[~ACdAAx@Lp@Kr@]hAa@HAQoCMwCSwGSiGK_CCCKaBCgCOoCOgECwGB_OB{JHkBEmC?yCDyFF{QFue@BsYByE?oAEgAByLBiL?gLBuGXsEd@cCNA?OHa@jAuCn@eAtCyDh@k@v@EvBKr@EEkACUKaC?G~@gAlCeDFBT[jFeGZAfBEh@UpBM`AEMaFjFYIhE?hEPpCJzAPt@Fj@GNUFu@N[FyBbAuB`@_@LEIOB}@HUBQFk@FcAACGQA}@Bi@F@F[Dc@D[FQHELGhBMtDGR?D");
//PolylineResult result = await polylinePoints.getRouteBetweenCoordinates("AIzaSyAUBI1ablMKuJwGj2-kSuEhvYxvB1A-mOE", origin,dest, travelMode: _mode, wayPoints: wayPoints);
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
}