Fixed Location & Storage issues

This commit is contained in:
2024-05-25 11:05:02 +09:00
parent e55674e1b9
commit 6a49aed98d
861 changed files with 80074 additions and 402 deletions

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:rogapp/widgets/GameState/Colors.dart';
class GameStatusIndicator extends StatelessWidget {
@ -15,7 +16,7 @@ class GameStatusIndicator extends StatelessWidget {
IconData iconData =
gameStarted ? Icons.stop_circle : Icons.play_circle_filled;
// Text to show based on the game status
String text = gameStarted ? 'ゲーム中' : 'ゲーム前';
String text = gameStarted ? 'in_game'.tr : 'start_game'.tr;
// Layout for minimized view
if (minimized) {

View File

@ -36,6 +36,8 @@ class BottomSheetNew extends GetView<BottomSheetController> {
final Destination destination; // 目的地オブジェクト
final bool isAlreadyCheckedIn; // すでにチェックイン済みかどうかのフラグ
final RxBool isButtonDisabled = false.obs;
// 目的地の画像を取得するためのメソッドです。
// indexController.rogModeの値に基づいて、適切な画像を返します。画像が見つからない場合は、デフォルトの画像を返します。
//
@ -139,7 +141,6 @@ class BottomSheetNew extends GetView<BottomSheetController> {
destinationController.photos.add(tempFile);
}
// アクションボタン(チェックイン、ゴールなど)を表示するためのメソッドです。
// 現在の状態に基づいて、適切なボタンを返します。
// ボタンがタップされたときの処理も含まれています。
@ -153,6 +154,7 @@ class BottomSheetNew extends GetView<BottomSheetController> {
// ...2024-04-03 Akira デバッグモードのみ出力するようにした。
*/
// bool isInRog=false;
Destination cdest = destinationController
.festuretoDestination(indexController.currentFeature[0]);
var distance = const Distance();
@ -164,66 +166,70 @@ class BottomSheetNew extends GetView<BottomSheetController> {
// Check conditions to show confirmation dialog
if (destinationController.isInRog.value == false &&
(destinationController.distanceToStart() <= 500 || destinationController.isGpsSignalWeak() ) && //追加 Akira 2024-4-5
(destinationController.distanceToStart() <= 100 || destinationController.isGpsSignalWeak() ) && //追加 Akira 2024-4-5
(destination.cp == -1 || destination.cp == 0 ) &&
destinationController.rogainingCounted.value == false) {
// ゲームが始まってなければ
return ElevatedButton(
return Obx(() {
final isInRog = destinationController.isInRog.value;
return ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.secondary,
),
onPressed: destinationController.isInRog.value == false &&
(destinationController.distanceToStart() <= 100 || destinationController.isGpsSignalWeak() ) && //追加 Akira 2024-4-5
(destination.cp == -1 || destination.cp == 0 ) &&
destinationController.rogainingCounted.value == false ? () async {
// Show confirmation dialog
Get.dialog(
AlertDialog(
title: Text("confirm".tr), //confirm
content: Text(
"clear_rog_data_message".tr), //are you sure
actions: <Widget>[
TextButton(
child: Text("no".tr), //no
onPressed: () {
Get.back(); // Close the dialog
},
),
TextButton(
child: Text("yes".tr), //yes
onPressed: () async {
onPressed: destinationController.isInRog.value
? null
: () async {
destinationController.isInRog.value = true;
await saveTemporaryImage(destination);
// Clear data and start game logic here
destinationController.isInRog.value = true;
destinationController.resetRogaining();
// Show confirmation dialog
Get.dialog(
AlertDialog(
title: Text("confirm".tr), //confirm
content: Text(
"clear_rog_data_message".tr), //are you sure
actions: <Widget>[
TextButton(
child: Text("no".tr), //no
onPressed: () {
// ダイアログをキャンセルした場合はボタンを再度有効化
destinationController.isInRog.value = false;
Get.back(); // Close the dialog
},
),
TextButton(
child: Text("yes".tr), //yes
onPressed: () async {
destinationController.isInRog.value = true;
await saveTemporaryImage(destination);
destinationController.addToRogaining(
destinationController.currentLat,
destinationController.currentLon,
destination.location_id!,
);
// Clear data and start game logic here
destinationController.resetRogaining();
saveGameState();
await ExternalService().startRogaining();
Get.back(); // Close the dialog and potentially navigate away
},
),
],
),
barrierDismissible:
false, // User must tap a button to close the dialog
);
}
: null,
child: Obx(
()=> Text(
destinationController.isInRog.value ? 'in_game'.tr : 'start_rogaining'.tr,
style: TextStyle(color: Colors.white),
),
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
);
},
child: Text(
isInRog ? 'in_game'.tr : 'start_rogaining'.tr,
style: TextStyle(color: Colors.white),
),
);
});
//print("counted ${destinationController.rogainingCounted.value}");
@ -418,11 +424,9 @@ class BottomSheetNew extends GetView<BottomSheetController> {
LogManager().addLog(
"current point : ${destinationController.currentLat}, ${destinationController.currentLon} - ${DateTime.now().hour}:${DateTime.now().minute}:${DateTime.now().second}:${DateTime.now().microsecond}");
//LogManager().addLog("is already checked in : $isAlreadyCheckedIn");
LogManager().addLog("Checkin radius : ${destination.checkin_radious}");
LogManager().addLog("--${destination.cp}--");
return SingleChildScrollView(
child: Column(
children: [
@ -433,7 +437,6 @@ class BottomSheetNew extends GetView<BottomSheetController> {
MaterialButton(
onPressed: () {
Get.back();
//indexController.makePrevious(indexController.currentFeature[0]);
},
color: Colors.blue,
textColor: Colors.white,
@ -441,7 +444,6 @@ class BottomSheetNew extends GetView<BottomSheetController> {
shape: const CircleBorder(),
child: const Icon(
Icons.arrow_back_ios,
//Icons.arrow_back_ios,
size: 14,
),
),
@ -449,14 +451,12 @@ class BottomSheetNew extends GetView<BottomSheetController> {
child: Container(
alignment: Alignment.centerLeft,
child: Obx(() => Text(
"${TextUtils.getDisplayTextFeture(indexController.currentFeature[0])} : ${indexController.currentFeature[0].properties!["location_name"]}",
// indexController
// .currentFeature[0].properties!["location_name"],
style: const TextStyle(
fontSize: 15.0,
fontWeight: FontWeight.bold,
),
)),
"${TextUtils.getDisplayTextFeture(indexController.currentFeature[0])} : ${indexController.currentFeature[0].properties!["location_name"]}",
style: const TextStyle(
fontSize: 15.0,
fontWeight: FontWeight.bold,
),
)),
),
),
],
@ -466,287 +466,306 @@ class BottomSheetNew extends GetView<BottomSheetController> {
children: [
Expanded(
child: SizedBox(
height: 260.0,
child: Obx(() => getImage()),
)),
height: 260.0,
child: Obx(() => getImage()),
)),
],
),
Obx(() => Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
// Finish or Goal
getActionButton(context, destination),
//remove checkin
isAlreadyCheckedIn == true && destination.cp != 0 && destination.cp != -1 && destination.cp != -2
? ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blueAccent),
onPressed: () async {
try {
await destinationController
.removeCheckin(destination.cp!.toInt());
destinationController
.deleteDestination(destination);
Get.back();
Get.snackbar(
'チェックイン取り消し',
'${destination
.name}のチェックインは取り消されました',
backgroundColor: Colors.green,
colorText: Colors.white,
duration: Duration(seconds: 3),
);
} catch (e ) {
// エラーハンドリング
Get.snackbar(
'Error',
'An error occurred while canceling check-in.',
backgroundColor: Colors.red,
colorText: Colors.white,
duration: Duration(seconds: 3),
);
// 必要に応じてエラーログを記録
print('Error canceling check-in: $e');
}
},
child: Text(
"cancel_checkin".tr,
style: TextStyle(color: Colors.white),
)) //remove checkin
: Container(),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context)
.colorScheme
.onPrimaryContainer),
onPressed: () async {
// print(
// "dist to start ${destinationController.distanceToStart()}");
Get.back();
//print("---- go to ----");
// GeoJSONMultiPoint mp = indexController
// .currentFeature[0] as GeoJSONMultiPoint;
Position position =
await Geolocator.getCurrentPosition(
desiredAccuracy:
LocationAccuracy.bestForNavigation,
forceAndroidLocationManager: true);
//print("------- position -------- $position");
Destination ds = Destination(
lat: position.latitude,
lon: position.longitude);
Destination tp = Destination(
lat: destination.lat, lon: destination.lon);
destinationController
.destinationMatrixFromCurrentPoint([ds, tp]);
},
//go here
child: Text(
"go_here".tr,
style: TextStyle(
color:
Theme.of(context).colorScheme.onPrimary),
)),
const SizedBox(
width: 10,
),
// forced start / checkin
],
),
Row(
children: [
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
indexController.currentDestinationFeature
.isNotEmpty &&
destinationController.isInCheckin.value ==
true
? Container()
: FutureBuilder<Widget>(
future: wantToGo(context),
builder: (context, snapshot) {
return Container(
child: snapshot.data,
);
},
),
indexController.currentFeature[0]
.properties!["location_name"] !=
null &&
(indexController.currentFeature[0]
.properties!["location_name"]
as String)
.isNotEmpty
? Flexible(
child: Text(indexController
.currentFeature[0]
.properties!["location_name"]))
: const SizedBox(
width: 0.0,
height: 0,
),
],
),
),
],
),
const SizedBox(
height: 8.0,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
const Icon(Icons.roundabout_left),
const SizedBox(
width: 8.0,
),
indexController.currentFeature[0]
.properties!["address"] !=
null &&
(indexController.currentFeature[0]
.properties!["address"] as String)
.isNotEmpty
? getDetails(
context,
"address".tr,
indexController.currentFeature[0]
.properties!["address"] ??
'')
: const SizedBox(
width: 0.0,
height: 0,
),
],
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
const Icon(Icons.phone),
const SizedBox(
width: 8.0,
),
indexController.currentFeature[0]
.properties!["phone"] !=
null &&
(indexController.currentFeature[0]
.properties!["phone"] as String)
.isNotEmpty
? getDetails(
context,
"telephone".tr,
indexController.currentFeature[0]
.properties!["phone"] ??
'')
: const SizedBox(
width: 0.0,
height: 0,
),
],
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
const Icon(Icons.email),
const SizedBox(
width: 8.0,
),
indexController.currentFeature[0]
.properties!["email"] !=
null &&
(indexController.currentFeature[0]
.properties!["email"] as String)
.isNotEmpty
? getDetails(
context,
"email".tr,
indexController.currentFeature[0]
.properties!["email"] ??
'')
: const SizedBox(
width: 0.0,
height: 0,
),
],
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
const Icon(Icons.language),
const SizedBox(
width: 8.0,
),
indexController.currentFeature[0]
.properties!["webcontents"] !=
null &&
(indexController.currentFeature[0]
.properties!["webcontents"] as String)
.isNotEmpty
? getDetails(
context,
"web".tr,
indexController.currentFeature[0]
.properties!["webcontents"] ??
'',
isurl: true)
: const SizedBox(
width: 0.0,
height: 0,
),
],
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
const SizedBox(
width: 8.0,
),
indexController.currentFeature[0]
.properties!["remark"] !=
null &&
(indexController.currentFeature[0]
.properties!["remark"] as String)
.isNotEmpty
? getDetails(
context,
"remarks".tr,
indexController.currentFeature[0]
.properties!["remark"] ??
'',
isurl: false)
: const SizedBox(
width: 0.0,
height: 0,
),
],
),
),
// Text('${TextUtils.getDisplayText(indexController.currentFeature[0].properties!["cp"].toString())} - id: ${TextUtils.getDisplayText(indexController.currentFeature[0].properties!["checkin_point"].toString())}'),
// Finish or Goal
(destination.cp == -1 || destination.cp == 0)
? getActionButton(context, destination)
: Container(),
],
),
)),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
//checkin or remove checkin
destinationController.isInRog.value == true && destination.cp != 0 && destination.cp != -1 && destination.cp != -2
? (isAlreadyCheckedIn == false
? ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red),
onPressed: () async {
try {
await destinationController.callforCheckin(destination);
} catch (e) {
// エラーハンドリング
Get.snackbar(
'Error',
'An error occurred while processing check-in.',
backgroundColor: Colors.red,
colorText: Colors.white,
duration: Duration(seconds: 3),
);
// 必要に応じてエラーログを記録
print('Error processing check-in: $e');
}
},
child: Text(
"checkin".tr,
style: TextStyle(color: Colors.white),
))
: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.grey[300]),
onPressed: () async {
try {
await destinationController
.removeCheckin(destination.cp!.toInt());
destinationController
.deleteDestination(destination);
Get.back();
Get.snackbar(
'チェックイン取り消し',
'${destination.name}のチェックインは取り消されました',
backgroundColor: Colors.green,
colorText: Colors.white,
duration: Duration(seconds: 3),
);
} catch (e) {
// エラーハンドリング
Get.snackbar(
'Error',
'An error occurred while canceling check-in.',
backgroundColor: Colors.red,
colorText: Colors.white,
duration: Duration(seconds: 3),
);
// 必要に応じてエラーログを記録
print('Error canceling check-in: $e');
}
},
child: Text(
"cancel_checkin".tr,
style: TextStyle(color: Colors.black),
)))
: Container(),
// go here or cancel route
Obx(() => ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context)
.colorScheme
.onPrimaryContainer),
onPressed: () async {
if (destinationController.isRouteShowing.value) {
destinationController.clearRoute();
} else {
Get.back();
Position position =
await Geolocator.getCurrentPosition(
desiredAccuracy:
LocationAccuracy.bestForNavigation,
forceAndroidLocationManager: true);
Destination ds = Destination(
lat: position.latitude,
lon: position.longitude);
Destination tp = Destination(
lat: destination.lat, lon: destination.lon);
destinationController
.destinationMatrixFromCurrentPoint([ds, tp]);
}
},
child: Text(
destinationController.isRouteShowing.value
? "cancel_route".tr
: "go_here".tr,
style: TextStyle(
color:
Theme.of(context).colorScheme.onPrimary),
))),
],
),
Row(
children: [
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
indexController.currentDestinationFeature
.isNotEmpty &&
destinationController.isInCheckin.value ==
true
? Container()
: FutureBuilder<Widget>(
future: wantToGo(context),
builder: (context, snapshot) {
return Container(
child: snapshot.data,
);
},
),
indexController.currentFeature[0]
.properties!["location_name"] !=
null &&
(indexController.currentFeature[0]
.properties!["location_name"]
as String)
.isNotEmpty
? Flexible(
child: Text(indexController
.currentFeature[0]
.properties!["location_name"]))
: const SizedBox(
width: 0.0,
height: 0,
),
],
),
),
],
),
const SizedBox(
height: 8.0,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
const Icon(Icons.roundabout_left),
const SizedBox(
width: 8.0,
),
indexController.currentFeature[0]
.properties!["address"] !=
null &&
(indexController.currentFeature[0]
.properties!["address"] as String)
.isNotEmpty
? getDetails(
context,
"address".tr,
indexController.currentFeature[0]
.properties!["address"] ??
'')
: const SizedBox(
width: 0.0,
height: 0,
),
],
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
const Icon(Icons.phone),
const SizedBox(
width: 8.0,
),
indexController.currentFeature[0]
.properties!["phone"] !=
null &&
(indexController.currentFeature[0]
.properties!["phone"] as String)
.isNotEmpty
? getDetails(
context,
"telephone".tr,
indexController.currentFeature[0]
.properties!["phone"] ??
'')
: const SizedBox(
width: 0.0,
height: 0,
),
],
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
const Icon(Icons.email),
const SizedBox(
width: 8.0,
),
indexController.currentFeature[0]
.properties!["email"] !=
null &&
(indexController.currentFeature[0]
.properties!["email"] as String)
.isNotEmpty
? getDetails(
context,
"email".tr,
indexController.currentFeature[0]
.properties!["email"] ??
'')
: const SizedBox(
width: 0.0,
height: 0,
),
],
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
const Icon(Icons.language),
const SizedBox(
width: 8.0,
),
indexController.currentFeature[0]
.properties!["webcontents"] !=
null &&
(indexController.currentFeature[0]
.properties!["webcontents"] as String)
.isNotEmpty
? getDetails(
context,
"web".tr,
indexController.currentFeature[0]
.properties!["webcontents"] ??
'',
isurl: true)
: const SizedBox(
width: 0.0,
height: 0,
),
],
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
const SizedBox(
width: 8.0,
),
indexController.currentFeature[0]
.properties!["remark"] !=
null &&
(indexController.currentFeature[0]
.properties!["remark"] as String)
.isNotEmpty
? getDetails(
context,
"remarks".tr,
indexController.currentFeature[0]
.properties!["remark"] ??
'',
isurl: false)
: const SizedBox(
width: 0.0,
height: 0,
),
],
),
),
],
),
)),
const SizedBox(
height: 60.0,
)