diff --git a/lib/pages/camera/camera_page.dart b/lib/pages/camera/camera_page.dart index df79b7e..baaf4cd 100644 --- a/lib/pages/camera/camera_page.dart +++ b/lib/pages/camera/camera_page.dart @@ -191,7 +191,7 @@ class CameraPage extends StatelessWidget { Get.snackbar("目標が保存されました", "目標が正常に追加されました"); destinationController.resetRogaining(); } else { - print("---- status ${value['status']} ---- "); + //print("---- status ${value['status']} ---- "); Get.snackbar("目標が追加されていません", "please_try_again"); } }); @@ -406,7 +406,7 @@ class BuyPointCamera extends StatelessWidget { @override Widget build(BuildContext context) { - print("in camera purchase 1 ${destinationController.isInRog.value}"); + //print("in camera purchase 1 ${destinationController.isInRog.value}"); return Scaffold( appBar: AppBar( @@ -445,8 +445,8 @@ class BuyPointCamera extends StatelessWidget { children: [ ElevatedButton( onPressed: () { - print( - "in camera purchase 2 ${destinationController.isInRog.value}"); + // print( + // "in camera purchase 2 ${destinationController.isInRog.value}"); destinationController.openCamera( context, destination); }, @@ -485,14 +485,14 @@ class BuyPointCamera extends StatelessWidget { style: ElevatedButton.styleFrom( backgroundColor: Colors.red), onPressed: () async { - print( - "in camera purchase 3 ${destinationController.isInRog.value}"); + // print( + // "in camera purchase 3 ${destinationController.isInRog.value}"); await destinationController.makeBuyPoint( destination, destinationController.photos[0].path); Get.back(); - print( - "in camera purchase 4 ${destinationController.isInRog.value}"); + // print( + // "in camera purchase 4 ${destinationController.isInRog.value}"); destinationController.rogainingCounted.value = true; destinationController.skipGps = false; diff --git a/lib/pages/destination/destination_controller.dart b/lib/pages/destination/destination_controller.dart index 4ba9d89..87c440f 100644 --- a/lib/pages/destination/destination_controller.dart +++ b/lib/pages/destination/destination_controller.dart @@ -648,7 +648,7 @@ class DestinationController extends GetxController { // Save the image to the gallery final result = await ImageGallerySaver.saveImage(imageBytes); - print("--- save result --- ${result}"); + //print("--- save result --- ${result}"); } Future makeBuyPoint(Destination destination, String imageurl) async { diff --git a/lib/services/external_service.dart b/lib/services/external_service.dart index fc40ad6..3560319 100644 --- a/lib/services/external_service.dart +++ b/lib/services/external_service.dart @@ -165,7 +165,7 @@ class ExternalService { //print("--- checnin response ${response2.statusCode}----"); if (response2.statusCode == 200) { res = json.decode(utf8.decode(response2.bodyBytes)); - print('----checkin res _res : $res ----'); + //print('----checkin res _res : $res ----'); if (res["status"] == "ERROR") { Get.snackbar("エラーがおきました", res["detail"]); } @@ -267,7 +267,7 @@ class ExternalService { ); String url = 'https://rogaining.sumasen.net/gifuroge/goal_from_rogapp'; - print('++++++++$url'); + //print('++++++++$url'); if (response.statusCode == 201) { Map res = json.decode(utf8.decode(response.bodyBytes)); // print('----_res : $res ----'); @@ -293,8 +293,8 @@ class ExternalService { .toString() .replaceAll('http://localhost:8100', 'http://rogaining.sumasen.net') }); - print("-- json -- $rec"); - print('----- response2 is $response2 --------'); + //print("-- json -- $rec"); + //print('----- response2 is $response2 --------'); if (response2.statusCode == 200) { res2 = json.decode(utf8.decode(response2.bodyBytes)); } diff --git a/lib/widgets/bottom_sheet_new.dart b/lib/widgets/bottom_sheet_new.dart index e81f26a..ebcf52f 100644 --- a/lib/widgets/bottom_sheet_new.dart +++ b/lib/widgets/bottom_sheet_new.dart @@ -110,9 +110,125 @@ class BottomSheetNew extends GetView { } } + 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: [ + 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 { 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 { .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 { 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 { ), // 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: [ - 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( diff --git a/lib/widgets/map_widget.dart b/lib/widgets/map_widget.dart index 1b09ac0..778d43b 100644 --- a/lib/widgets/map_widget.dart +++ b/lib/widgets/map_widget.dart @@ -16,14 +16,21 @@ import 'package:rogapp/widgets/base_layer_widget.dart'; import 'package:rogapp/widgets/bottom_sheet_new.dart'; import 'package:rogapp/widgets/game_state_view.dart'; -class MapWidget extends StatelessWidget { +class MapWidget extends StatefulWidget { + MapWidget({Key? key}) : super(key: key); + + @override + State createState() => _MapWidgetState(); +} + +class _MapWidgetState extends State { final IndexController indexController = Get.find(); + final DestinationController destinationController = Get.find(); - MapWidget({Key? key}) : super(key: key); - StreamSubscription? subscription; + Timer? _timer; Widget getMarkerShape(GeoJSONFeature i, BuildContext context) { GeoJSONMultiPoint p = i.geometry as GeoJSONMultiPoint; @@ -153,6 +160,29 @@ class MapWidget extends StatelessWidget { return pts; } + @override + void initState() { + super.initState(); + _startIdleTimer(); + } + + void _startIdleTimer() { + _timer = + Timer(const Duration(milliseconds: (1000 * 60 * 10)), _centerMapOnUser); + } + + void _resetTimer() { + _timer?.cancel(); + _startIdleTimer(); + } + + void _centerMapOnUser() { + indexController.mapController.move( + LatLng( + destinationController.currentLat, destinationController.currentLon), + 15.0); + } + @override Widget build(BuildContext context) { // print( @@ -174,7 +204,8 @@ class MapWidget extends StatelessWidget { subscription = indexController.mapController.mapEventStream .listen((MapEvent mapEvent) { if (mapEvent is MapEventMoveStart) { - //print(DateTime.now().toString() + ' [MapEventMoveStart] START'); + // print(DateTime.now().toString() + + // ' [MapEventMoveStart] START'); // do something } if (mapEvent is MapEventMoveEnd) {} @@ -191,7 +222,11 @@ class MapWidget extends StatelessWidget { interactiveFlags: InteractiveFlag.pinchZoom | InteractiveFlag.drag, - onPositionChanged: (MapPosition pos, isvalue) { + onPositionChanged: (MapPosition pos, hasGesture) { + //print("map position changed ${pos.center!.latitude}"); + if (hasGesture) { + _resetTimer(); + } indexController.currentBound = [pos.bounds!]; }, onTap: (_, __) => popupController