From 264cd828f4085c6a97ed33efa8b2c74155caf88f Mon Sep 17 00:00:00 2001 From: Mohamed Nouffer Date: Sun, 10 Jul 2022 23:50:43 +0530 Subject: [PATCH] update for travelmode change bug fixes --- lib/model/destination.dart | 1 + .../destination/destination_controller.dart | 45 +++++++++++----- lib/pages/index/index_controller.dart | 6 +++ lib/pages/index/index_page.dart | 28 +++++++--- lib/services/destination_service.dart | 6 ++- lib/services/maxtrix_service.dart | 2 + lib/utils/database_helper.dart | 7 +++ lib/widgets/bottom_sheet_new.dart | 36 ++++++++----- lib/widgets/destination_widget.dart | 52 ++++++++----------- 9 files changed, 121 insertions(+), 62 deletions(-) diff --git a/lib/model/destination.dart b/lib/model/destination.dart index b5e6a24..f5fafc3 100644 --- a/lib/model/destination.dart +++ b/lib/model/destination.dart @@ -16,6 +16,7 @@ class Destination { String? photos; double? checkin_radious; int? auto_checkin; + bool selected = false; Destination({ this.name, diff --git a/lib/pages/destination/destination_controller.dart b/lib/pages/destination/destination_controller.dart index 81804ba..940a718 100644 --- a/lib/pages/destination/destination_controller.dart +++ b/lib/pages/destination/destination_controller.dart @@ -27,6 +27,8 @@ class DestinationController extends GetxController { List destinations = [].obs; List> destination_index_data = >[].obs; + List currentSelectedDestinations = [].obs; + bool checking_in = false; List isSelected = [true].obs; BuildContext? context; @@ -159,12 +161,17 @@ class DestinationController extends GetxController { } - void deleteDestination(int index){ - print("---- index ${index}-----"); - int id = destinations[index].location_id!; + void deleteDestination(Destination d){ + //int id = 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; - db.deleteDestination(id).then((value){ + db.deleteDestination(d.location_id!).then((value){ PopulateDestinations(); }); // DestinationService.deleteDestination(id).then((val){ @@ -178,36 +185,50 @@ class DestinationController extends GetxController { void addDestinations(Destination dest){ + print('------ destination controller in add destination ${dest.name} ---- :::::'); + DatabaseHelper db = DatabaseHelper.instance; db.getDestinationByLatLon(dest.lat!, dest.lon!).then((value){ - //print("----- available destination for latlon $value[0]"); if(value.isNotEmpty){ db.deleteDestination(value[0].location_id!).then((value){ db.insertDestination(dest).then((value){ - print("----- delete andinserted destination id $value"); + print("----- destination controller deleted and inserted destination id $value ---- :::::"); + PopulateDestinations(); }); }); } else { db.insertDestination(dest).then((value){ - print("----- new inserted destination id $value"); + print("----- destination controller added as new ${value}--- :::::"); + PopulateDestinations(); }); } }); - PopulateDestinations(); } void PopulateDestinations(){ - print("--------- populsting destinations -----------"); + print("--------- destination controller populsting destinations ----------- ::::::"); + destinations.clear(); + destinationCount.value = 0; DatabaseHelper db = DatabaseHelper.instance; db.getDestinations().then((value){ - destinations.clear(); - destinations = value; + for(Destination d in 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; - print("------destinationcount-------- ${destinationCount}--------"); destinationCount.value = destinations.length; + print("------ destination controller destinationcount-------- ${destinationCount}-------- :::::"); + MatrixService.getDestinations(value).then((mat){ print(mat); diff --git a/lib/pages/index/index_controller.dart b/lib/pages/index/index_controller.dart index d3db1e2..c92ef65 100644 --- a/lib/pages/index/index_controller.dart +++ b/lib/pages/index/index_controller.dart @@ -51,6 +51,8 @@ class IndexController extends GetxController { var desination_mode = 1.obs; + bool showPopup = true; + String dropdownValue = "9"; String subDropdownValue = "-1"; @@ -372,6 +374,9 @@ void login(String email, String password, BuildContext context){ } locations.clear(); if(value != null && value.collection.isEmpty){ + if(showPopup == false) { + return; + } Get.snackbar( "Too many Points", "please zoom in", @@ -381,6 +386,7 @@ void login(String email, String password, BuildContext context){ backgroundColor: Colors.yellow, //icon:Image(image:AssetImage("assets/images/dora.png")) ); + showPopup = false; //Get.showSnackbar(GetSnackBar(message: "Too many points, please zoom in",)); } if(value != null && value.collection.isNotEmpty){ diff --git a/lib/pages/index/index_page.dart b/lib/pages/index/index_page.dart index b98a47c..8bc2e0f 100644 --- a/lib/pages/index/index_page.dart +++ b/lib/pages/index/index_page.dart @@ -2,10 +2,12 @@ import 'dart:ui'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; +import 'package:rogapp/model/destination.dart'; import 'package:rogapp/pages/drawer/drawer_page.dart'; import 'package:rogapp/pages/index/index_controller.dart'; import 'package:rogapp/routes/app_pages.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/cat_widget.dart'; import 'package:rogapp/widgets/list_widget.dart'; @@ -23,15 +25,27 @@ class IndexPage extends GetView { return Scaffold( drawer: const DrawerPage(), appBar: AppBar( - leading: IconButton( - icon: Icon(Icons.arrow_back_ios), - onPressed: (){ - indexController.switchPage(AppPages.TRAVEL); - }, - ), - automaticallyImplyLeading: false, + // leading: IconButton( + // icon: Icon(Icons.arrow_back_ios), + // onPressed: (){ + // indexController.switchPage(AppPages.TRAVEL); + // }, + // ), + //automaticallyImplyLeading: false, title: Text("Add locations"), 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,), ], ), diff --git a/lib/services/destination_service.dart b/lib/services/destination_service.dart index ae86711..525b1c7 100644 --- a/lib/services/destination_service.dart +++ b/lib/services/destination_service.dart @@ -67,8 +67,12 @@ class DestinationService{ static Future>? getDestinationLine(List destinations) async{ PolylinePoints polylinePoints = PolylinePoints(); + + if(destinations.length <= 0){ + return []; + } - print("##### @@@@@ ${destinations[0].lat}"); + //print("##### @@@@@ ${destinations[0].lat}"); PointLatLng origin = PointLatLng(destinations[0].lat!, destinations[0].lon!); PointLatLng dest = PointLatLng(destinations[destinations.length -1].lat!, destinations[destinations.length -1].lon!); diff --git a/lib/services/maxtrix_service.dart b/lib/services/maxtrix_service.dart index 5c7c168..acc7aa9 100644 --- a/lib/services/maxtrix_service.dart +++ b/lib/services/maxtrix_service.dart @@ -13,6 +13,8 @@ class MatrixService{ int i = 0; for(Destination d in destinations){ + print("---- getting matrix for ${d} ------------"); + if(i==0){ origin = "${d.lat}, ${d.lon}"; } diff --git a/lib/utils/database_helper.dart b/lib/utils/database_helper.dart index 3004752..e33cdbe 100644 --- a/lib/utils/database_helper.dart +++ b/lib/utils/database_helper.dart @@ -68,6 +68,12 @@ class DatabaseHelper{ return ret; } + FutureisAlreadyAvailable(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 insertDestination(Destination dest) async { Database db = await instance.database; int res = await db.insert( @@ -75,6 +81,7 @@ class DatabaseHelper{ dest.toMap(), conflictAlgorithm: ConflictAlgorithm.replace, ); + print("------ database helper insert ${res}-----------::::::::"); return res; } diff --git a/lib/widgets/bottom_sheet_new.dart b/lib/widgets/bottom_sheet_new.dart index 980a670..0b1b4ab 100644 --- a/lib/widgets/bottom_sheet_new.dart +++ b/lib/widgets/bottom_sheet_new.dart @@ -132,9 +132,19 @@ class BottomSheetNew extends GetView { Container(width: 0.0, height: 0,), ), SizedBox(height: 20.0,), - //Obx(() => - wantToGo(context), - //), + Obx(() => + //wantToGo(context), + + FutureBuilder( + future: wantToGo(context), + builder: (context, snapshot) { + return Container( + child: snapshot.data, + ); + }, + ), + + ), SizedBox(height: 60.0,) ], ) @@ -143,25 +153,27 @@ class BottomSheetNew extends GetView { } - Widget wantToGo(BuildContext context){ - return Row( + Future wantToGo(BuildContext context)async { + 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, children: [ Row( mainAxisAlignment: MainAxisAlignment.center, children: [ + ElevatedButton( onPressed: (){ }, - - child: IconButton( - icon: Icon(Icons.favorite, color: Colors.white, semanticLabel: "want_to_go".tr,), - onPressed: () - { + child: ElevatedButton( + child: Text("want_to_go".tr), + onPressed: (){ GeoJsonMultiPoint mp = indexController.currentFeature[0].geometry as GeoJsonMultiPoint; LatLng pt = LatLng(mp.geoSerie!.geoPoints[0].latitude, mp.geoSerie!.geoPoints[0].longitude); - print("--- name---- ${indexController.currentFeature[0].properties!["location_name"]} -----"); Destination dest = Destination( name: indexController.currentFeature[0].properties!["location_name"], address: indexController.currentFeature[0].properties!["address"], @@ -181,7 +193,7 @@ class BottomSheetNew extends GetView { ); destinationController.addDestinations(dest); }, - ) + ), ), ], ) diff --git a/lib/widgets/destination_widget.dart b/lib/widgets/destination_widget.dart index f5c91d3..092f3d6 100644 --- a/lib/widgets/destination_widget.dart +++ b/lib/widgets/destination_widget.dart @@ -47,10 +47,13 @@ class DestinationWidget extends StatelessWidget { } void doDelete() { - destinationController.destination_index_data.forEach((element) { - //print(element["index"]); - destinationController.deleteDestination(element["index"]); + destinationController.currentSelectedDestinations.forEach((element) { + destinationController.deleteDestination(element); }); + // destinationController.destination_index_data.forEach((element) { + // //print(element["index"]); + // destinationController.deleteDestination(element["index"]); + // }); // destinationController.destination_index_data.clear(); } @@ -83,7 +86,7 @@ class DestinationWidget extends StatelessWidget { @override Widget build(BuildContext context) { - print("---- destinations ${destinationController.destinations[0].name} ------"); + print("------ destination widget------ ${destinationController.destinationCount.value} ----------"); return Obx(() => @@ -93,18 +96,7 @@ class DestinationWidget extends StatelessWidget { padding: const EdgeInsets.only(top:45.0), child: ListView.builder( 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) { return TimelineTile( @@ -142,29 +134,29 @@ class DestinationWidget extends StatelessWidget { }; }, onLongPress: (){ - print("#### long press #### ${destinationController.destination_index_data.length}"); - - var match_element = null; - destinationController.destination_index_data.forEach((element) { - if(element["index"] == index){ + + Destination? match_element = null; + destinationController.currentSelectedDestinations.forEach((element) { + if(element.location_id == destinationController.destinations[index].location_id){ match_element = element; - print("----match----"); return; } }); + if(match_element != null){ - destinationController.destination_index_data.remove(match_element); - return; + destinationController.currentSelectedDestinations.remove(destinationController.destinations[index]); } - //print("------${destinationController.destination_index_data}----"); - Map indexed = {'index': index, 'selected':true}; - destinationController.destination_index_data.add(indexed); + + destinationController.currentSelectedDestinations.add(destinationController.destinations[index]); + + destinationController.PopulateDestinations(); + }, selectedTileColor: Colors.amberAccent, - selected:getSelection(index), + selected:destinationController.destinations[index].selected, leading: getImage(index), 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( icon:Icon(Icons.cancel), //onPressed: (){doDelete();}, - onPressed: destinationController.destination_index_data.length > 0 ? doDelete : null, + onPressed: destinationController.currentSelectedDestinations.length > 0 ? doDelete : null, ), IconButton( icon:Icon(Icons.move_up),