update
This commit is contained in:
@ -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>();
|
||||
|
||||
@ -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()
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
85
lib/pages/destination_map/destination_map_page.dart
Normal file
85
lib/pages/destination_map/destination_map_page.dart
Normal 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),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -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();
|
||||
|
||||
@ -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(
|
||||
|
||||
@ -23,6 +23,7 @@ class AppPages {
|
||||
static const REGISTER = Routes.REGISTER;
|
||||
static const TRAVEL = Routes.TRAVEL;
|
||||
static const LOADING = Routes.LOADING;
|
||||
static const DESTINATION_MAP = Routes.DESTINATION_MAP;
|
||||
|
||||
static final routes = [
|
||||
// GetPage(
|
||||
@ -69,6 +70,11 @@ class AppPages {
|
||||
name: Routes.LOADING,
|
||||
page: () => LoadingPage(),
|
||||
//binding: DestinationBinding(),
|
||||
)
|
||||
),
|
||||
GetPage(
|
||||
name: Routes.DESTINATION_MAP,
|
||||
page: () => DestinationPage(),
|
||||
//binding: DestinationBinding(),
|
||||
),
|
||||
];
|
||||
}
|
||||
@ -13,4 +13,5 @@ abstract class Routes {
|
||||
static const REGISTER = '/register';
|
||||
static const TRAVEL = '/travel';
|
||||
static const LOADING = '/loading';
|
||||
static const DESTINATION_MAP = '/destination_map';
|
||||
}
|
||||
|
||||
@ -1,4 +1,7 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:ffi';
|
||||
import 'package:flutter_polyline_points/flutter_polyline_points.dart';
|
||||
//import 'package:google_maps_webservice/directions.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
|
||||
@ -36,6 +39,35 @@ class DestinationService{
|
||||
return cats;
|
||||
}
|
||||
|
||||
static Future<List<PointLatLng>>? getDestinationLine(List<dynamic> destinations) async{
|
||||
PolylinePoints polylinePoints = PolylinePoints();
|
||||
|
||||
//print("##### @@@@@ ${destinations[0]["location"]["geometry"]["coordinates"][0][1]}");
|
||||
PointLatLng origin = PointLatLng(destinations[0]["location"]["geometry"]["coordinates"][0][1], destinations[0]["location"]["geometry"]["coordinates"][0][0]);
|
||||
PointLatLng dest = PointLatLng(destinations[destinations.length -1]["location"]["geometry"]["coordinates"][0][1], destinations[destinations.length -1]["location"]["geometry"]["coordinates"][0][0]);
|
||||
|
||||
|
||||
List<PolylineWayPoint> wayPoints = [];
|
||||
int i=0;
|
||||
for(dynamic d in destinations){
|
||||
if(i == 0 || i == (destinations.length -1)){
|
||||
i+=1;
|
||||
continue;
|
||||
}
|
||||
double la = d["location"]["geometry"]["coordinates"][0][1]as double;
|
||||
double ln = d["location"]["geometry"]["coordinates"][0][0] as double;
|
||||
PolylineWayPoint pwp = PolylineWayPoint(location: "${la},${ln}", stopOver: true);
|
||||
//print("----- UUUUUU ${pwp}");
|
||||
//PointLatLng wp = PointLatLng(d["Location"]["geometry"][0][1], d["Location"]["geometry"][0][0]);
|
||||
wayPoints.add(pwp);
|
||||
i+=1;
|
||||
}
|
||||
//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: TravelMode.driving, wayPoints: wayPoints);
|
||||
//print("#####@@@@@ ${result.points}");
|
||||
return result.points;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -24,7 +24,7 @@ class MatrixService{
|
||||
//print(locs);
|
||||
|
||||
Map<String, dynamic> cats = {};
|
||||
String url = "https://maps.googleapis.com/maps/api/distancematrix/json?destinations=${locs}&origins=${origin}&key=AIzaSyBLgnwft3py6c4YkT-MxZ9y4zYGFgAEmRk";
|
||||
String url = "https://maps.googleapis.com/maps/api/distancematrix/json?destinations=${locs}&origins=${origin}&key=AIzaSyAUBI1ablMKuJwGj2-kSuEhvYxvB1A-mOE";
|
||||
print(url);
|
||||
final http.Response response = await http.get(
|
||||
Uri.parse(url),
|
||||
|
||||
87
lib/widgets/destination_widget.dart
Normal file
87
lib/widgets/destination_widget.dart
Normal file
@ -0,0 +1,87 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:rogapp/pages/destination/destination_controller.dart';
|
||||
import 'package:rogapp/pages/index/index_controller.dart';
|
||||
import 'package:timeline_tile/timeline_tile.dart';
|
||||
|
||||
class DestinationWidget extends StatelessWidget {
|
||||
DestinationWidget({ Key? key }) : super(key: key);
|
||||
|
||||
final DestinationController destinationController = Get.find<DestinationController>();
|
||||
|
||||
final IndexController indexController = Get.find<IndexController>();
|
||||
|
||||
final List<int> _items = List<int>.generate(50, (int index) => index);
|
||||
|
||||
Image getImage(int index){
|
||||
if(destinationController.destinations[index]["location"]["properties"]["photos"] == null || destinationController.destinations[index]["location"]["properties"]["photos"] == ""){
|
||||
return Image(image: AssetImage('assets/images/empty_image.png'));
|
||||
}
|
||||
else{
|
||||
return Image(image: NetworkImage(destinationController.destinations[index]["location"]["properties"]["photos"]));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return
|
||||
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: index == 0 ? (Colors.red) : (Colors.grey[400])!
|
||||
),
|
||||
key: Key(index.toString()),
|
||||
endChild: Card(
|
||||
child: Container(
|
||||
constraints: const BoxConstraints(
|
||||
minHeight: 80,
|
||||
),
|
||||
child: ListTile(
|
||||
onLongPress: (){
|
||||
print("----- selected index ${index}");
|
||||
var el = destinationController.destination_index_data.where((element) =>
|
||||
element["index"] == index
|
||||
);
|
||||
if(el != null){
|
||||
destinationController.destination_index_data.remove(el);
|
||||
}
|
||||
print("------${el}---- index ${index}");
|
||||
Map<String, dynamic> indexed = {'index': index, 'selected':true};
|
||||
destinationController.destination_index_data.add(indexed);
|
||||
},
|
||||
leading: getImage(index),
|
||||
title: Text(destinationController.destinations[index]["location"]["properties"]["location_name"]),
|
||||
subtitle: Text(destinationController.destinations[index]["location"]["properties"]["category"]),
|
||||
),
|
||||
),
|
||||
|
||||
),
|
||||
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())
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -162,6 +162,13 @@ class MapWidget extends StatelessWidget {
|
||||
width: 70.0,
|
||||
point: LatLng(p.geoSerie!.geoPoints[0].latitude, p.geoSerie!.geoPoints[0].longitude),
|
||||
builder: (ctx) => Icon(Icons.pin_drop),
|
||||
// builder: (ctx) => i.properties!["category"] != null ?
|
||||
// ImageIcon(
|
||||
// AssetImage("assets/images/${i.properties!["category"]}.png"),
|
||||
// color: Color(0xFF3A5A98),
|
||||
// )
|
||||
// : Icon(Icons.pin_drop),
|
||||
|
||||
);
|
||||
}).toList(),
|
||||
builder: (context, markers) {
|
||||
|
||||
Reference in New Issue
Block a user