Files
rog_app/lib/pages/destination_map/destination_map_page.dart

173 lines
6.0 KiB
Dart
Raw Normal View History

2022-05-24 20:43:41 +05:30
2022-06-04 20:16:29 +05:30
import 'dart:async';
2022-05-24 20:43:41 +05:30
import 'package:flutter/material.dart';
import 'package:flutter_map/plugin_api.dart';
2022-06-04 20:16:29 +05:30
import 'package:flutter_map_location_marker/flutter_map_location_marker.dart';
2022-06-14 14:37:59 +05:30
import 'package:flutter_map_marker_popup/flutter_map_marker_popup.dart';
2022-05-24 20:43:41 +05:30
import 'package:flutter_polyline_points/flutter_polyline_points.dart';
import 'package:get/get.dart';
import 'package:latlong2/latlong.dart';
2022-07-09 22:51:34 +05:30
import 'package:rogapp/model/destination.dart';
2022-05-24 20:43:41 +05:30
import 'package:rogapp/pages/destination/destination_controller.dart';
import 'package:rogapp/pages/index/index_controller.dart';
2022-10-12 21:46:17 +05:30
import 'package:rogapp/utils/text_util.dart';
2023-03-17 11:54:12 +05:30
import 'package:rogapp/widgets/base_layer_widget.dart';
2022-06-27 12:15:54 +05:30
import 'package:rogapp/widgets/bottom_sheet_new.dart';
2022-05-24 20:43:41 +05:30
2022-09-22 20:36:56 +05:30
class DestinationMapPage extends StatelessWidget {
DestinationMapPage({Key? key}) : super(key: key);
2022-06-14 14:37:59 +05:30
2022-05-24 20:43:41 +05:30
final IndexController indexController = Get.find<IndexController>();
final DestinationController destinationController = Get.find<DestinationController>();
2022-06-04 20:16:29 +05:30
StreamSubscription? subscription;
2022-06-14 14:37:59 +05:30
final PopupController _popupLayerController = PopupController();
2022-05-24 20:43:41 +05:30
List<LatLng>? getPoints(){
2022-09-22 20:36:56 +05:30
print("##### --- route point ${indexController.routePoints.length}");
2022-05-24 20:43:41 +05:30
List<LatLng> pts = [];
for(PointLatLng p in indexController.routePoints){
LatLng l = LatLng(p.latitude, p.longitude);
pts.add(l);
}
return pts;
}
2022-06-14 14:37:59 +05:30
List<Marker>? getMarkers() {
2022-05-24 20:43:41 +05:30
List<Marker> pts = [];
2022-07-28 19:01:45 +05:30
int index = -1;
for (int i = 0; i < destinationController.destinations.length; i++) {
Destination d = destinationController.destinations[i];
2023-08-16 14:53:32 +05:30
print("^^^^ $d ^^^^");
2022-07-27 19:43:12 +05:30
Marker m = Marker(
point: LatLng(d.lat!, d.lon!),
anchorPos: AnchorPos.align(AnchorAlign.center),
builder:(cts){
2022-07-28 19:01:45 +05:30
return InkWell(
onTap: (){
print("-- Destination is --- ${d.name} ------");
2023-08-16 14:53:32 +05:30
if(indexController.currentDestinationFeature.isNotEmpty) {
indexController.currentDestinationFeature.clear();
2022-07-28 19:01:45 +05:30
}
2023-08-16 14:53:32 +05:30
indexController.currentDestinationFeature.add(d);
//indexController.getAction();
showModalBottomSheet(context: Get.context!, isScrollControlled: true,
builder:((context) => BottomSheetNew())
).whenComplete((){
print("---- set skip gps to false -----");
destinationController.skip_gps = false;
});
2022-07-28 19:01:45 +05:30
},
2022-09-01 19:14:18 +05:30
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
width:20,
height:20,
decoration: BoxDecoration(
color: Colors.red,
shape: BoxShape.circle,
2023-08-16 14:53:32 +05:30
border: Border.all(
2022-09-01 19:14:18 +05:30
color: Colors.white,
width: d.checkin_radious != null ? d.checkin_radious! : 1,
),
),
2023-08-16 14:53:32 +05:30
child: Center(
child: Text(
2022-09-01 19:14:18 +05:30
(i + 1).toString(),
2023-08-16 14:53:32 +05:30
style: const TextStyle(color: Colors.white),
2022-09-01 19:14:18 +05:30
),
),
2022-07-28 19:01:45 +05:30
),
2023-08-16 14:53:32 +05:30
Container( color: Colors.yellow, child: Text(TextUtils.getDisplayText(d), style: const TextStyle(fontSize: 15.0, fontWeight: FontWeight.bold, overflow: TextOverflow.visible),)),
2022-09-01 19:14:18 +05:30
],
2022-07-28 19:01:45 +05:30
),
);
2022-06-14 14:37:59 +05:30
2022-05-24 20:43:41 +05:30
});
2022-06-14 14:37:59 +05:30
2022-05-24 20:43:41 +05:30
pts.add(m);
}
return pts;
}
@override
Widget build(BuildContext context) {
return Obx((() =>
2022-07-09 22:51:34 +05:30
Stack(
children: [
2023-05-18 10:27:49 +05:30
// indexController.is_rog_mapcontroller_loaded.value == false ?
// Center(child: CircularProgressIndicator())
// :
// Padding(
// padding: const EdgeInsets.only(left:8.0),
// child: BreadCrumbWidget(mapController:indexController.rogMapController),
// ),
2022-10-12 21:46:17 +05:30
Padding(
2023-05-18 10:27:49 +05:30
padding: const EdgeInsets.only(top:0.0),
2022-07-09 22:51:34 +05:30
//child: TravelMap(),
child:
TravelMap(),
2022-07-20 15:57:40 +05:30
),
2022-07-09 22:51:34 +05:30
],
)
));
}
FlutterMap TravelMap() {
return FlutterMap(
2023-03-17 11:54:12 +05:30
mapController: indexController.rogMapController,
2022-07-09 22:51:34 +05:30
options: MapOptions(
2023-03-17 11:54:12 +05:30
onMapReady: (){
2022-07-09 22:51:34 +05:30
indexController.is_rog_mapcontroller_loaded.value = true;
2023-08-16 14:53:32 +05:30
subscription = indexController.rogMapController.mapEventStream.listen((MapEvent mapEvent) {
2022-07-09 22:51:34 +05:30
if (mapEvent is MapEventMoveStart) {
}
if (mapEvent is MapEventMoveEnd) {
2022-10-30 21:43:29 +05:30
//destinationController.is_gps_selected.value = true;
//indexController.mapController!.move(c.center, c.zoom);
2023-08-16 14:53:32 +05:30
LatLngBounds bounds = indexController.rogMapController.bounds!;
2022-10-30 21:43:29 +05:30
indexController.currentBound.clear();
indexController.currentBound.add(bounds);
2023-08-16 14:53:32 +05:30
if(indexController.currentUser.isEmpty){
2023-02-16 19:36:39 +05:30
indexController.loadLocationsBound();
}
2022-07-09 22:51:34 +05:30
}
2022-06-04 20:16:29 +05:30
});
2022-07-09 22:51:34 +05:30
} ,
2023-08-16 14:53:32 +05:30
bounds: indexController.currentBound.isNotEmpty ? indexController.currentBound[0]: LatLngBounds.fromPoints([LatLng(35.03999881162295, 136.40587119778962), LatLng(36.642756778706904, 137.95226720406063)]),
2022-07-09 22:51:34 +05:30
zoom: 1,
2022-07-25 19:56:32 +05:30
maxZoom: 42,
2022-07-09 22:51:34 +05:30
interactiveFlags: InteractiveFlag.pinchZoom | InteractiveFlag.drag,
),
children: [
2023-08-16 14:53:32 +05:30
const BaseLayer(),
2022-09-22 20:36:56 +05:30
Obx(() =>
indexController.routePointLenght > 0 ?
2023-03-17 11:54:12 +05:30
PolylineLayer(
2022-07-25 19:56:32 +05:30
polylines: [
Polyline(
points: getPoints()!,
2022-09-01 19:14:18 +05:30
strokeWidth: 6.0,
2022-09-22 20:36:56 +05:30
color: Colors.indigo
),
2022-07-25 19:56:32 +05:30
],
)
2023-03-17 11:54:12 +05:30
2022-07-25 19:56:32 +05:30
:
Container(),
2022-09-22 20:36:56 +05:30
),
2023-03-17 11:54:12 +05:30
CurrentLocationLayer(),
MarkerLayer(
markers: getMarkers()!
2022-07-15 21:50:14 +05:30
),
2022-07-09 22:51:34 +05:30
],
);
2022-05-24 20:43:41 +05:30
}
2022-09-22 20:36:56 +05:30
}