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;
double? checkin_radious;
int? auto_checkin;
bool selected = false;
Destination({
this.name,

View File

@ -27,6 +27,8 @@ class DestinationController extends GetxController {
List<Destination> destinations = <Destination>[].obs;
List<Map<String, dynamic>> destination_index_data = <Map<String, dynamic>>[].obs;
List<Destination> currentSelectedDestinations = <Destination>[].obs;
bool checking_in = false;
List<bool> 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);

View File

@ -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){

View File

@ -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<IndexController> {
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,),
],
),

View File

@ -67,8 +67,12 @@ class DestinationService{
static Future<List<PointLatLng>>? getDestinationLine(List<Destination> 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!);

View File

@ -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}";
}

View File

@ -68,6 +68,12 @@ class DatabaseHelper{
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 {
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;
}

View File

@ -132,9 +132,19 @@ class BottomSheetNew extends GetView<BottomSheetController> {
Container(width: 0.0, height: 0,),
),
SizedBox(height: 20.0,),
//Obx(() =>
wantToGo(context),
//),
Obx(() =>
//wantToGo(context),
FutureBuilder<Widget>(
future: wantToGo(context),
builder: (context, snapshot) {
return Container(
child: snapshot.data,
);
},
),
),
SizedBox(height: 60.0,)
],
)
@ -143,25 +153,27 @@ class BottomSheetNew extends GetView<BottomSheetController> {
}
Widget wantToGo(BuildContext context){
return Row(
Future<Widget> 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<BottomSheetController> {
);
destinationController.addDestinations(dest);
},
)
),
),
],
)

View File

@ -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<String, dynamic> 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),