From 6c8ac75b194761cf0d27c9f1a0d0caa379ea9156 Mon Sep 17 00:00:00 2001 From: Mohamed Nouffer Date: Sun, 11 Jun 2023 21:03:30 +0530 Subject: [PATCH] update to rog_only --- .../destination/destination_controller.dart | 5 +- .../destination_map/destination_map_page.dart | 257 ------------------ lib/pages/index/index_controller.dart | 4 +- lib/pages/index/index_page.dart | 22 +- lib/widgets/list_widget.dart | 140 +++++++--- lib/widgets/map_widget.dart | 26 ++ 6 files changed, 149 insertions(+), 305 deletions(-) diff --git a/lib/pages/destination/destination_controller.dart b/lib/pages/destination/destination_controller.dart index 6c3d0d4..f3155b5 100644 --- a/lib/pages/destination/destination_controller.dart +++ b/lib/pages/destination/destination_controller.dart @@ -510,6 +510,9 @@ class DestinationController extends GetxController { current_lat = position != null ? position.latitude : 0; current_lon = position != null ? position.longitude : 0; + indexController.current_lat = position != null ? position.latitude : 0; + current_lon = position != null ? position.longitude : 0; + print("==== gps skip is : ${skip_gps.toString()}, selected is ${is_gps_selected} , ${current_lat}"); if(is_gps_selected.value){ @@ -721,7 +724,7 @@ class DestinationController extends GetxController { DestinationService.getDestinationLine(points, matrix)?.then((value){ indexController.routePoints = value; indexController.routePointLenght.value = indexController.routePoints.length; - Get.toNamed(AppPages.TRAVEL); + //Get.toNamed(AppPages.TRAVEL); }); destinationCount.value = destinations.length; } diff --git a/lib/pages/destination_map/destination_map_page.dart b/lib/pages/destination_map/destination_map_page.dart index 8f16599..7f29b48 100644 --- a/lib/pages/destination_map/destination_map_page.dart +++ b/lib/pages/destination_map/destination_map_page.dart @@ -178,260 +178,3 @@ class DestinationMapPage extends StatelessWidget { ); } } - - - - -// class DestinationMapPage extends StatefulWidget { -// DestinationMapPage({ Key? key }) : super(key: key); - - -// @override -// State createState() => _DestinationMapPageState(); -// } - -//class _DestinationMapPageState extends State { - // final IndexController indexController = Get.find(); - - // final DestinationController destinationController = Get.find(); - // StreamSubscription? subscription; - // final PopupController _popupLayerController = PopupController(); - - // List? getPoints(List ptts){ - // //print("##### --- route point ${indexController.routePoints.length}"); - // List pts = []; - // for(PointLatLng p in ptts){ - // LatLng l = LatLng(p.latitude, p.longitude); - // pts.add(l); - // } - // return pts; - // } - - // String getDisplaytext(Destination dp){ - // String txt = ""; - // if(dp.cp! > 0){ - // txt = "${dp.cp}"; - // if(dp.checkin_point != null && dp.checkin_point! > 0){ - // txt = txt + "{${dp.checkin_point}}"; - // } - // if(dp.buy_point != null && dp.buy_point! > 0){ - // txt = txt + "[${dp.buy_point}]"; - // } - // } - // return txt; - // } - - // List? getMarkers() { - // List pts = []; - // int index = -1; - // for (int i = 0; i < destinationController.destinations.length; i++) { - // Destination d = destinationController.destinations[i]; - // //for(Destination d in destinationController.destinations){ - // //print("-----lat ${lat}, ----- lon ${lan}"); - // Marker m = Marker( - // point: LatLng(d.lat!, d.lon!), - // anchorPos: AnchorPos.align(AnchorAlign.center), - // builder:(cts){ - - // return InkWell( - // onTap: (){ - // print("-- Destination is --- ${d.name} ------"); - // if(d != null){ - // if(indexController.currentDestinationFeature.length > 0) { - // indexController.currentDestinationFeature.clear(); - // } - // indexController.currentDestinationFeature.add(d); - // //indexController.getAction(); - - // showModalBottomSheet(context: context, isScrollControlled: true, - // //builder:((context) => BottomSheetWidget()) - // builder:((context) => BottomSheetNew()) - // ); - // } - // }, - // child: Row( - // mainAxisAlignment: MainAxisAlignment.spaceBetween, - // children: [ - // Container( - // width:20, - // height:20, - // decoration: BoxDecoration( - // color: Colors.red, - // shape: BoxShape.circle, - // border: new Border.all( - // color: Colors.white, - // width: d.checkin_radious != null ? d.checkin_radious! : 1, - // ), - // ), - // child: new Center( - // child: new Text( - // (i + 1).toString(), - // style: TextStyle(color: Colors.white), - // ), - // ), - // ), - // Container( color: Colors.yellow, child: Text(getDisplaytext(d), style: TextStyle(fontSize: 15.0, fontWeight: FontWeight.bold, overflow: TextOverflow.visible),)), - // ], - // ), - // ); - - // //return Icon(Icons.pin_drop); - // // return IconButton( - // // onPressed: ()async { - // // Destination? fs = await destinationController.getDEstinationForLatLong(d.lat!, d.lon!); - // // print("-- Destination is --- ${fs!.name} ------"); - // // if(fs != null){ - // // if(indexController.currentDestinationFeature.length > 0) { - // // indexController.currentDestinationFeature.clear(); - // // } - // // indexController.currentDestinationFeature.add(fs); - // // //indexController.getAction(); - - // // showModalBottomSheet(context: context, isScrollControlled: true, - // // //builder:((context) => BottomSheetWidget()) - // // builder:((context) => BottomSheetNew()) - // // ); - // // } - // // }, - // // icon: Container( - // // width: 60, - // // height: 60, - // // decoration: BoxDecoration( - // // borderRadius: BorderRadius.circular(d.checkin_radious ?? 0), - // // color: Colors.transparent, - // // border: BoxBorder() - // // ), - // // child: Icon(Icons.pin_drop) - // // ) - // // ); - - // }); - - // pts.add(m); - // } - // return pts; - // } - - // @override - // void initState() { - - // //indexController.routePoints.clear(); - // DestinationService.getDestinationLine(destinationController.destinations)?.then((value){ - // //print("---- loading destination points ------ ${value}"); - // setState(() { - // indexController.routePoints = value; - // }); - // }); - // super.initState(); - // } - - // void reload(){ - // setState(() { - - // }); - // } - - // @override - // Widget build(BuildContext context) { - // return Obx((() => - // Stack( - // children: [ - // indexController.is_rog_mapcontroller_loaded.value == false ? - // Center(child: CircularProgressIndicator()) - // : - // BreadCrumbWidget(mapController:indexController.rogMapController), - // Padding( - // padding: const EdgeInsets.only(top:50.0), - // //child: TravelMap(), - // child: - // TravelMap(indexController.routePoints), - // ), - // // Positioned( - // // bottom: 200, - // // left: 10, - // // child: Container( - // // color: Colors.white, - // // child: Row( - // // children: [ - // // Text(destinationController.gps[0]), - // // Text(destinationController.locationPermission[0]) - // // ], - // // ), - // // ) - // // ), - // ], - // ) - // )); - // } - - // FlutterMap TravelMap(List ptts) { - // return FlutterMap( - // options: MapOptions( - // onMapCreated: (c){ - // indexController.rogMapController = c; - // indexController.rogMapController!.onReady.then((_) { - // indexController.is_rog_mapcontroller_loaded.value = true; - // subscription = indexController.rogMapController!.mapEventStream.listen((MapEvent mapEvent) { - // if (mapEvent is MapEventMoveStart) { - // //print(DateTime.now().toString() + ' [MapEventMoveStart] START'); - // // do something - // } - // if (mapEvent is MapEventMoveEnd) { - // destinationController.isSelected.value = false; - // //print(DateTime.now().toString() + ' [MapEventMoveStart] END'); - // //indexController.loadLocationsBound(); - // } - // }); - // }); - // } , - // bounds: indexController.currentBound.length > 0 ? indexController.currentBound[0]: LatLngBounds.fromPoints([LatLng(35.03999881162295, 136.40587119778962), LatLng(36.642756778706904, 137.95226720406063)]), - // zoom: 1, - // maxZoom: 42, - // interactiveFlags: InteractiveFlag.pinchZoom | InteractiveFlag.drag, - // //plugins: [LocationMarkerPlugin(),] - // ), - // children: [ - // TileLayerWidget( - // options: TileLayerOptions( - // urlTemplate: 'https://cyberjapandata.gsi.go.jp/xyz/std/{z}/{x}/{y}.png', - // subdomains: ['a', 'b', 'c'], - // ), - // ), - // //Obx(() => - // indexController.routePoints.length > 0 ? - // PolylineLayerWidget( - // options: PolylineLayerOptions( - // polylines: [ - // Polyline( - // points: getPoints(ptts)!, - // strokeWidth: 6.0, - // color: Colors.indigo - // ), - // ], - // ), - // ) - // : - // Container(), - // //), - // // PopupMarkerLayerWidget( - // // options: PopupMarkerLayerOptions( - // // popupController: _popupLayerController, - // // markers: _markers, - // // markerRotateAlignment: - // // PopupMarkerLayerOptions.rotationAlignmentFor(AnchorAlign.top), - // // popupBuilder: (BuildContext context, Marker marker) => - - // // examplePopup(marker), - // // ), - // // ), - // LocationMarkerLayerWidget(), - // MarkerLayerWidget( - // options: MarkerLayerOptions( - // markers: getMarkers()! - // ), - // ), - // ], - - // ); - // } -//} \ No newline at end of file diff --git a/lib/pages/index/index_controller.dart b/lib/pages/index/index_controller.dart index da25c94..f4279d4 100644 --- a/lib/pages/index/index_controller.dart +++ b/lib/pages/index/index_controller.dart @@ -39,6 +39,8 @@ class IndexController extends GetxController { List routePoints = [].obs; var routePointLenght = 0.obs; + double current_lat = 0.0, current_lon = 0.0; + var is_loading = false.obs; var is_mapController_loaded = false.obs; @@ -117,6 +119,7 @@ class IndexController extends GetxController { } } + @override void onInit() { _ever = ever(rog_mode, (_) => print("$_ has been changed (ever)")); @@ -131,7 +134,6 @@ class IndexController extends GetxController { } _connectivitySubscription = _connectivity.onConnectivityChanged.listen(_updateConnectionStatus); - super.onInit(); } diff --git a/lib/pages/index/index_page.dart b/lib/pages/index/index_page.dart index ad49ddc..c8aa073 100644 --- a/lib/pages/index/index_page.dart +++ b/lib/pages/index/index_page.dart @@ -25,19 +25,17 @@ class IndexPage extends GetView { @override Widget build(BuildContext context) { return WillPopScope( - onWillPop: () async { - indexController.switchPage(AppPages.INITIAL); - return false; - }, + onWillPop: () async => false, child: Scaffold( //drawer: const DrawerPage(), appBar: AppBar( - leading: IconButton( - icon: Icon(Icons.arrow_back_ios), - onPressed: (){ - indexController.switchPage(AppPages.TRAVEL); - }, - ), + automaticallyImplyLeading: false, + // leading: IconButton( + // icon: Icon(Icons.arrow_back_ios), + // onPressed: (){ + // indexController.switchPage(AppPages.TRAVEL); + // }, + // ), //automaticallyImplyLeading: false, title: Text("add_location".tr), actions: [ @@ -74,7 +72,7 @@ class IndexPage extends GetView { child: InkWell( child: Image(image: AssetImage('assets/images/route3_off.png'), width: 35, height: 35,), onTap: (){ - indexController.switchPage(AppPages.TRAVEL); + //indexController.switchPage(AppPages.TRAVEL); }, ), ) : @@ -83,7 +81,7 @@ class IndexPage extends GetView { child: InkWell( child: Image(image: AssetImage('assets/images/route2_on.png'),width: 35, height: 35,), onTap: (){ - indexController.switchPage(AppPages.TRAVEL); + //indexController.switchPage(AppPages.TRAVEL); }, ), ) diff --git a/lib/widgets/list_widget.dart b/lib/widgets/list_widget.dart index c663d05..ea1e93a 100644 --- a/lib/widgets/list_widget.dart +++ b/lib/widgets/list_widget.dart @@ -4,15 +4,23 @@ import 'package:get/get.dart'; import 'package:rogapp/model/destination.dart'; import 'package:rogapp/pages/destination/destination_controller.dart'; import 'package:rogapp/pages/index/index_controller.dart'; +import 'package:rogapp/services/maxtrix_service.dart'; import 'package:rogapp/utils/const.dart'; import 'package:rogapp/widgets/bottom_sheet_new.dart'; import 'package:rogapp/widgets/bottom_sheet_widget.dart'; -class ListWidget extends StatelessWidget { +class ListWidget extends StatefulWidget { ListWidget({ Key? key }) : super(key: key); + @override + State createState() => _ListWidgetState(); +} + +class _ListWidgetState extends State { final IndexController indexController = Get.find(); + final DestinationController destinationController = Get.find(); + List destList = []; Image getImage(int index){ if(indexController.locations[0].collection[index].properties!["photos"] == null || indexController.locations[0].collection[index].properties!["photos"] == ""){ @@ -41,44 +49,108 @@ class ListWidget extends StatelessWidget { indexController.currentFeature.add(fs); } + void getDestinationCoords() { + Destination cdes = Destination(lat: indexController.current_lat, lon: indexController.current_lon); + List dest = [cdes]; + for(int k=0; k < indexController.locations[0].collection.length; k++){ + GeoJsonMultiPoint _pt = indexController.locations[0].collection[k].geometry; + final de = Destination( + lat: _pt.geoSerie!.geoPoints.first.latitude, + lon: _pt.geoSerie!.geoPoints.first.longitude, + ); + //print("---dest a is: ${dest} ---"); + dest.insert(0, de); + + } + destList.assignAll(dest); + //print("--- dest is: ${dest} ---"); + } + + @override + void initState() { + super.initState(); + getDestinationCoords(); + } + + Future matrixDistance(int i) async { + final res = await MatrixService.getDestinations(destList.sublist(i, i+2)); + return res["routes"][0]["legs"][0]["distance"]["text"]; + //print("matrix result is ${i} : ${res["routes"][0]["legs"][0]["distance"]["text"]} "); + } + + Future _pullRefresh() async { + print("pull to refesh"); + setState(() { + indexController.locations[0].collection.sort((a, b) => + (a.properties!['cp'] as Comparable) + .compareTo(b.properties!['cp'] as Comparable)); + }); + // why use freshNumbers var? https://stackoverflow.com/a/52992836/2301224 + } + @override Widget build(BuildContext context) { return Obx(() => indexController.locations.length > 0 ? - ListView.builder( - itemCount: indexController.locations[0].collection.length, - shrinkWrap: true, - itemBuilder: (_, index){ - bool _is_found = false; - for(Destination d in destinationController.destinations){ - if(indexController.locations[0].collection[index].properties!['location_id'] == d.location_id){ - _is_found = true; - break; + RefreshIndicator( + onRefresh: _pullRefresh, + child: ListView.builder( + itemCount: indexController.locations[0].collection.length, + shrinkWrap: true, + itemBuilder: (_, index){ + bool _is_found = false; + for(Destination d in destinationController.destinations){ + if(indexController.locations[0].collection[index].properties!['location_id'] == d.location_id){ + _is_found = true; + break; + } } - } - return Card( - child: ListTile( - selected: _is_found, - - selectedTileColor: Colors.yellow.shade200, - onTap: (){ - GeoJsonFeature gf = indexController.locations[0].collection[index]; - changeCurrentFeature(gf); - showModalBottomSheet( - isScrollControlled: true, - context: context, - //builder: (context) => BottomSheetWidget(), - builder:((context) => BottomSheetNew()) - ); - }, - leading: getImage(index), - title: indexController.locations[0].collection[index].properties!['location_name'] != null ? Text(indexController.locations[0].collection[index].properties!['location_name'].toString()) : Text(""), - subtitle: indexController.locations[0].collection[index].properties!['category'] != null ? Text(indexController.locations[0].collection[index].properties!['category']) : Text(""), - trailing: indexController.locations[0].collection[index].properties!['sub_loc_id'] != null ? Text(indexController.locations[0].collection[index].properties!['sub_loc_id']) : Text(""), - ), - ); - }, - ) : Container(width: 0, height: 0,), + return Card( + child: ListTile( + selected: _is_found, + + selectedTileColor: Colors.yellow.shade200, + onTap: (){ + GeoJsonFeature gf = indexController.locations[0].collection[index]; + changeCurrentFeature(gf); + showModalBottomSheet( + isScrollControlled: true, + context: context, + //builder: (context) => BottomSheetWidget(), + builder:((context) => BottomSheetNew()) + ); + }, + leading: getImage(index), + title: indexController.locations[0].collection[index].properties!['location_name'] != null ? Text(indexController.locations[0].collection[index].properties!['location_name'].toString()) : Text(""), + subtitle: indexController.locations[0].collection[index].properties!['category'] != null ? Text(indexController.locations[0].collection[index].properties!['category']) : Text(""), + trailing: Column( + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + indexController.locations[0].collection[index].properties!['sub_loc_id'] != null ? Text(indexController.locations[0].collection[index].properties!['sub_loc_id']) : Text(""), + Container( + width: 100, + child: FutureBuilder( + future: matrixDistance(index), + builder: (context, snapshot){ + if(snapshot.connectionState == ConnectionState.waiting){ + return const Center(child: CircularProgressIndicator(),); + } + if(snapshot.hasError){ + return Text("-"); + } + else{ + return Text(snapshot.data ?? '', style: TextStyle(color: Colors.red, fontWeight: FontWeight.bold),); + } + }, + ), + ) + ], + ) + ), + ); + }, + ), + ) : Container(width: 0, height: 0,), ); } } \ No newline at end of file diff --git a/lib/widgets/map_widget.dart b/lib/widgets/map_widget.dart index 90fa391..b581b3b 100644 --- a/lib/widgets/map_widget.dart +++ b/lib/widgets/map_widget.dart @@ -3,6 +3,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_map/plugin_api.dart'; import 'package:flutter_map_location_marker/flutter_map_location_marker.dart'; import 'package:flutter_map_marker_cluster/flutter_map_marker_cluster.dart'; +import 'package:flutter_polyline_points/flutter_polyline_points.dart'; import 'package:geojson/geojson.dart'; import 'package:get/get.dart'; import 'package:get/get_state_manager/get_state_manager.dart'; @@ -87,6 +88,16 @@ class MapWidget extends StatelessWidget { ); } + List? getPoints(){ + print("##### --- route point ${indexController.routePoints.length}"); + List pts = []; + for(PointLatLng p in indexController.routePoints){ + LatLng l = LatLng(p.latitude, p.longitude); + pts.add(l); + } + return pts; + } + @override Widget build(BuildContext context) { @@ -133,6 +144,21 @@ class MapWidget extends StatelessWidget { ), children: [ BaseLayer(), + Obx(() => + indexController.routePointLenght > 0 ? + PolylineLayer( + polylines: [ + Polyline( + points: getPoints()!, + strokeWidth: 6.0, + color: Colors.indigo + ), + ], + ) + + : + Container(), + ), CurrentLocationLayer(), indexController.locations.isNotEmpty && indexController.locations[0].collection.isNotEmpty ? MarkerLayer(