update buttons

This commit is contained in:
2024-03-02 11:11:46 +05:30
parent 992f9f3414
commit d55ba7cfdb
5 changed files with 177 additions and 142 deletions

View File

@ -110,9 +110,125 @@ class BottomSheetNew extends GetView<BottomSheetController> {
}
}
Widget getActionButton(BuildContext context, Destination destination) {
Destination cdest = destinationController
.festuretoDestination(indexController.currentFeature[0]);
var distance = const Distance();
double distanceToDest = distance.as(
LengthUnit.Meter,
LatLng(
destinationController.currentLat, destinationController.currentLon),
LatLng(cdest.lat!, cdest.lon!));
if (destinationController.rogainingCounted.value == true &&
destinationController.distanceToStart() <= 500 //destination.cp == -1
&&
DestinationController.ready_for_goal == true) {
//goal
return ElevatedButton(
style: ElevatedButton.styleFrom(backgroundColor: Colors.red),
onPressed: destinationController.rogainingCounted.value == true &&
destinationController.distanceToStart() <= 500 &&
//destination.cp == -1 &&
DestinationController.ready_for_goal == true
? () async {
destinationController.isAtGoal.value = true;
destinationController.photos.clear();
await showModalBottomSheet(
constraints: BoxConstraints.loose(
ui.Size(Get.width, Get.height * 0.75)),
context: Get.context!,
isScrollControlled: true,
builder: ((context) => CameraPage(
destination: destination,
))).whenComplete(() {
destinationController.skipGps = false;
destinationController.chekcs = 0;
destinationController.isAtGoal.value = false;
});
}
: null,
child: const Text(
"ロゲイニングを終える",
style: TextStyle(color: Colors.white),
));
} else if (distanceToDest <=
destinationController.getForcedChckinDistance(destination)) {
//start
return ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.secondary,
),
onPressed: () async {
// Check conditions to show confirmation dialog
if (destination.cp == -1 &&
destinationController.isInRog.value == false &&
destinationController.rogainingCounted.value == false) {
// Show confirmation dialog
Get.dialog(
AlertDialog(
title: const Text("確認"), //confirm
content: const Text(
"ロゲを開始すると、今までのロゲデータが全てクリアされます。本当に開始しますか?"), //are you sure
actions: <Widget>[
TextButton(
child: const Text("いいえ"), //no
onPressed: () {
Get.back(); // Close the dialog
},
),
TextButton(
child: const Text("はい"), //yes
onPressed: () async {
// Clear data and start game logic here
destinationController.isInRog.value = true;
destinationController
.resetRogaining(); // Assuming you have a method to clear data
destinationController.addToRogaining(
destinationController.currentLat,
destinationController.currentLon,
destination.location_id!,
);
saveGameState();
await ExternalService().startRogaining();
Get.back(); // Close the dialog and potentially navigate away
},
),
],
),
barrierDismissible:
false, // User must tap a button to close the dialog
);
} else {
// Existing logic for other conditions
if (destination.cp == -1) {
return;
}
Get.back();
await destinationController.callforCheckin(destination);
}
},
child: Text(
destination.cp == -1 &&
destinationController.isInRog.value == false &&
destinationController.rogainingCounted.value == false
? "ロゲ開始"
: destinationController.isInRog.value == true &&
destination.cp == -1
? "ゲーム中"
: isAlreadyCheckedIn == true
? "ゲーム中"
: "チェックイン",
style: TextStyle(color: Theme.of(context).colorScheme.onSecondary),
),
);
}
return Container();
}
@override
Widget build(BuildContext context) {
print("to start ${destinationController.distanceToStart()}");
//print("to start ${destinationController.distanceToStart()}");
destinationController.skipGps = true;
// print('--- c use --- ${indexController.currentUser[0].values}');
@ -207,37 +323,7 @@ class BottomSheetNew extends GetView<BottomSheetController> {
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
// Finish or Goal
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red),
onPressed: destinationController
.rogainingCounted.value ==
true &&
destinationController.distanceToStart() <=
500 &&
//destination.cp == -1 &&
DestinationController.ready_for_goal == true
? () async {
destinationController.isAtGoal.value = true;
destinationController.photos.clear();
await showModalBottomSheet(
constraints: BoxConstraints.loose(
ui.Size(
Get.width, Get.height * 0.75)),
context: Get.context!,
isScrollControlled: true,
builder: ((context) => CameraPage(
destination: destination,
))).whenComplete(() {
destinationController.skipGps = false;
destinationController.chekcs = 0;
destinationController.isAtGoal.value =
false;
});
}
: null,
child: const Text("ロゲイニングを終える")) // goal
,
getActionButton(context, destination),
//remove checkin
isAlreadyCheckedIn == true && destination.cp != -1
? ElevatedButton(
@ -250,7 +336,10 @@ class BottomSheetNew extends GetView<BottomSheetController> {
.deleteDestination(destination);
Get.back();
},
child: const Text("チェックイン取消")) //remove checkin
child: const Text(
"チェックイン取消",
style: TextStyle(color: Colors.white),
)) //remove checkin
: Container(),
],
),
@ -265,8 +354,8 @@ class BottomSheetNew extends GetView<BottomSheetController> {
onPressed: destinationController.distanceToStart() >
500
? () async {
print(
"dist to start ${destinationController.distanceToStart()}");
// print(
// "dist to start ${destinationController.distanceToStart()}");
Get.back();
//print("---- go to ----");
GeoJSONMultiPoint mp = indexController
@ -302,95 +391,6 @@ class BottomSheetNew extends GetView<BottomSheetController> {
),
// forced start / checkin
distanceToDest <=
destinationController
.getForcedChckinDistance(destination)
? Obx(() => ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor:
Theme.of(context).colorScheme.secondary,
),
onPressed: () async {
// Check conditions to show confirmation dialog
if (destination.cp == -1 &&
destinationController.isInRog.value ==
false &&
destinationController
.rogainingCounted.value ==
false) {
// Show confirmation dialog
Get.dialog(
AlertDialog(
title: const Text("確認"), //confirm
content: const Text(
"ロゲを開始すると、今までのロゲデータが全てクリアされます。本当に開始しますか?"), //are you sure
actions: <Widget>[
TextButton(
child: const Text("いいえ"), //no
onPressed: () {
Get.back(); // Close the dialog
},
),
TextButton(
child: const Text("はい"), //yes
onPressed: () async {
// Clear data and start game logic here
destinationController
.isInRog.value = true;
destinationController
.resetRogaining(); // Assuming you have a method to clear data
destinationController
.addToRogaining(
destinationController
.currentLat,
destinationController
.currentLon,
destination.location_id!,
);
saveGameState();
await ExternalService()
.startRogaining();
Get.back(); // Close the dialog and potentially navigate away
},
),
],
),
barrierDismissible:
false, // User must tap a button to close the dialog
);
} else {
// Existing logic for other conditions
if (destination.cp == -1) {
return;
}
Get.back();
await destinationController
.callforCheckin(destination);
}
},
child: Text(
destination.cp == -1 &&
destinationController
.isInRog.value ==
false &&
destinationController
.rogainingCounted.value ==
false
? "ロゲ開始"
: destinationController.isInRog.value ==
true &&
destination.cp == -1
? "ゲーム中"
: isAlreadyCheckedIn == true
? "ゲーム中"
: "チェックイン",
style: TextStyle(
color: Theme.of(context)
.colorScheme
.onSecondary),
),
))
: Container(),
],
),
Row(