From 0470e1f27f9e964c16b580a9699bbc7012763489 Mon Sep 17 00:00:00 2001 From: Mohamed Nouffer Date: Thu, 29 Sep 2022 15:32:33 +0530 Subject: [PATCH] update to routing --- .../destination/destination_controller.dart | 4 +- lib/pages/destination/destination_page.dart | 22 +++--- lib/pages/index/index_controller.dart | 2 +- lib/services/destination_service.dart | 26 +++++-- lib/services/maxtrix_service.dart | 13 +++- lib/utils/const.dart | 2 +- lib/utils/string_values.dart | 6 +- lib/widgets/bottom_sheet_new.dart | 74 +++++++++++-------- lib/widgets/destination_widget.dart | 30 +++++--- lib/widgets/map_widget.dart | 8 +- lib/widgets/perfecture_widget.dart | 3 +- 11 files changed, 120 insertions(+), 70 deletions(-) diff --git a/lib/pages/destination/destination_controller.dart b/lib/pages/destination/destination_controller.dart index 81e7487..18412a6 100644 --- a/lib/pages/destination/destination_controller.dart +++ b/lib/pages/destination/destination_controller.dart @@ -46,7 +46,7 @@ class DestinationController extends GetxController { void getRoutePoints() { indexController.routePoints = []; indexController.routePointLenght.value = 0; - DestinationService.getDestinationLine(destinations)?.then((value){ + DestinationService.getDestinationLine(destinations, matrix)?.then((value){ indexController.routePoints = value; indexController.routePointLenght.value = indexController.routePoints.length; }); @@ -272,8 +272,8 @@ class DestinationController extends GetxController { print("--------- destination controller populsting destinations ----------- ::::::"); DatabaseHelper db = DatabaseHelper.instance; + destinations.clear(); db.getDestinations().then((value){ - destinations.clear(); destinationCount.value = 0; for(Destination d in value){ for(Destination s in currentSelectedDestinations){ diff --git a/lib/pages/destination/destination_page.dart b/lib/pages/destination/destination_page.dart index bad5142..e767289 100644 --- a/lib/pages/destination/destination_page.dart +++ b/lib/pages/destination/destination_page.dart @@ -105,17 +105,17 @@ class DestnationPage extends StatelessWidget { Get.back(); }, ), - ListTile( - selected: destinationController.travelMode == 2 ? true : false, - selectedTileColor: Colors.amber.shade200, - leading: Image(image: AssetImage('assets/images/p4_10_train.png'),), - title: Text("transit".tr), - onTap:(){ - destinationController.travelMode.value = 2; - destinationController.PopulateDestinations(); - Get.back(); - }, - ), + // ListTile( + // selected: destinationController.travelMode == 2 ? true : false, + // selectedTileColor: Colors.amber.shade200, + // leading: Image(image: AssetImage('assets/images/p4_10_train.png'),), + // title: Text("transit".tr), + // onTap:(){ + // destinationController.travelMode.value = 2; + // destinationController.PopulateDestinations(); + // Get.back(); + // }, + // ), ], ), diff --git a/lib/pages/index/index_controller.dart b/lib/pages/index/index_controller.dart index 4803fe8..93d12f8 100644 --- a/lib/pages/index/index_controller.dart +++ b/lib/pages/index/index_controller.dart @@ -305,7 +305,7 @@ void login(String email, String password, BuildContext context){ void loadAreaFor(String perf){ areas.clear(); - dynamic initVal = {'id':'-1', 'adm2_ja':'----'}; + dynamic initVal = {'id':'-1', 'area_nm':'----'}; PerfectureService.loadGifuAreas(perf).then((value){ value!.add(initVal); areas.add(value); diff --git a/lib/services/destination_service.dart b/lib/services/destination_service.dart index d0acace..f3fb32d 100644 --- a/lib/services/destination_service.dart +++ b/lib/services/destination_service.dart @@ -67,7 +67,7 @@ class DestinationService{ return cats; } - static Future>? getDestinationLine(List destinations) async{ + static Future>? getDestinationLine(List destinations, Map mtx) async{ PolylinePoints polylinePoints = PolylinePoints(); if(destinations.length <= 0){ @@ -88,28 +88,40 @@ class DestinationService{ } double la = d.lat; double ln = d.lon; - PolylineWayPoint pwp = PolylineWayPoint(location: "${la},${ln}", stopOver: true); + + int j = 0; + + PolylineWayPoint pwp = PolylineWayPoint(location: "${la},${ln}", stopOver: false); + + //print("----- UUUUUU ${pwp}"); //PointLatLng wp = PointLatLng(d["Location"]["geometry"][0][1], d["Location"]["geometry"][0][0]); wayPoints.add(pwp); i+=1; + j += 4; } final DestinationController destinationController = Get.find(); int trav_mode = destinationController.travelMode.value; - TravelMode _mode = TravelMode.walking; + String _mode = "WALKING"; if(trav_mode == 1){ - _mode = TravelMode.driving; + //_mode = TravelMode.driving; + _mode = "DRIVING"; } else if(trav_mode == 2) { - _mode = TravelMode.transit; + //_mode = TravelMode.transit; + _mode = "TRANSIT"; } //PolylineResult result = await polylinePoints.getRouteBetweenCoordinates("AIzaSyAUBI1ablMKuJwGj2-kSuEhvYxvB1A-mOE", PointLatLng(35.389282, 136.498027), PointLatLng(36.285848, 137.575186)); - PolylineResult result = await polylinePoints.getRouteBetweenCoordinates("AIzaSyAUBI1ablMKuJwGj2-kSuEhvYxvB1A-mOE", origin,dest, travelMode: _mode, wayPoints: wayPoints); + Map pl = destinationController.matrix["routes"][0]["overview_polyline"]; + List result = polylinePoints.decodePolyline(pl["points"]); + //List 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); + //print("#####@@@@@ ${result.points}"); - return result.points; + return result; } diff --git a/lib/services/maxtrix_service.dart b/lib/services/maxtrix_service.dart index 03c6473..421799c 100644 --- a/lib/services/maxtrix_service.dart +++ b/lib/services/maxtrix_service.dart @@ -14,6 +14,7 @@ class MatrixService{ String locs = ""; String origin = ""; + String destination = ""; int i = 0; for(Destination d in destinations){ @@ -21,6 +22,14 @@ class MatrixService{ if(i==0){ origin = "${d.lat}, ${d.lon}"; + i++; + continue; + } + + if(i == (destinations.length - 1)){ + destination = "${d.lat}, ${d.lon}"; + i++; + continue; } print("lat is ${d.lat}, long is ${d.lon}"); @@ -28,6 +37,8 @@ class MatrixService{ i++; } + locs = "optimize:false|${locs}"; + String _mode = "walking"; switch (destinationController.travelMode.value) { case 1: @@ -42,7 +53,7 @@ class MatrixService{ } Map cats = {}; - String url = "https://maps.googleapis.com/maps/api/distancematrix/json?destinations=${locs}&mode=${_mode}&origins=${origin}&key=AIzaSyAUBI1ablMKuJwGj2-kSuEhvYxvB1A-mOE"; + String url = "https://maps.googleapis.com/maps/api/directions/json?destination=${destination}&mode=${_mode}&waypoints=${locs}&origin=${origin}&key=AIzaSyAUBI1ablMKuJwGj2-kSuEhvYxvB1A-mOE"; print(url); final http.Response response = await http.get( Uri.parse(url), diff --git a/lib/utils/const.dart b/lib/utils/const.dart index fa0903a..bacb16a 100644 --- a/lib/utils/const.dart +++ b/lib/utils/const.dart @@ -8,6 +8,6 @@ class ConstValues{ static const dev_home_ip_server = "http://172.20.10.9:8100"; static String currentServer(){ - return dev_home_ip_server; + return server_uri; } } diff --git a/lib/utils/string_values.dart b/lib/utils/string_values.dart index 61242fb..da61189 100644 --- a/lib/utils/string_values.dart +++ b/lib/utils/string_values.dart @@ -41,7 +41,8 @@ class StringValues extends Translations{ 'confirm': 'Confirm', 'cancel': 'Cancel', 'all_destinations_are_deleted_successfully' : 'All destinations are deleted successfully', - 'deleted': "Deleted" + 'deleted': 'Deleted', + 'remarks' : 'Remarks' }, 'ja_JP': { 'drawer_title':'ロゲイニング参加者はログイン するとチェックポイントが参照 できます', @@ -83,7 +84,8 @@ class StringValues extends Translations{ 'confirm': '確認', 'cancel': 'キャンセル', 'all_destinations_are_deleted_successfully' : 'すべての宛先が正常に削除されました', - 'deleted': "削除された" + 'deleted': "削除された", + 'remarks' : '備考' }, }; } \ No newline at end of file diff --git a/lib/widgets/bottom_sheet_new.dart b/lib/widgets/bottom_sheet_new.dart index b55187c..924bbc4 100644 --- a/lib/widgets/bottom_sheet_new.dart +++ b/lib/widgets/bottom_sheet_new.dart @@ -111,7 +111,8 @@ class BottomSheetNew extends GetView { children: [ MaterialButton( onPressed: () { - destinationController.makePrevious(indexController.currentDestinationFeature[0]); + Get.back(); + //destinationController.makePrevious(indexController.currentDestinationFeature[0]); }, color: Colors.blue, textColor: Colors.white, @@ -134,19 +135,19 @@ class BottomSheetNew extends GetView { ), ), ), - MaterialButton( - onPressed: () { - destinationController.makeNext(indexController.currentDestinationFeature[0]); - }, - color: Colors.blue, - textColor: Colors.white, - child: Icon( - Icons.arrow_forward_ios, - size: 14, - ), - padding: EdgeInsets.all(16), - shape: CircleBorder(), - ), + // MaterialButton( + // onPressed: () { + // destinationController.makeNext(indexController.currentDestinationFeature[0]); + // }, + // color: Colors.blue, + // textColor: Colors.white, + // child: Icon( + // Icons.arrow_forward_ios, + // size: 14, + // ), + // padding: EdgeInsets.all(16), + // shape: CircleBorder(), + // ), ], ), ), @@ -223,7 +224,8 @@ class BottomSheetNew extends GetView { children: [ MaterialButton( onPressed: () { - indexController.makePrevious(indexController.currentFeature[0]); + Get.back(); + //indexController.makePrevious(indexController.currentFeature[0]); }, color: Colors.blue, textColor: Colors.white, @@ -246,20 +248,20 @@ class BottomSheetNew extends GetView { ), ), ), - MaterialButton( - onPressed: () { - //print("----- next is ${indexController.currentFeature[0]} ------"); - indexController.makeNext(indexController.currentFeature[0]); - }, - color: Colors.blue, - textColor: Colors.white, - child: Icon( - Icons.arrow_forward_ios, - size: 14, - ), - padding: EdgeInsets.all(16), - shape: CircleBorder(), - ), + // MaterialButton( + // onPressed: () { + // //print("----- next is ${indexController.currentFeature[0]} ------"); + // indexController.makeNext(indexController.currentFeature[0]); + // }, + // color: Colors.blue, + // textColor: Colors.white, + // child: Icon( + // Icons.arrow_forward_ios, + // size: 14, + // ), + // padding: EdgeInsets.all(16), + // shape: CircleBorder(), + // ), ], ), ), @@ -365,7 +367,19 @@ class BottomSheetNew extends GetView { ], ), ), - Text('id: ${indexController.currentFeature[0].properties!["location_id"].toString()}, cp : ${indexController.currentFeature[0].properties!["cp"].toString()}'), + Padding( + padding: const EdgeInsets.all(8.0), + child: Row( + children: [ + SizedBox(width: 8.0,), + indexController.currentFeature[0].properties!["remark"] != null && (indexController.currentFeature[0].properties!["remark"] as String).isNotEmpty ? + getDetails(context, "remarks".tr, indexController.currentFeature[0].properties!["remark"] ?? '', isurl: false) + : + Container(width: 0.0, height: 0,), + ], + ), + ), + Text('${indexController.currentFeature[0].properties!["cp"].toString()} - id: ${indexController.currentFeature[0].properties!["checkin_point"].toString()}'), ], ), ) diff --git a/lib/widgets/destination_widget.dart b/lib/widgets/destination_widget.dart index 3325e0e..85d5620 100644 --- a/lib/widgets/destination_widget.dart +++ b/lib/widgets/destination_widget.dart @@ -26,12 +26,24 @@ class DestinationWidget extends StatelessWidget { } else{ print("------- image is ${destinationController.destinations[index].photos!}------"); - return Image(image: NetworkImage( - destinationController.destinations[index].photos!), - errorBuilder: (BuildContext context, Object exception, StackTrace? stackTrace) { - return Image.asset("assets/images/empty_image.png"); - }, - ); + String _photo = destinationController.destinations[index].photos!; + if(_photo.contains('http')){ + return Image(image: NetworkImage( + destinationController.destinations[index].photos!), + errorBuilder: (BuildContext context, Object exception, StackTrace? stackTrace) { + return Image.asset("assets/images/empty_image.png"); + }, + ); + } + else { + return Image(image: NetworkImage( + 'http://container.intranet.sumasen.net:8100/media/' + destinationController.destinations[index].photos!), + errorBuilder: (BuildContext context, Object exception, StackTrace? stackTrace) { + return Image.asset("assets/images/empty_image.png"); + }, + ); + } + } } @@ -221,12 +233,12 @@ class DestinationWidget extends StatelessWidget { ), ), startChild: - destinationController.matrix["rows"][0]["elements"] != null ? + index > 0 && destinationController.matrix["routes"][0]["legs"] != null ? Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - Text(destinationController.matrix["rows"][0]["elements"][index]["distance"] != null ? destinationController.matrix["rows"][0]["elements"][index]["distance"]["text"].toString(): ''), - Text(destinationController.matrix["rows"][0]["elements"][index]["distance"] != null ? destinationController.matrix["rows"][0]["elements"][index]["duration"]["text"].toString() : '') + Text(destinationController.matrix["routes"][0]["legs"][index -1]["distance"] != null ? destinationController.matrix["routes"][0]["legs"][index-1]["distance"]["text"].toString(): ''), + Text(destinationController.matrix["routes"][0]["legs"][index -1]["duration"] != null ? destinationController.matrix["routes"][0]["legs"][index-1]["duration"]["text"].toString() : '') ], ): Container() diff --git a/lib/widgets/map_widget.dart b/lib/widgets/map_widget.dart index aa83fb2..8c601b5 100644 --- a/lib/widgets/map_widget.dart +++ b/lib/widgets/map_widget.dart @@ -43,10 +43,10 @@ class MapWidget extends StatelessWidget { Icon(Icons.circle,size: 6.0,), i.properties!['cp'] == -1 ? Transform.rotate( - alignment: Alignment.center, - origin: Offset.fromDirection(0, 6), - angle: 90 * pi / 180, - child: Icon(Icons.play_arrow_outlined, color: Colors.red, size: 40,)): + alignment: Alignment.centerLeft, + origin: Offset.fromDirection(1, 26), + angle: 270 * pi / 180, + child: Icon(Icons.play_arrow_outlined, color: Colors.red, size: 70,)): Container(color: Colors.transparent,), ], ) diff --git a/lib/widgets/perfecture_widget.dart b/lib/widgets/perfecture_widget.dart index 543824f..56c280f 100644 --- a/lib/widgets/perfecture_widget.dart +++ b/lib/widgets/perfecture_widget.dart @@ -60,7 +60,6 @@ class _PerfectureWidgetState extends State { child: Text(currency["adm2_ja"].toString()), value: currency["id"].toString(), ); - dropDownItems.add(newDropdown); } } @@ -76,8 +75,8 @@ class _PerfectureWidgetState extends State { child: Text(currency["area_nm"].toString()), value: currency["id"].toString(), ); - dropDownItems.add(newDropdown); + } }