This commit is contained in:
Mohamed Nouffer
2022-05-24 20:43:41 +05:30
parent ee0440e6b6
commit 3cb7865d3b
60 changed files with 342 additions and 100 deletions

View File

@ -11,6 +11,7 @@ class DestinationController extends GetxController {
List<dynamic> destinations = <dynamic>[].obs;
List<Map<String, dynamic>> destination_index_data = <Map<String, dynamic>>[].obs;
Map<String, dynamic> matrix = {};
final IndexController indexController = Get.find<IndexController>();

View File

@ -3,8 +3,10 @@ import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:rogapp/pages/destination/destination_controller.dart';
import 'package:rogapp/pages/destination_map/destination_map_page.dart';
import 'package:rogapp/pages/index/index_controller.dart';
import 'package:rogapp/routes/app_pages.dart';
import 'package:rogapp/widgets/destination_widget.dart';
import 'package:timeline_tile/timeline_tile.dart';
@ -56,12 +58,8 @@ class _DestinationPageState extends State<DestinationPage> {
),
floatingActionButton: FloatingActionButton(
onPressed: (){
indexController.toggleMode();
if(indexController.currentCat.isNotEmpty){
print("###############");
print(indexController.currentCat[0].toString());
}
//print("######");
indexController.toggleDestinationMode();
},
tooltip: 'Increment',
child: const Icon(Icons.document_scanner),
@ -70,53 +68,39 @@ class _DestinationPageState extends State<DestinationPage> {
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
appBar:AppBar(
title: Text("Iternery"),
),
body:Obx(() =>
ReorderableListView.builder(
itemCount: destinationController.destinations.length,
onReorder: (int oldIndex, int newIndex){
int action_id = destinationController.destinations[oldIndex]["id"] as int;
//print(action_id);
if(oldIndex > newIndex){
destinationController.makeOrder(context, action_id, newIndex, "up");
}
else if(oldIndex < newIndex){
destinationController.makeOrder(context, action_id, newIndex, "down");
}
},
itemBuilder: (BuildContext context, int index) {
return TimelineTile(
alignment: TimelineAlign.manual,
lineXY: 0.2,
isFirst: index == 0 ? true : false,
indicatorStyle: IndicatorStyle(
color: Colors.red //index == 0 ? (Colors.red)! : (Colors.grey[400])!
),
key: Key(index.toString()),
endChild: Card(
child: Container(
constraints: const BoxConstraints(
minHeight: 80,
),
child: ListTile(
leading: getImage(index),
title: Text(destinationController.destinations[index]["location"]["properties"]["location_name"]),
subtitle: Text(destinationController.destinations[index]["location"]["properties"]["category"]),
actions: [
PopupMenuButton(
icon: Icon(Icons.more_vert),
itemBuilder: (BuildContext context) => <PopupMenuEntry>[
const PopupMenuItem(
child: ListTile(
leading: Icon(Icons.cut),
title: Text('Cut'),
),
),
),
),
startChild: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Text(destinationController.matrix["rows"][0]["elements"][index]["distance"]["text"].toString()),
Text(destinationController.matrix["rows"][0]["elements"][index]["duration"]["text"].toString())
const PopupMenuItem(
child: ListTile(
leading: Icon(Icons.paste),
title: Text('Paste'),
),
),
const PopupMenuItem(
child: ListTile(
leading: Icon(Icons.delete),
title: Text('Delete'),
),
),
// const PopupMenuDivider(),
// const PopupMenuItem(child: Text('Item A')),
// const PopupMenuItem(child: Text('Item B')),
],
),
);
}
)
],
),
body: Obx(() =>
indexController.desination_mode.value == 0 ?
DestinationWidget():
DestinationMapPage()
)
);

View File

@ -0,0 +1,85 @@
import 'package:flutter/material.dart';
import 'package:flutter_map/plugin_api.dart';
import 'package:flutter_polyline_points/flutter_polyline_points.dart';
import 'package:get/get.dart';
import 'package:latlong2/latlong.dart';
import 'package:rogapp/pages/destination/destination_controller.dart';
//import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:rogapp/pages/index/index_controller.dart';
import 'package:rogapp/services/destination_service.dart';
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>();
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;
}
List<Marker>? getMarkers(){
List<Marker> pts = [];
for(dynamic d in destinationController.destinations){
double lat = d["location"]["geometry"]["coordinates"][0][1];
double lan = d["location"]["geometry"]["coordinates"][0][0];
Marker m = Marker(point: LatLng(lat, lan), builder:(cts){
return Icon(Icons.pin_drop);
});
pts.add(m);
}
return pts;
}
@override
void initState() {
DestinationService.getDestinationLine(destinationController.destinations)?.then((value){
print("---- loading destination points ------ ${value}");
indexController.routePoints.clear();
indexController.routePoints = value;
});
super.initState();
}
@override
Widget build(BuildContext context) {
return Obx((() =>
FlutterMap(
options: MapOptions(
bounds: indexController.currentBound.length > 0 ? indexController.currentBound[0]: LatLngBounds.fromPoints([LatLng(35.03999881162295, 136.40587119778962), LatLng(36.642756778706904, 137.95226720406063)]),
zoom: 5.0,
),
layers: [
TileLayerOptions(
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c']),
MarkerLayerOptions(
markers: getMarkers()!,
),
PolylineLayerOptions(
polylines: [
Polyline(
points: getPoints()!,
strokeWidth: 4.0,
color: Colors.purple),
],
),
],
)
));
}
}

View File

@ -3,6 +3,7 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map/plugin_api.dart';
import 'package:flutter_polyline_points/flutter_polyline_points.dart';
import 'package:geojson/geojson.dart';
import 'package:get/get.dart';
import 'package:latlong2/latlong.dart';
@ -25,6 +26,7 @@ class IndexController extends GetxController {
List<Map<String, dynamic>> currentUser = <Map<String, dynamic>>[].obs;
List<dynamic> currentAction = <dynamic>[].obs;
List<PointLatLng> routePoints = <PointLatLng>[].obs;
var is_loading = false.obs;
@ -32,12 +34,14 @@ class IndexController extends GetxController {
var mode = 0.obs;
var desination_mode = 0.obs;
String dropdownValue = "9";
String subDropdownValue = "-1";
void toggleMode(){
if(mode==0){
if(mode.value==0){
mode += 1;
}
else{
@ -45,6 +49,15 @@ class IndexController extends GetxController {
}
}
void toggleDestinationMode(){
if(desination_mode.value==0){
desination_mode.value += 1;
}
else{
desination_mode.value -= 1;
}
}
@override
void onInit() {
super.onInit();
@ -208,10 +221,10 @@ class IndexController extends GetxController {
void loadLocationsBound(){
String cat = currentCat.isNotEmpty ? currentCat[0] : "";
LatLngBounds bounds = mapController!.bounds!;
print(currentCat);
//print(currentCat);
if(bounds.southEast != null && bounds.southWest != null && bounds.northEast != null && bounds.southEast != null ){
LocationService.loadLocationsBound(bounds.southWest!.latitude, bounds.southWest!.longitude, bounds.northWest.latitude, bounds.northWest.longitude, bounds.northEast!.latitude, bounds.northEast!.longitude, bounds.southEast.latitude, bounds.southEast.longitude, cat).then((value){
print("---value length ------ ${value!.collection.length}");
//print("---value length ------ ${value!.collection.length}");
if(value == null){
return;
}
@ -219,7 +232,7 @@ class IndexController extends GetxController {
Get.showSnackbar(GetSnackBar(message: "Too many points, please zoom in",));
}
if(value != null && value.collection.isNotEmpty){
print("---- added---");
//print("---- added---");
locations.clear();
locations.add(value);
loadCatsv2();

View File

@ -11,6 +11,8 @@ import 'package:rogapp/widgets/cat_widget.dart';
import 'package:rogapp/widgets/list_widget.dart';
import 'package:rogapp/widgets/map_widget.dart';
import 'package:flutter_polyline_points/flutter_polyline_points.dart';
class IndexPage extends GetView<IndexController> {
IndexPage({Key? key}) : super(key: key);
@ -24,7 +26,16 @@ class IndexPage extends GetView<IndexController> {
title: Text("app_title".tr),
actions: [
ElevatedButton(onPressed: (){}, child: CatWidget(indexController: indexController,)),
//CatWidget(indexController: indexController,),
CatWidget(indexController: indexController,),
ElevatedButton(
onPressed: () async{
PolylinePoints polylinePoints = PolylinePoints();
PolylineResult result = await polylinePoints.getRouteBetweenCoordinates("AIzaSyAUBI1ablMKuJwGj2-kSuEhvYxvB1A-mOE", PointLatLng(35.389282, 136.498027), PointLatLng(36.285848, 137.575186));
print(result.points);
indexController.routePoints = result.points;
},
child: Text("Google")
)
],
),
bottomNavigationBar: BottomAppBar(