update to rog_only

This commit is contained in:
Mohamed Nouffer
2023-06-11 21:03:30 +05:30
parent 08332d45d4
commit 6c8ac75b19
6 changed files with 149 additions and 305 deletions

View File

@ -510,6 +510,9 @@ class DestinationController extends GetxController {
current_lat = position != null ? position.latitude : 0; current_lat = position != null ? position.latitude : 0;
current_lon = position != null ? position.longitude : 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}"); print("==== gps skip is : ${skip_gps.toString()}, selected is ${is_gps_selected} , ${current_lat}");
if(is_gps_selected.value){ if(is_gps_selected.value){
@ -721,7 +724,7 @@ class DestinationController extends GetxController {
DestinationService.getDestinationLine(points, matrix)?.then((value){ DestinationService.getDestinationLine(points, matrix)?.then((value){
indexController.routePoints = value; indexController.routePoints = value;
indexController.routePointLenght.value = indexController.routePoints.length; indexController.routePointLenght.value = indexController.routePoints.length;
Get.toNamed(AppPages.TRAVEL); //Get.toNamed(AppPages.TRAVEL);
}); });
destinationCount.value = destinations.length; destinationCount.value = destinations.length;
} }

View File

@ -178,260 +178,3 @@ class DestinationMapPage extends StatelessWidget {
); );
} }
} }
// class DestinationMapPage extends StatefulWidget {
// DestinationMapPage({ Key? key }) : super(key: key);
// @override
// State<DestinationMapPage> createState() => _DestinationMapPageState();
// }
//class _DestinationMapPageState extends State<DestinationMapPage> {
// final IndexController indexController = Get.find<IndexController>();
// final DestinationController destinationController = Get.find<DestinationController>();
// StreamSubscription? subscription;
// final PopupController _popupLayerController = PopupController();
// List<LatLng>? getPoints(List<PointLatLng> ptts){
// //print("##### --- route point ${indexController.routePoints.length}");
// List<LatLng> 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<Marker>? getMarkers() {
// List<Marker> 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<PointLatLng> 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()!
// ),
// ),
// ],
// );
// }
//}

View File

@ -39,6 +39,8 @@ class IndexController extends GetxController {
List<PointLatLng> routePoints = <PointLatLng>[].obs; List<PointLatLng> routePoints = <PointLatLng>[].obs;
var routePointLenght = 0.obs; var routePointLenght = 0.obs;
double current_lat = 0.0, current_lon = 0.0;
var is_loading = false.obs; var is_loading = false.obs;
var is_mapController_loaded = false.obs; var is_mapController_loaded = false.obs;
@ -117,6 +119,7 @@ class IndexController extends GetxController {
} }
} }
@override @override
void onInit() { void onInit() {
_ever = ever(rog_mode, (_) => print("$_ has been changed (ever)")); _ever = ever(rog_mode, (_) => print("$_ has been changed (ever)"));
@ -131,7 +134,6 @@ class IndexController extends GetxController {
} }
_connectivitySubscription = _connectivity.onConnectivityChanged.listen(_updateConnectionStatus); _connectivitySubscription = _connectivity.onConnectivityChanged.listen(_updateConnectionStatus);
super.onInit(); super.onInit();
} }

View File

