diff --git a/lib/pages/camera/camera_page.dart b/lib/pages/camera/camera_page.dart index 3eedf42..0f655b7 100644 --- a/lib/pages/camera/camera_page.dart +++ b/lib/pages/camera/camera_page.dart @@ -14,6 +14,8 @@ class CameraPage extends StatelessWidget { DestinationController destinationController = Get.find(); IndexController indexController = Get.find(); + var settingGoal = false.obs; + Timer? timer; ImageProvider getFinishImage(){ @@ -25,51 +27,70 @@ class CameraPage extends StatelessWidget { } } - Widget getAction(BuildContext context){ + Widget getAction(BuildContext context) { if(destinationController.is_at_goal.value && destinationController.is_in_rog.value){ return Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ ElevatedButton( onPressed: (){ - destinationController.openCamera(context); + if(settingGoal.value ==false){ + destinationController.openCamera(context); + } }, child: Text("take_photo of the clock".tr) ), Obx(() => destinationController.photos.isNotEmpty ? - ElevatedButton( - style: ElevatedButton.styleFrom( - primary: Colors.red - ), - onPressed: (){ - int user_id = indexController.currentUser[0]["user"]["id"]; - //print("--- Pressed -----"); - String _team = indexController.currentUser[0]["user"]['team_name']; - //print("--- _team : ${_team}-----"); - String _event_code = indexController.currentUser[0]["user"]["event_code"]; - //print("--- _event_code : ${_event_code}-----"); - String _token = indexController.currentUser[0]["token"]; - //print("--- _token : ${_token}-----"); - DateTime now = DateTime.now(); - String formattedDate = DateFormat('yyyy-MM-dd HH:mm:ss').format(now); - - ExternalService().makeGoal(user_id, _token, _team, destinationController.photos[0].path, formattedDate, _event_code).then((value){ - print("---called ext api ${value['status']} ------"); - if(value['status'] == 'OK'){ - Get.back(); - destinationController.skip_gps = false; - Get.snackbar("目標が保存されました", "目標が正常に追加されました"); - destinationController.resetRogaining(); - } - else{ - print("---- status ${value['status']} ---- "); - Get.snackbar("目標が追加されていません", "please_try_again"); - } - }); - }, - child: Text("finish_goal".tr) - ): + settingGoal.value == false ? + ElevatedButton( + style: ElevatedButton.styleFrom( + primary: Colors.red + ), + onPressed: () async { + settingGoal.value = true; + try{ + int user_id = indexController.currentUser[0]["user"]["id"]; + //print("--- Pressed -----"); + String _team = indexController.currentUser[0]["user"]['team_name']; + //print("--- _team : ${_team}-----"); + String _event_code = indexController.currentUser[0]["user"]["event_code"]; + //print("--- _event_code : ${_event_code}-----"); + String _token = indexController.currentUser[0]["token"]; + //print("--- _token : ${_token}-----"); + DateTime now = DateTime.now(); + String formattedDate = DateFormat('yyyy-MM-dd HH:mm:ss').format(now); + + await ExternalService().makeGoal(user_id, _token, _team, destinationController.photos[0].path, formattedDate, _event_code).then((value){ + print("---called ext api ${value['status']} ------"); + if(value['status'] == 'OK'){ + Get.back(); + destinationController.skip_gps = false; + Get.snackbar("目標が保存されました", "目標が正常に追加されました"); + destinationController.resetRogaining(); + } + else{ + print("---- status ${value['status']} ---- "); + Get.snackbar("目標が追加されていません", "please_try_again"); + } + }); + } + on Exception catch(_){ + settingGoal.value = false; + } + finally{ + settingGoal.value = false; + } + }, + child:Text("finish_goal".tr) + ) + : + Container( + child: Center( + child: CircularProgressIndicator(), + ), + ) + : Container() ) ],