update for travelmode change bug fixes

This commit is contained in:
Mohamed Nouffer
2022-07-10 23:50:43 +05:30
parent ce105a6754
commit 264cd828f4
9 changed files with 121 additions and 62 deletions

View File

@ -16,6 +16,7 @@ class Destination {
String? photos; String? photos;
double? checkin_radious; double? checkin_radious;
int? auto_checkin; int? auto_checkin;
bool selected = false;
Destination({ Destination({
this.name, this.name,

View File

@ -27,6 +27,8 @@ class DestinationController extends GetxController {
List<Destination> destinations = <Destination>[].obs; List<Destination> destinations = <Destination>[].obs;
List<Map<String, dynamic>> destination_index_data = <Map<String, dynamic>>[].obs; List<Map<String, dynamic>> destination_index_data = <Map<String, dynamic>>[].obs;
List<Destination> currentSelectedDestinations = <Destination>[].obs;
bool checking_in = false; bool checking_in = false;
List<bool> isSelected = [true].obs; List<bool> isSelected = [true].obs;
BuildContext? context; BuildContext? context;
@ -159,12 +161,17 @@ class DestinationController extends GetxController {
} }
void deleteDestination(int index){ void deleteDestination(Destination d){
print("---- index ${index}-----"); //int id = destinations[index].location_id!;
int id = destinations[index].location_id!;
//print("---- index ${destinations[index].location_id!}-----"); //print("---- index ${destinations[index].location_id!}-----");
for(Destination ss in currentSelectedDestinations){
if(ss.location_id == d.location_id){
currentSelectedDestinations.remove(ss);
break;
}
}
DatabaseHelper db = DatabaseHelper.instance; DatabaseHelper db = DatabaseHelper.instance;
db.deleteDestination(id).then((value){ db.deleteDestination(d.location_id!).then((value){
PopulateDestinations(); PopulateDestinations();
}); });
// DestinationService.deleteDestination(id).then((val){ // DestinationService.deleteDestination(id).then((val){
@ -178,36 +185,50 @@ class DestinationController extends GetxController {
void addDestinations(Destination dest){ void addDestinations(Destination dest){
print('------ destination controller in add destination ${dest.name} ---- :::::');
DatabaseHelper db = DatabaseHelper.instance; DatabaseHelper db = DatabaseHelper.instance;
db.getDestinationByLatLon(dest.lat!, dest.lon!).then((value){ db.getDestinationByLatLon(dest.lat!, dest.lon!).then((value){
//print("----- available destination for latlon $value[0]");
if(value.isNotEmpty){ if(value.isNotEmpty){
db.deleteDestination(value[0].location_id!).then((value){ db.deleteDestination(value[0].location_id!).then((value){
db.insertDestination(dest).then((value){ db.insertDestination(dest).then((value){
print("----- delete andinserted destination id $value"); print("----- destination controller deleted and inserted destination id $value ---- :::::");
PopulateDestinations();
}); });
}); });
} }
else { else {
db.insertDestination(dest).then((value){ db.insertDestination(dest).then((value){
print("----- new inserted destination id $value"); print("----- destination controller added as new ${value}--- :::::");
PopulateDestinations();
}); });
} }
}); });
PopulateDestinations();
} }
void PopulateDestinations(){ void PopulateDestinations(){
print("--------- populsting destinations -----------"); print("--------- destination controller populsting destinations ----------- ::::::");
destinations.clear();
destinationCount.value = 0;
DatabaseHelper db = DatabaseHelper.instance; DatabaseHelper db = DatabaseHelper.instance;
db.getDestinations().then((value){ db.getDestinations().then((value){
destinations.clear(); for(Destination d in value){
destinations = value; print("-- destination controller Populating destination -- ${d.name}-----::::");
for(Destination s in currentSelectedDestinations){
if(d.location_id == s.location_id){
d.selected = !d.selected;
}
}
destinations.add(d);
}
// destinationCount.value = 0; // destinationCount.value = 0;
print("------destinationcount-------- ${destinationCount}--------");
destinationCount.value = destinations.length; destinationCount.value = destinations.length;
print("------ destination controller destinationcount-------- ${destinationCount}-------- :::::");
MatrixService.getDestinations(value).then((mat){ MatrixService.getDestinations(value).then((mat){
print(mat); print(mat);

View File

@ -51,6 +51,8 @@ class IndexController extends GetxController {
var desination_mode = 1.obs; var desination_mode = 1.obs;
bool showPopup = true;
String dropdownValue = "9"; String dropdownValue = "9";
String subDropdownValue = "-1"; String subDropdownValue = "-1";
@ -372,6 +374,9 @@ void login(String email, String password, BuildContext context){
} }
locations.clear(); locations.clear();
if(value != null && value.collection.isEmpty){ if(value != null && value.collection.isEmpty){
if(showPopup == false) {
return;
}
Get.snackbar( Get.snackbar(
"Too many Points", "Too many Points",
"please zoom in", "please zoom in",
@ -381,6 +386,7 @@ void login(String email, String password, BuildContext context){
backgroundColor: Colors.yellow, backgroundColor: Colors.yellow,
//icon:Image(image:AssetImage("assets/images/dora.png")) //icon:Image(image:AssetImage("assets/images/dora.png"))
); );
showPopup = false;
//Get.showSnackbar(GetSnackBar(message: "Too many points, please zoom in",)); //Get.showSnackbar(GetSnackBar(message: "Too many points, please zoom in",));
} }
if(value != null && value.collection.isNotEmpty){ if(value != null && value.collection.isNotEmpty){

View File

@ -2,10 +2,12 @@ import 'dart:ui';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:rogapp/model/destination.dart';
import 'package:rogapp/pages/drawer/drawer_page.dart'; import 'package:rogapp/pages/drawer/drawer_page.dart';
import 'package:rogapp/pages/index/index_controller.dart'; import 'package:rogapp/pages/index/index_controller.dart';
import 'package:rogapp/routes/app_pages.dart'; import 'package:rogapp/routes/app_pages.dart';
import 'package:rogapp/services/maxtrix_service.dart'; import 'package:rogapp/services/maxtrix_service.dart';
import 'package:rogapp/utils/database_helper.dart';
import 'package:rogapp/widgets/bread_crum_widget.dart'; import 'package:rogapp/widgets/bread_crum_widget.dart';
import 'package:rogapp/widgets/cat_widget.dart'; import 'package:rogapp/widgets/cat_widget.dart';
import 'package:rogapp/widgets/list_widget.dart'; import 'package:rogapp/widgets/list_widget.dart';
@ -23,15 +25,27 @@ class IndexPage extends GetView<IndexController> {
return Scaffold( return Scaffold(
drawer: const DrawerPage(), drawer: const DrawerPage(),
appBar: AppBar( appBar: AppBar(
leading: IconButton( // leading: IconButton(
icon: Icon(Icons.arrow_back_ios), // icon: Icon(Icons.arrow_back_ios),
onPressed: (){ // onPressed: (){
indexController.switchPage(AppPages.TRAVEL); // indexController.switchPage(AppPages.TRAVEL);
}, // },
), // ),
automaticallyImplyLeading: false, //automaticallyImplyLeading: false,
title: Text("Add locations"), title: Text("Add locations"),
actions: [ actions: [
// RaisedButton(
// child: Text("db"),
// onPressed: (){
// DatabaseHelper db = DatabaseHelper.instance;
// db.getDestinations().then((value){
// print("-------- lendth in db ${value.length} ---- :::::");
// for(Destination d in value){
// print("-------- values in db are ${d.toString()} ---- :::::");
// };
// });
// },
// ),
CatWidget(indexController: indexController,), CatWidget(indexController: indexController,),
], ],
), ),

View File

@ -68,7 +68,11 @@ class DestinationService{
static Future<List<PointLatLng>>? getDestinationLine(List<Destination> destinations) async{ static Future<List<PointLatLng>>? getDestinationLine(List<Destination> destinations) async{
PolylinePoints polylinePoints = PolylinePoints(); PolylinePoints polylinePoints = PolylinePoints();
print("##### @@@@@ ${destinations[0].lat}"); if(destinations.length <= 0){
return [];
}
//print("##### @@@@@ ${destinations[0].lat}");
PointLatLng origin = PointLatLng(destinations[0].lat!, destinations[0].lon!); PointLatLng origin = PointLatLng(destinations[0].lat!, destinations[0].lon!);
PointLatLng dest = PointLatLng(destinations[destinations.length -1].lat!, destinations[destinations.length -1].lon!); PointLatLng dest = PointLatLng(destinations[destinations.length -1].lat!, destinations[destinations.length -1].lon!);

View File

@ -13,6 +13,8 @@ class MatrixService{
int i = 0; int i = 0;
for(Destination d in destinations){ for(Destination d in destinations){
print("---- getting matrix for ${d} ------------");
if(i==0){ if(i==0){
origin = "${d.lat}, ${d.lon}"; origin = "${d.lat}, ${d.lon}";
} }

View File

@ -68,6 +68,12 @@ class DatabaseHelper{
return ret; return ret;
} }
Future<bool>isAlreadyAvailable(int location_id) async{
Database db = await instance.database;
var dest = await db.delete('destination', where: "location_id = ${location_id}");
return dest > 0 ? true : false;
}
Future<int> insertDestination(Destination dest) async { Future<int> insertDestination(Destination dest) async {
Database db = await instance.database; Database db = await instance.database;
int res = await db.insert( int res = await db.insert(
@ -75,6 +81,7 @@ class DatabaseHelper{
dest.toMap(), dest.toMap(),
conflictAlgorithm: ConflictAlgorithm.replace, conflictAlgorithm: ConflictAlgorithm.replace,
); );
print("------ database helper insert ${res}-----------::::::::");
return res; return res;
} }

View File

@ -132,9 +132,19 @@ class BottomSheetNew extends GetView<BottomSheetController> {
Container(width: 0.0, height: 0,), Container(width: 0.0, height: 0,),
), ),
SizedBox(height: 20.0,), SizedBox(height: 20.0,),
//Obx(() => Obx(() =>
wantToGo(context), //wantToGo(context),
//),
FutureBuilder<Widget>(
future: wantToGo(context),
builder: (context, snapshot) {
return Container(
child: snapshot.data,
);
},
),
),
SizedBox(height: 60.0,) SizedBox(height: 60.0,)
], ],
) )
@ -143,25 +153,27 @@ class BottomSheetNew extends GetView<BottomSheetController> {
} }
Widget wantToGo(BuildContext context){ Future<Widget> wantToGo(BuildContext context)async {
return Row( DatabaseHelper db = DatabaseHelper.instance;
bool isAdded = await db.isAlreadyAvailable(indexController.currentFeature[0].properties!["location_id"]);
return
isAdded == true ? Container(child: Text("すでに追加されています"),) :
Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Row( Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
ElevatedButton( ElevatedButton(
onPressed: (){ onPressed: (){
}, },
child: ElevatedButton(
child: IconButton( child: Text("want_to_go".tr),
icon: Icon(Icons.favorite, color: Colors.white, semanticLabel: "want_to_go".tr,), onPressed: (){
onPressed: ()
{
GeoJsonMultiPoint mp = indexController.currentFeature[0].geometry as GeoJsonMultiPoint; GeoJsonMultiPoint mp = indexController.currentFeature[0].geometry as GeoJsonMultiPoint;
LatLng pt = LatLng(mp.geoSerie!.geoPoints[0].latitude, mp.geoSerie!.geoPoints[0].longitude); LatLng pt = LatLng(mp.geoSerie!.geoPoints[0].latitude, mp.geoSerie!.geoPoints[0].longitude);
print("--- name---- ${indexController.currentFeature[0].properties!["location_name"]} -----");
Destination dest = Destination( Destination dest = Destination(
name: indexController.currentFeature[0].properties!["location_name"], name: indexController.currentFeature[0].properties!["location_name"],
address: indexController.currentFeature[0].properties!["address"], address: indexController.currentFeature[0].properties!["address"],
@ -181,7 +193,7 @@ class BottomSheetNew extends GetView<BottomSheetController> {
); );
destinationController.addDestinations(dest); destinationController.addDestinations(dest);
}, },
) ),
), ),
], ],
) )

View File

@ -47,10 +47,13 @@ class DestinationWidget extends StatelessWidget {
} }
void doDelete() { void doDelete() {
destinationController.destination_index_data.forEach((element) { destinationController.currentSelectedDestinations.forEach((element) {
//print(element["index"]); destinationController.deleteDestination(element);
destinationController.deleteDestination(element["index"]);
}); });
// destinationController.destination_index_data.forEach((element) {
// //print(element["index"]);
// destinationController.deleteDestination(element["index"]);
// });
// destinationController.destination_index_data.clear(); // destinationController.destination_index_data.clear();
} }
@ -83,7 +86,7 @@ class DestinationWidget extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
print("---- destinations ${destinationController.destinations[0].name} ------"); print("------ destination widget------ ${destinationController.destinationCount.value} ----------");
return return
Obx(() => Obx(() =>
@ -93,18 +96,7 @@ class DestinationWidget extends StatelessWidget {
padding: const EdgeInsets.only(top:45.0), padding: const EdgeInsets.only(top:45.0),
child: ListView.builder( child: ListView.builder(
itemCount: destinationController.destinationCount.value, itemCount: destinationController.destinationCount.value,
//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) { itemBuilder: (BuildContext context, int index) {
return return
TimelineTile( TimelineTile(
@ -142,29 +134,29 @@ class DestinationWidget extends StatelessWidget {
}; };
}, },
onLongPress: (){ onLongPress: (){
print("#### long press #### ${destinationController.destination_index_data.length}");
var match_element = null; Destination? match_element = null;
destinationController.destination_index_data.forEach((element) { destinationController.currentSelectedDestinations.forEach((element) {
if(element["index"] == index){ if(element.location_id == destinationController.destinations[index].location_id){
match_element = element; match_element = element;
print("----match----");
return; return;
} }
}); });
if(match_element != null){ if(match_element != null){
destinationController.destination_index_data.remove(match_element); destinationController.currentSelectedDestinations.remove(destinationController.destinations[index]);
return;
} }
//print("------${destinationController.destination_index_data}----");
Map<String, dynamic> indexed = {'index': index, 'selected':true}; destinationController.currentSelectedDestinations.add(destinationController.destinations[index]);
destinationController.destination_index_data.add(indexed);
destinationController.PopulateDestinations();
}, },
selectedTileColor: Colors.amberAccent, selectedTileColor: Colors.amberAccent,
selected:getSelection(index), selected:destinationController.destinations[index].selected,
leading: getImage(index), leading: getImage(index),
title: Text(destinationController.destinations[index].name!), title: Text(destinationController.destinations[index].name!),
//subtitle: Text(destinationController.destinations[index].category!), subtitle: Text(destinationController.destinations[index].category!),
), ),
), ),
), ),
@ -203,7 +195,7 @@ class DestinationWidget extends StatelessWidget {
IconButton( IconButton(
icon:Icon(Icons.cancel), icon:Icon(Icons.cancel),
//onPressed: (){doDelete();}, //onPressed: (){doDelete();},
onPressed: destinationController.destination_index_data.length > 0 ? doDelete : null, onPressed: destinationController.currentSelectedDestinations.length > 0 ? doDelete : null,
), ),
IconButton( IconButton(
icon:Icon(Icons.move_up), icon:Icon(Icons.move_up),