@ -25,19 +25,17 @@ class IndexPage extends GetView<IndexController> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return WillPopScope( return WillPopScope(
onWillPop: () async { onWillPop: () async => false,
indexController.switchPage(AppPages.INITIAL);
return false;
},
child: Scaffold( child: Scaffold(
//drawer: const DrawerPage(), //drawer: const DrawerPage(),
appBar: AppBar( appBar: AppBar(
leading: IconButton( automaticallyImplyLeading: false,
icon: Icon(Icons.arrow_back_ios), // leading: IconButton(
onPressed: (){ // icon: Icon(Icons.arrow_back_ios),
indexController.switchPage(AppPages.TRAVEL); // onPressed: (){
}, // indexController.switchPage(AppPages.TRAVEL);
), // },
// ),
//automaticallyImplyLeading: false, //automaticallyImplyLeading: false,
title: Text("add_location".tr), title: Text("add_location".tr),
actions: [ actions: [
@ -74,7 +72,7 @@ class IndexPage extends GetView<IndexController> {
child: InkWell( child: InkWell(
child: Image(image: AssetImage('assets/images/route3_off.png'), width: 35, height: 35,), child: Image(image: AssetImage('assets/images/route3_off.png'), width: 35, height: 35,),
onTap: (){ onTap: (){
indexController.switchPage(AppPages.TRAVEL); //indexController.switchPage(AppPages.TRAVEL);
}, },
), ),
) : ) :
@ -83,7 +81,7 @@ class IndexPage extends GetView<IndexController> {
child: InkWell( child: InkWell(
child: Image(image: AssetImage('assets/images/route2_on.png'),width: 35, height: 35,), child: Image(image: AssetImage('assets/images/route2_on.png'),width: 35, height: 35,),
onTap: (){ onTap: (){
indexController.switchPage(AppPages.TRAVEL); //indexController.switchPage(AppPages.TRAVEL);
}, },
), ),
) )

View File

@ -4,15 +4,23 @@ import 'package:get/get.dart';
import 'package:rogapp/model/destination.dart'; import 'package:rogapp/model/destination.dart';
import 'package:rogapp/pages/destination/destination_controller.dart'; import 'package:rogapp/pages/destination/destination_controller.dart';
import 'package:rogapp/pages/index/index_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/utils/const.dart';
import 'package:rogapp/widgets/bottom_sheet_new.dart'; import 'package:rogapp/widgets/bottom_sheet_new.dart';
import 'package:rogapp/widgets/bottom_sheet_widget.dart'; import 'package:rogapp/widgets/bottom_sheet_widget.dart';
class ListWidget extends StatelessWidget { class ListWidget extends StatefulWidget {
ListWidget({ Key? key }) : super(key: key); ListWidget({ Key? key }) : super(key: key);
@override
State<ListWidget> createState() => _ListWidgetState();
}
class _ListWidgetState extends State<ListWidget> {
final IndexController indexController = Get.find<IndexController>(); final IndexController indexController = Get.find<IndexController>();
final DestinationController destinationController = Get.find<DestinationController>(); final DestinationController destinationController = Get.find<DestinationController>();
List<Destination> destList = [];
Image getImage(int index){ Image getImage(int index){
if(indexController.locations[0].collection[index].properties!["photos"] == null || indexController.locations[0].collection[index].properties!["photos"] == ""){ 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); indexController.currentFeature.add(fs);
} }
void getDestinationCoords() {
Destination cdes = Destination(lat: indexController.current_lat, lon: indexController.current_lon);
List<Destination> 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<String> 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<void> _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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Obx(() => return Obx(() =>
indexController.locations.length > 0 ? indexController.locations.length > 0 ?
ListView.builder( RefreshIndicator(
itemCount: indexController.locations[0].collection.length, onRefresh: _pullRefresh,
shrinkWrap: true, child: ListView.builder(
itemBuilder: (_, index){ itemCount: indexController.locations[0].collection.length,
bool _is_found = false; shrinkWrap: true,
for(Destination d in destinationController.destinations){ itemBuilder: (_, index){
if(indexController.locations[0].collection[index].properties!['location_id'] == d.location_id){ bool _is_found = false;
_is_found = true; for(Destination d in destinationController.destinations){
break; if(indexController.locations[0].collection[index].properties!['location_id'] == d.location_id){
_is_found = true;
break;
}
} }
} return Card(
return Card( child: ListTile(
child: ListTile( selected: _is_found,
selected: _is_found,
selectedTileColor: Colors.yellow.shade200, selectedTileColor: Colors.yellow.shade200,
onTap: (){ onTap: (){
GeoJsonFeature gf = indexController.locations[0].collection[index]; GeoJsonFeature gf = indexController.locations[0].collection[index];
changeCurrentFeature(gf); changeCurrentFeature(gf);
showModalBottomSheet( showModalBottomSheet(
isScrollControlled: true, isScrollControlled: true,
context: context, context: context,
//builder: (context) => BottomSheetWidget(), //builder: (context) => BottomSheetWidget(),
builder:((context) => BottomSheetNew()) builder:((context) => BottomSheetNew())
); );
}, },
leading: getImage(index), leading: getImage(index),
title: indexController.locations[0].collection[index].properties!['location_name'] != null ? Text(indexController.locations[0].collection[index].properties!['location_name'].toString()) : Text(""), 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(""), 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(""), 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: 0, height: 0,), Container(
width: 100,
child: FutureBuilder<String>(
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,),
); );
} }
} }

View File

@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_map/plugin_api.dart'; import 'package:flutter_map/plugin_api.dart';
import 'package:flutter_map_location_marker/flutter_map_location_marker.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_map_marker_cluster/flutter_map_marker_cluster.dart';
import 'package:flutter_polyline_points/flutter_polyline_points.dart';
import 'package:geojson/geojson.dart'; import 'package:geojson/geojson.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:get/get_state_manager/get_state_manager.dart'; import 'package:get/get_state_manager/get_state_manager.dart';
@ -87,6 +88,16 @@ class MapWidget extends StatelessWidget {
); );
} }
List<LatLng>? getPoints(){
print("##### --- route point ${indexController.routePoints.length}");
List<LatLng> pts = [];
for(PointLatLng p in indexController.routePoints){
LatLng l = LatLng(p.latitude, p.longitude);
pts.add(l);
}
return pts;
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -133,6 +144,21 @@ class MapWidget extends StatelessWidget {
), ),
children: [ children: [
BaseLayer(), BaseLayer(),
Obx(() =>
indexController.routePointLenght > 0 ?
PolylineLayer(
polylines: [
Polyline(
points: getPoints()!,
strokeWidth: 6.0,
color: Colors.indigo
),
],
)
:
Container(),
),
CurrentLocationLayer(), CurrentLocationLayer(),
indexController.locations.isNotEmpty && indexController.locations[0].collection.isNotEmpty ? indexController.locations.isNotEmpty && indexController.locations[0].collection.isNotEmpty ?
MarkerLayer( MarkerLayer(