update for chech in

This commit is contained in:
Mohamed Nouffer
2022-07-14 23:10:24 +05:30
parent 264cd828f4
commit 42accf9f3a
10 changed files with 532 additions and 311 deletions

View File

@ -16,7 +16,8 @@ class Destination {
String? photos;
double? checkin_radious;
int? auto_checkin;
bool selected = false;
bool? selected = false;
bool? checkedin = false;
Destination({
this.name,
@ -33,10 +34,17 @@ class Destination {
this.list_order,
this.photos,
this.checkin_radious,
this.auto_checkin
this.auto_checkin,
this.selected,
this.checkedin
});
factory Destination.fromMap(Map<String, dynamic> json) => Destination(
factory Destination.fromMap(Map<String, dynamic> json) {
bool selec = json['selected'] == 0 ? false : true;
bool checkin = json['checkedin'] == 0 ? false : true;
return Destination(
name: json['name'],
address: json['address'],
phone: json['phone'],
@ -49,12 +57,17 @@ class Destination {
lon: json['lon'],
location_id: json['location_id'],
list_order: json['list_order'],
photos: json['category'],
photos: json['photos'],
checkin_radious: json['checkin_radious'],
auto_checkin:json['auto_checkin']
auto_checkin:json['auto_checkin'],
selected: selec,
checkedin: checkin
);
}
Map<String, dynamic> toMap(){
int sel = selected == false ? 0 : 1;
int check = checkedin == false ? 0 : 1;
return {
'name':name,
'address': address,
@ -70,7 +83,9 @@ class Destination {
'list_order':list_order,
'photos':photos,
'checkin_radious': checkin_radious,
'auto_checkin': auto_checkin
'auto_checkin': auto_checkin,
'selected': sel,
'checkedin': check
};
}

View File

@ -61,6 +61,7 @@ class DestinationController extends GetxController {
}
checkForCheckin(double la, double ln){
for(final d in destinations){
double lat = d.lat!;
double lon = d.lon!;
@ -74,19 +75,10 @@ class DestinationController extends GetxController {
indexController.currentDestinationFeature.add(value);
//indexController.getAction();
if(!checking_in){
checking_in = true;
if(rad >= dist){
if(auto_checkin){
if(indexController.currentAction.isNotEmpty){
print(indexController.currentAction[0]);
indexController.currentAction[0][0]["checkin"] = true;
Map<String,dynamic> temp = Map<String,dynamic>.from(indexController.currentAction[0][0]);
indexController.currentAction.clear();
print("---temp---${temp}");
indexController.currentAction.add([temp]);
}
indexController.makeAction(Get.context!);
makeCheckin(value, true);
}
else{
showModalBottomSheet(context: Get.context!, isScrollControlled: true,
@ -96,19 +88,59 @@ class DestinationController extends GetxController {
});
}
}
}
// if(!checking_in){
// checking_in = true;
// if(rad >= dist){
// if(auto_checkin){
// if(indexController.currentAction.isNotEmpty){
// print(indexController.currentAction[0]);
// indexController.currentAction[0][0]["checkin"] = true;
// Map<String,dynamic> temp = Map<String,dynamic>.from(indexController.currentAction[0][0]);
// indexController.currentAction.clear();
// print("---temp---${temp}");
// indexController.currentAction.add([temp]);
// }
// indexController.makeAction(Get.context!);
// }
// else{
// showModalBottomSheet(context: Get.context!, isScrollControlled: true,
// builder:((context) => BottomSheetWidget())
// ).whenComplete((){
// checking_in = false;
// });
// }
// }
// }
print("----- rad is ${rad}");
});
}
}
void makeCheckin(Destination destination, bool action) async {
print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ressssss ${action}@@@@@@@@@@@");
DatabaseHelper db = DatabaseHelper.instance;
int res = await db.updateAction(destination, action);
List<Destination> ddd = await db.getDestinationByLatLon(destination.lat!, destination.lon!);
print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ddddd ${ddd[0].checkedin} @@@@@@@@@@@");
print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ressssss ${res}@@@@@@@@@@@");
PopulateDestinations();
print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ after populating ${res} @@@@@@@@@@@");
print("---- database update resulr ------ res : ${res}-------");
}
@override
void onInit() {
void onInit() async {
super.onInit();
checkPermission();
PopulateDestinations();
print("------ in iniit");
@ -146,14 +178,16 @@ class DestinationController extends GetxController {
StreamSubscription<Position> positionStream = Geolocator.getPositionStream(locationSettings: locationSettings).listen(
(Position? position) {
if(isSelected[0]){
double czoom = indexController.rogMapController!.zoom;
indexController.rogMapController!.move(LatLng(position!.latitude, position!.longitude), czoom);
if(isSelected[0]){
String user_id = indexController.currentUser[0]["user"]["id"].toString();
TrackingService.addTrack(user_id, position!.latitude, position.longitude).then((val){
//checkForCheckin(position!.latitude, position.longitude);
});
//String user_id = indexController.currentUser[0]["user"]["id"].toString();
//TrackingService.addTrack(user_id, position!.latitude, position.longitude).then((val){
print("---- postion is ${position.latitude}, ${position.longitude}");
checkForCheckin(position!.latitude, position.longitude);
//});
}
print(position == null ? 'Unknown' : 'current position is ${position.latitude.toString()}, ${position.longitude.toString()}');
@ -161,6 +195,14 @@ class DestinationController extends GetxController {
}
void checkPermission() async {
LocationPermission permission = await Geolocator.checkPermission();
if (permission != LocationPermission.whileInUse ||
permission != LocationPermission.always) {
permission = await Geolocator.requestPermission();
}
}
void deleteDestination(Destination d){
//int id = destinations[index].location_id!;
//print("---- index ${destinations[index].location_id!}-----");
@ -215,11 +257,9 @@ class DestinationController extends GetxController {
DatabaseHelper db = DatabaseHelper.instance;
db.getDestinations().then((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;
d.selected = !d.selected!;
}
}

View File

@ -90,6 +90,7 @@ class _DestinationPageState extends State<DestinationPage> {
automaticallyImplyLeading: false,
title: Text("app_title".tr),
actions: [
Obx(() =>
ToggleButtons(
disabledColor: Colors.grey.shade200,
selectedColor: Colors.red,
@ -103,10 +104,11 @@ class _DestinationPageState extends State<DestinationPage> {
},
isSelected: destinationController.isSelected,
),
IconButton(onPressed: (){
showCurrentPosition();
},
icon: Icon(Icons.location_on_outlined))
),
// IconButton(onPressed: (){
// showCurrentPosition();
// },
// icon: Icon(Icons.location_on_outlined))
],
),
body: Obx(() =>

View File

@ -159,6 +159,8 @@ class _DestinationMapPageState extends State<DestinationMapPage> {
// do something
}
if (mapEvent is MapEventMoveEnd) {
destinationController.isSelected.clear();
destinationController.isSelected.add(false);
//print(DateTime.now().toString() + ' [MapEventMoveStart] END');
//indexController.loadLocationsBound();
}

View File

@ -47,6 +47,7 @@ class IndexController extends GetxController {
var mode = 0.obs;
// master mode, rog or selection
var rog_mode = 1.obs;
var desination_mode = 1.obs;

View File

@ -34,18 +34,18 @@ class IndexPage extends GetView<IndexController> {
//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()} ---- :::::");
// };
// });
// },
// ),
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.checkedin} ---- :::::");
};
});
},
),
CatWidget(indexController: indexController,),
],
),
@ -65,7 +65,6 @@ class IndexPage extends GetView<IndexController> {
onPressed: (){
indexController.toggleMode();
if(indexController.currentCat.isNotEmpty){
print("###############");
print(indexController.currentCat[0].toString());
}

View File

@ -39,7 +39,9 @@ class DatabaseHelper{
list_order INTEGER,
photos TEXT,
checkin_radious REAL,
auto_checkin INTEGER
auto_checkin INTEGER,
selected INTEGER,
checkedin INTEGER
)
''');
}
@ -85,6 +87,20 @@ class DatabaseHelper{
return res;
}
Future<int> updateAction(Destination destination, bool checkin)async {
Database db = await instance.database;
int act = checkin == false ? 0 : 1;
Map<String, dynamic> row = {
"checkedin": act
};
return await db.update(
"destination",
row,
where: 'location_id = ?',
whereArgs: [destination.location_id]
);
}
// Future<int?> getPending() async{
// Database db = await instance.database;
// return await Sqflite.firstIntValue(await db.rawQuery("SELECT COUNT(*) FROM incidents"));

View File

@ -18,7 +18,25 @@ class BottomSheetNew extends GetView<BottomSheetController> {
final IndexController indexController = Get.find<IndexController>();
final DestinationController destinationController = Get.find<DestinationController>();
Image getImage(GeoJsonFeature? gf){
Image getImage(){
if(indexController.rog_mode == 1){
if(indexController.currentDestinationFeature.length <= 0 || indexController.currentDestinationFeature[0].photos! == ""){
return Image(image: AssetImage('assets/images/empty_image.png'));
}
else{
print("@@@@@@@@@@@@@ rog mode -------------------- ${indexController.currentDestinationFeature[0].photos} @@@@@@@@@@@");
return Image(image: NetworkImage(
indexController.currentDestinationFeature[0].photos!,
),
errorBuilder: (BuildContext context, Object exception, StackTrace? stackTrace) {
return Image.asset("assets/images/empty_image.png");
},
);
}
}
else{
GeoJsonFeature<dynamic> gf = indexController.currentFeature[0];
if(gf!.properties!["photos"] == null || gf.properties!["photos"] == ""){
return Image(image: AssetImage('assets/images/empty_image.png'));
}
@ -33,15 +51,134 @@ class BottomSheetNew extends GetView<BottomSheetController> {
}
}
}
void _launchURL(url) async {
if (!await launch(url)) throw 'Could not launch $url';
}
@override
Widget build(BuildContext context) {
return Wrap(
return indexController.rog_mode == 0 ? detailsSheet(context) : destinationSheet(context);
}
SingleChildScrollView destinationSheet(BuildContext context) {
return SingleChildScrollView(
child: Column(
children: [
Column(
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
child: Row(
children: [
MaterialButton(
onPressed: () {
indexController.makePrevious(indexController.currentFeature[0]);
},
color: Colors.blue,
textColor: Colors.white,
child: Icon(
Icons.arrow_back_ios,
size: 14,
),
padding: EdgeInsets.all(16),
shape: CircleBorder(),
),
Expanded(
child: Container(
alignment: Alignment.center,
child: Obx(() =>
Text(indexController.currentDestinationFeature[0].name!, style: TextStyle(
fontSize: 15.0,
fontWeight: FontWeight.bold,
),
)
),
),
),
MaterialButton(
onPressed: () {
print("----- next is ${indexController.currentFeature[0]} ------");
//indexController.makeNext(indexController.currentFeature[0]);
},
color: Colors.blue,
textColor: Colors.white,
child: Icon(
Icons.arrow_forward_ios,
size: 14,
),
padding: EdgeInsets.all(16),
shape: CircleBorder(),
),
],
),
),
),
Row(
children: [
Expanded(
child: SizedBox(
height: 260.0,
child: Obx(() => getImage()),
)
),
],
),
Obx(() =>
indexController.currentDestinationFeature[0].address!.isNotEmpty ?
getDetails(context, "address".tr, indexController.currentDestinationFeature[0].address! ?? '')
:
Container(width: 0.0, height: 0,),
),
Obx(() =>
indexController.currentDestinationFeature[0].phone!.isNotEmpty ?
getDetails(context, "telephone".tr, indexController.currentDestinationFeature[0].phone! ?? '')
:
Container(width: 0.0, height: 0,),
),
Obx(() =>
indexController.currentDestinationFeature[0].email!.isNotEmpty ?
getDetails(context, "email".tr, indexController.currentDestinationFeature[0].email! ?? '')
:
Container(width: 0.0, height: 0,),
),
Obx(() =>
indexController.currentDestinationFeature[0].webcontents!.isNotEmpty ?
getDetails(context, "web".tr, indexController.currentDestinationFeature[0].webcontents! ?? '', isurl: true)
:
Container(width: 0.0, height: 0,),
),
Obx(() =>
indexController.currentDestinationFeature[0].videos!.isNotEmpty ?
getDetails(context, "video".tr, indexController.currentDestinationFeature[0].videos! ?? '', isurl: true)
:
Container(width: 0.0, height: 0,),
),
SizedBox(height: 20.0,),
Obx(() =>
//wantToGo(context),
FutureBuilder<Widget>(
future: wantToGo(context),
builder: (context, snapshot) {
return Container(
child: snapshot.data,
);
},
),
),
SizedBox(height: 60.0,)
],
),
);
}
SingleChildScrollView detailsSheet(BuildContext context) {
return SingleChildScrollView(
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
@ -96,38 +233,38 @@ class BottomSheetNew extends GetView<BottomSheetController> {
Expanded(
child: SizedBox(
height: 260.0,
child: Obx(() => getImage(indexController.currentFeature[0])),
child: Obx(() => getImage()),
)
),
],
),
Obx(() =>
(indexController.currentFeature[0].properties!["address"] as String).isNotEmpty ?
getDetails("address".tr, indexController.currentFeature[0].properties!["address"] ?? '')
getDetails(context, "address".tr, indexController.currentFeature[0].properties!["address"] ?? '')
:
Container(width: 0.0, height: 0,),
),
Obx(() =>
(indexController.currentFeature[0].properties!["phone"] as String).isNotEmpty ?
getDetails("telephone".tr, indexController.currentFeature[0].properties!["phone"] ?? '')
getDetails(context, "telephone".tr, indexController.currentFeature[0].properties!["phone"] ?? '')
:
Container(width: 0.0, height: 0,),
),
Obx(() =>
(indexController.currentFeature[0].properties!["email"] as String).isNotEmpty ?
getDetails("email".tr, indexController.currentFeature[0].properties!["email"] ?? '')
getDetails(context, "email".tr, indexController.currentFeature[0].properties!["email"] ?? '')
:
Container(width: 0.0, height: 0,),
),
Obx(() =>
(indexController.currentFeature[0].properties!["webcontents"] as String).isNotEmpty ?
getDetails("web".tr, indexController.currentFeature[0].properties!["webcontents"] ?? '', isurl: true)
getDetails(context, "web".tr, indexController.currentFeature[0].properties!["webcontents"] ?? '', isurl: true)
:
Container(width: 0.0, height: 0,),
),
Obx(() =>
(indexController.currentFeature[0].properties!["videos"] as String).isNotEmpty ?
getDetails("video".tr, indexController.currentFeature[0].properties!["videos"] ?? '', isurl: true)
getDetails(context, "video".tr, indexController.currentFeature[0].properties!["videos"] ?? '', isurl: true)
:
Container(width: 0.0, height: 0,),
),
@ -147,28 +284,25 @@ class BottomSheetNew extends GetView<BottomSheetController> {
),
SizedBox(height: 60.0,)
],
)
],
),
);
}
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: [
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: [
indexController.rog_mode == 0 ?
ElevatedButton(
onPressed: (){
},
child: ElevatedButton(
child: Text("want_to_go".tr),
onPressed: (){
GeoJsonMultiPoint mp = indexController.currentFeature[0].geometry as GeoJsonMultiPoint;
@ -189,12 +323,36 @@ class BottomSheetNew extends GetView<BottomSheetController> {
list_order: 1,
photos: indexController.currentFeature[0].properties!["photos"],
checkin_radious: indexController.currentFeature[0].properties!["checkin_radious"],
auto_checkin: indexController.currentFeature[0].properties!["auto_checkin"] == true ? 1 : 0
auto_checkin: indexController.currentFeature[0].properties!["auto_checkin"] == true ? 1 : 0,
selected: false,
checkedin: false
);
destinationController.addDestinations(dest);
},
),
),
):
Container(),
SizedBox(width: 20.0,) ,
Obx((() =>
indexController.rog_mode == 1 ?
ElevatedButton(
onPressed: () async {
Destination dest = indexController.currentDestinationFeature[0]!;
//print("------ curent destination is ${dest!.checkedIn}-------");
if(dest != null){
print("------ curent destination is ${dest!.checkedin}-------::::::::::");
destinationController.makeCheckin(dest, !dest.checkedin!);
}
},
child: indexController.currentDestinationFeature[0].checkedin == false ?
Text("Check in")
:
Text("Check out")
):
Container()
)
)
],
)
],
@ -208,8 +366,7 @@ class BottomSheetNew extends GetView<BottomSheetController> {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Flexible(
child: Row(
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
indexController.currentAction[0][0]["checkin"] == false ?
@ -264,7 +421,6 @@ class BottomSheetNew extends GetView<BottomSheetController> {
,
)
],
),
)
],
);
@ -386,45 +542,36 @@ class BottomSheetNew extends GetView<BottomSheetController> {
);
}
Widget getDetails(String label, String text, {bool isurl=false}){
Widget getDetails(BuildContext context, String label, String text, {bool isurl=false}){
return Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Flexible(
flex: 1,
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(label),
],
),
),
SizedBox(width: 10.0,),
Flexible(
flex: 3,
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Expanded(
child: InkWell(
onTap: (){
if(isurl){
if(indexController.rog_mode == 0){
_launchURL(indexController.currentFeature[0].properties!["webcontents"]);
}
else {
indexController.currentDestinationFeature[0].webcontents;
}
}
},
child: Text(text,
style: TextStyle(
color: Colors.blue,
),
softWrap: true,
overflow: TextOverflow.fade,
overflow: TextOverflow.ellipsis,
maxLines: 5,
),
),
),
],
),
),
],
);
}

View File

@ -24,6 +24,7 @@ class DestinationWidget extends StatelessWidget {
return Image(image: AssetImage('assets/images/empty_image.png'));
}
else{
print("------- image is ${destinationController.destinations[index].photos!}------");
return Image(image: NetworkImage(
destinationController.destinations[index].photos!),
errorBuilder: (BuildContext context, Object exception, StackTrace? stackTrace) {
@ -115,12 +116,11 @@ class DestinationWidget extends StatelessWidget {
child: ListTile(
onTap: () async {
{
double lat = destinationController.destinations[index].lat as double;
double lon = destinationController.destinations[index].lon as double;
Destination? fs = await destinationController.getDEstinationForLatLong(lat, lon);
Destination? fs = destinationController.destinations[index];
print("----fsf-----${fs}");
if(fs != null){
if(indexController.currentFeature.length > 0) {
if(indexController.currentDestinationFeature.length > 0) {
indexController.currentDestinationFeature.clear();
}
indexController.currentDestinationFeature.add(fs);
@ -153,7 +153,7 @@ class DestinationWidget extends StatelessWidget {
},
selectedTileColor: Colors.amberAccent,
selected:destinationController.destinations[index].selected,
selected:destinationController.destinations[index].selected!,
leading: getImage(index),
title: Text(destinationController.destinations[index].name!),
subtitle: Text(destinationController.destinations[index].category!),
@ -161,12 +161,12 @@ class DestinationWidget extends StatelessWidget {
),
),
startChild:
destinationController.matrix["rows"] != null ?
destinationController.matrix["rows"][0]["elements"] != null ?
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())
//Text(destinationController.matrix["rows"][0]["elements"][index]["distance"]["text"].toString()),
//Text(destinationController.matrix["rows"][0]["elements"][index]["duration"]["text"].toString())
],
):
Container()

View File

@ -136,10 +136,9 @@ class MapWidget extends StatelessWidget {
GeoJsonFeature? fs = indexController.getFeatureForLatLong(marker.point.latitude, marker.point.longitude);
//print("------- fs ${fs}------");
if(fs != null){
if(indexController.currentFeature.length > 0) {
indexController.currentFeature.clear();
}
indexController.currentFeature.add(fs);
//print("----- fs is ${fs.properties!['photos']}");
indexController.getAction();
showModalBottomSheet(