diff --git a/.vscode/launch.json b/.vscode/launch.json index 8dd1e7a..7ea06a3 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -20,6 +20,12 @@ "request": "launch", "type": "dart", "flutterMode": "release" + }, + { + "name": "Flutter (lib/main.dart)", + "type": "dart", + "request": "launch", + "program": "lib/main.dart" } ] } \ No newline at end of file diff --git a/lib/pages/camera/camera_page.dart b/lib/pages/camera/camera_page.dart index 920fa62..6917780 100644 --- a/lib/pages/camera/camera_page.dart +++ b/lib/pages/camera/camera_page.dart @@ -1,10 +1,14 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; +import 'package:intl/intl.dart'; import 'package:rogapp/pages/destination/destination_controller.dart'; +import 'package:rogapp/pages/index/index_controller.dart'; +import 'package:rogapp/services/external_service.dart'; class CameraPage extends StatelessWidget { CameraPage({Key? key}) : super(key: key); DestinationController destinationController = Get.find(); + IndexController indexController = Get.find(); ImageProvider getFinishImage(){ if(destinationController.photos.isNotEmpty){ @@ -62,7 +66,27 @@ class CameraPage extends StatelessWidget { 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(); + Get.snackbar("goal_saved", "goal_added_successfuly"); + } + else{ + Get.snackbar("goal_not_added", "please_try_again"); + } + }); }, child: Text("finish_goal".tr) ): diff --git a/lib/pages/destination/destination_controller.dart b/lib/pages/destination/destination_controller.dart index c6ed6f4..ca160af 100644 --- a/lib/pages/destination/destination_controller.dart +++ b/lib/pages/destination/destination_controller.dart @@ -16,6 +16,7 @@ import 'package:rogapp/pages/index/index_controller.dart'; import 'package:rogapp/routes/app_pages.dart'; import 'package:rogapp/services/action_service.dart'; import 'package:rogapp/services/destination_service.dart'; +import 'package:rogapp/services/external_service.dart'; import 'package:rogapp/services/maxtrix_service.dart'; import 'package:rogapp/services/reacking_service.dart'; import 'package:rogapp/utils/database_helper.dart'; @@ -72,7 +73,6 @@ class DestinationController extends GetxController { } else{ //finish rogiain - //is_in_rog.value = true; if (rogaining_counted.value && distance <=250){ Get.toNamed(AppPages.CAMERA_PAGE); } @@ -130,6 +130,8 @@ class DestinationController extends GetxController { for(final d in destinations){ + print("-----loc_id- ${d.location_id}----"); + if(!checking_in) { checking_in = true; @@ -142,6 +144,10 @@ class DestinationController extends GetxController { double rad = value!.checkin_radious ?? double.infinity; bool auto_checkin = value.auto_checkin == 0 ? false : true; + print("-----rogaining_counted---${rogaining_counted.value}-----"); + print("-----is_in_rog---${is_in_rog}-----"); + print("-----dist is ---${dist}-----"); + if(d.cp != -1 && is_in_rog == true){ rogaining_counted.value == true; } @@ -215,24 +221,25 @@ class DestinationController extends GetxController { } void makeCheckin(Destination destination, bool action) async { - print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ressssss ${action}@@@@@@@@@@@"); + // print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ressssss ${action}@@@@@@@@@@@"); DatabaseHelper db = DatabaseHelper.instance; int res = await db.updateAction(destination, action); List ddd = await db.getDestinationByLatLon(destination.lat!, destination.lon!); - print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ddddd ${ddd[0].checkedin} @@@@@@@@@@@"); + // print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ddddd ${ddd[0].checkedin} @@@@@@@@@@@"); - print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ressssss ${res}@@@@@@@@@@@"); + // print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ressssss ${res}@@@@@@@@@@@"); PopulateDestinations(); - print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ after populating ${res} @@@@@@@@@@@"); - print("---- database update resulr ------ res : ${res}-------"); + // print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ after populating ${res} @@@@@@@@@@@"); + // print("---- database update resulr ------ res : ${res}-------"); /// post to NATNAT if(indexController.currentUser.length > 0){ - String cp_num = destination.cp.toString(); - String team_name = indexController.currentUser[0]['user']['group']; - ActionService.postCheckin(cp_num, team_name).then((value){ - print('------- NATNAT RES ${value} ------------'); + int cp_num = int.parse(destination.cp!.toString()); + String _team = indexController.currentUser[0]["user"]["team_name"]; + String _event_code = indexController.currentUser[0]["user"]["event_code"]; + ExternalService().makeCheckpoint(_team, cp_num, _event_code).then((value){ + print("------Ext service check point ${value} ------"); }); } } diff --git a/lib/pages/destination/destination_page.dart b/lib/pages/destination/destination_page.dart index f0b5f11..e21e527 100644 --- a/lib/pages/destination/destination_page.dart +++ b/lib/pages/destination/destination_page.dart @@ -12,6 +12,7 @@ import 'package:rogapp/pages/destination_map/destination_map_page.dart'; import 'package:rogapp/pages/drawer/drawer_page.dart'; import 'package:rogapp/pages/index/index_controller.dart'; import 'package:rogapp/routes/app_pages.dart'; +import 'package:rogapp/services/external_service.dart'; import 'package:rogapp/widgets/destination_widget.dart'; import 'package:timeline_tile/timeline_tile.dart'; @@ -159,13 +160,14 @@ class DestnationPage extends StatelessWidget { automaticallyImplyLeading: true, title: Text("app_title".tr), actions: [ - // TextButton( - // onPressed: (){ - // //destinationController.openCamera(context); - // Get.toNamed(AppPages.CAMERA_PAGE); - // }, - // child: Icon(Icons.ac_unit), - // ), + TextButton( + onPressed: (){ + //ExternalService().StartRogaining('team_name', "2222"); + //destinationController.openCamera(context); + Get.toNamed(AppPages.CAMERA_PAGE); + }, + child: Icon(Icons.ac_unit), + ), Obx(() => ToggleButtons( disabledColor: Colors.grey.shade200, diff --git a/lib/services/action_service.dart b/lib/services/action_service.dart index 1de96db..f6ccfaa 100644 --- a/lib/services/action_service.dart +++ b/lib/services/action_service.dart @@ -5,27 +5,6 @@ import 'package:rogapp/utils/const.dart'; class ActionService{ - static Future> postCheckin(String cp_num, String team_name) async{ - Map checkin_res = {}; - String url = 'https://natnats.mobilous.com/post_from_rogapp_ogaki'; - //print('---- toekn is ${token} -----'); - final http.Response response = await http.post( - Uri.parse(url), - headers: { - 'Content-Type': 'application/json; charset=UTF-8', - }, - body: jsonEncode({ - 'team_name': team_name, - 'cp_number': cp_num.toString() - }), - ); - - if (response.statusCode == 200) { - checkin_res = json.decode(utf8.decode(response.bodyBytes)); - } - return checkin_res; - } - static Future> makeAction(int user_id, int location_id, bool wanttogo, bool like, bool checkin) async { print("----- action is ---- ${like}-- ${wanttogo}-- ${checkin}"); Map cats = {}; diff --git a/lib/services/external_service.dart b/lib/services/external_service.dart new file mode 100644 index 0000000..d774e48 --- /dev/null +++ b/lib/services/external_service.dart @@ -0,0 +1,133 @@ +import 'dart:io'; + +import 'package:flutter/foundation.dart'; +import 'package:http/http.dart' as http; +import 'dart:convert'; + +import '../utils/const.dart'; + +class ExternalService { + static final ExternalService _instance = ExternalService._internal(); + + factory ExternalService(){ + return _instance; + } + + ExternalService._internal(); + + Future> StartRogaining(String teamname, String eventcode) async { + Map _res = {}; + String url = 'https://natnats.mobilous.com/start_from_rogapp'; + //print('---- toekn is ${token} -----'); + final http.Response response = await http.post( + Uri.parse(url), + headers: { + 'Content-Type': 'application/json; charset=UTF-8', + }, + body: jsonEncode({ + 'team_name': teamname, + 'event_code': eventcode + }), + ); + + if (response.statusCode == 200) { + _res = json.decode(utf8.decode(response.bodyBytes)); + print('----_res : ${_res} ----'); + } + return _res; + } + + Future> makeCheckpoint(String teamname, int cp, String eventcode) async { + Map _res = {}; + String url = 'https://natnats.mobilous.com/checkin_from_rogapp'; + //print('---- toekn is ${token} -----'); + final http.Response response = await http.post( + Uri.parse(url), + headers: { + 'Content-Type': 'application/json; charset=UTF-8', + }, + body: jsonEncode({ + 'team_name': teamname, + 'cp_number': cp.toString(), + 'event_code': eventcode + }), + ); + + if (response.statusCode == 200) { + _res = json.decode(utf8.decode(response.bodyBytes)); + print('----_res : ${_res} ----'); + } + return _res; + } + + Future> makeGoal(int user_id, String token, String teamname, String image, String goal_time, String eventcode) async { + Map _res2 = {}; + + String server_url = ConstValues.currentServer(); + String url1 = "${server_url}/api/goalimage/"; + final im1Bytes = File(image!).readAsBytesSync(); + String im1_64 = base64Encode(im1Bytes); + + final http.Response response = await http.post( + Uri.parse(url1), + headers: { + 'Content-Type': 'application/json; charset=UTF-8', + 'Authorization': 'Token ${token}' + }, + // 'id', 'user', 'goalimage', 'goaltime', 'team_name', 'event_code','cp_number' + body: jsonEncode({ + 'user' : user_id.toString(), + 'team_name': teamname, + 'event_code': eventcode, + 'goaltime' : goal_time, + 'goalimage' : im1_64, + 'cp_number' : "-1" + }), + ); + + String url = 'https://natnats.mobilous.com/start_from_rogapp'; + //print("---response is : ${response.statusCode}----"); + if (response.statusCode == 201) { + Map _res = json.decode(utf8.decode(response.bodyBytes)); + print('----_res : ${_res} ----'); + print('---- image url ${_res["goalimage"]} ----'); + final http.Response response2 = await http.post( + Uri.parse(url), + headers: { + 'Content-Type': 'application/json; charset=UTF-8', + }, + body: jsonEncode({ + 'team_name': teamname, + 'event_code': eventcode, + 'goal_time' : goal_time, + 'image' : _res["goalimage"] + } + ), + ); + print('----- response2 is ${response2} --------'); + if (response2.statusCode == 200) { + _res2 = json.decode(utf8.decode(response2.bodyBytes)); + } + } + return _res2; + } + + + static Future> usersEventCode(String teamcode, String password) async { + Map _res = {}; + String url = "https://natnats.mobilous.com/check_event_code?zekken_number=${teamcode}&password=${password}"; + print("url is ------ ${url}"); + final http.Response response = await http.get( + Uri.parse(url), + headers: { + 'Content-Type': 'application/json; charset=UTF-8', + } + ); + + if (response.statusCode == 200) { + _res = json.decode(utf8.decode(response.bodyBytes)); + } + return _res; + } + +} \ No newline at end of file diff --git a/lib/services/location_service.dart b/lib/services/location_service.dart index 8439ab3..b645bd0 100644 --- a/lib/services/location_service.dart +++ b/lib/services/location_service.dart @@ -44,7 +44,7 @@ class LocationService{ bool _rog = indexController.currentUser[0]['user']['is_rogaining']; String r = _rog == true ? 'True': 'False'; var grp = indexController.currentUser[0]['user']['group']; - url = '${server_url}/api/inperf/?rog=${r}&perf=' + perfecture + '&cat=' + cat + "&grp=${grp}"; + url = '${server_url}/api/inperf/?rog=${r}&perf=' + perfecture + '&cat=' + cat; } else { url = '${server_url}/api/inperf/?perf=' + perfecture + '&cat=' + cat; @@ -55,7 +55,7 @@ class LocationService{ bool _rog = indexController.currentUser[0]['user']['is_rogaining']; String r = _rog == true ? 'True': 'False'; var grp = indexController.currentUser[0]['user']['group']; - url = '${server_url}/api/inperf/?rog=${r}&perf=' + perfecture + "&grp=${grp}"; + url = '${server_url}/api/inperf/?rog=${r}&perf=' + perfecture; } else { url = '${server_url}/api/inperf/?perf=' + perfecture; @@ -86,7 +86,7 @@ class LocationService{ bool _rog = indexController.currentUser[0]['user']['is_rogaining']; String r = _rog == true ? 'True': 'False'; var grp = indexController.currentUser[0]['user']['group']; - url = '${server_url}/api/insubperf?rog=${r}&subperf=' + subperfecture + '&cat=' + cat + "&grp=${grp}"; + url = '${server_url}/api/insubperf?rog=${r}&subperf=' + subperfecture + '&cat=' + cat; } else{ url = '${server_url}/api/insubperf?subperf=' + subperfecture + '&cat=' + cat; @@ -97,7 +97,7 @@ class LocationService{ bool _rog = indexController.currentUser[0]['user']['is_rogaining']; String r = _rog == true ? 'True': 'False'; var grp = indexController.currentUser[0]['user']['group']; - url = '${server_url}/api/insubperf?rog=${r}&subperf=' + subperfecture + "&grp=${grp}"; + url = '${server_url}/api/insubperf?rog=${r}&subperf=' + subperfecture; } else{ url = '${server_url}/api/insubperf?subperf=' + subperfecture; @@ -129,7 +129,7 @@ class LocationService{ bool _rog = indexController.currentUser[0]['user']['is_rogaining']; String r = _rog == true ? 'True': 'False'; var grp = indexController.currentUser[0]['user']['group']; - url = '${server_url}/api/inbound?rog=${r}&ln1=${lon1}&la1=${lat1}&ln2=${lon2}&la2=${lat2}&ln3=${lon3}&la3=${lat3}&ln4=${lon4}&la4=${lat4}' + '&cat=' + cat + "&grp=${grp}"; + url = '${server_url}/api/inbound?rog=${r}&ln1=${lon1}&la1=${lat1}&ln2=${lon2}&la2=${lat2}&ln3=${lon3}&la3=${lat3}&ln4=${lon4}&la4=${lat4}' + '&cat=' + cat; } else{ url = '${server_url}/api/inbound?ln1=${lon1}&la1=${lat1}&ln2=${lon2}&la2=${lat2}&ln3=${lon3}&la3=${lat3}&ln4=${lon4}&la4=${lat4}' + '&cat=' + cat; @@ -141,7 +141,7 @@ class LocationService{ String r = _rog == true ? 'True': 'False'; var grp = indexController.currentUser[0]['user']['group']; print("-------- requested user group ${grp} -------------"); - url = '${server_url}/api/inbound?rog=${r}&ln1=${lon1}&la1=${lat1}&ln2=${lon2}&la2=${lat2}&ln3=${lon3}&la3=${lat3}&ln4=${lon4}&la4=${lat4}' + '&grp=${grp}'; + url = '${server_url}/api/inbound?rog=${r}&ln1=${lon1}&la1=${lat1}&ln2=${lon2}&la2=${lat2}&ln3=${lon3}&la3=${lat3}&ln4=${lon4}&la4=${lat4}'; } else{ url = '${server_url}/api/inbound?ln1=${lon1}&la1=${lat1}&ln2=${lon2}&la2=${lat2}&ln3=${lon3}&la3=${lat3}&ln4=${lon4}&la4=${lat4}'; @@ -184,7 +184,7 @@ class LocationService{ bool _rog = indexController.currentUser[0]['user']['is_rogaining']; String r = _rog == true ? 'True': 'False'; var grp = indexController.currentUser[0]['user']['group']; - url = '${server_url}/api/custom_area/?rog=${r}&&cat=' + cat + "&grp=${grp}"; + url = '${server_url}/api/custom_area/?rog=${r}&&cat=' + cat; } else{ url = '${server_url}/api/custom_area/?&cat=' + cat; @@ -195,7 +195,7 @@ class LocationService{ bool _rog = indexController.currentUser[0]['user']['is_rogaining']; String r = _rog == true ? 'True': 'False'; var grp = indexController.currentUser[0]['user']['group']; - url = '${server_url}/api/customarea?rog=${r}&name=${name}' + "&grp=${grp}"; + url = '${server_url}/api/customarea?rog=${r}&name=${name}'; } else{ url = '${server_url}/api/customarea?name=${name}'; diff --git a/lib/utils/const.dart b/lib/utils/const.dart index dd1e936..bacb16a 100644 --- a/lib/utils/const.dart +++ b/lib/utils/const.dart @@ -8,6 +8,6 @@ class ConstValues{ static const dev_home_ip_server = "http://172.20.10.9:8100"; static String currentServer(){ - return dev_server; + return server_uri; } } diff --git a/lib/utils/string_values.dart b/lib/utils/string_values.dart index e0c081d..b7e865f 100644 --- a/lib/utils/string_values.dart +++ b/lib/utils/string_values.dart @@ -55,6 +55,10 @@ class StringValues extends Translations{ 'finishing_rogaining' : 'Finishing Rogaining', 'take_photo of the clock' : 'Take photo of the clock', 'finish_goal': 'finish Goal', + 'goal_saved': "Goal Saved", + 'goal_added_successfuly' : 'Goal added successfully', + 'goal_not_added' : 'Goal not added', + 'please_try_again' : 'Please try again' }, 'ja_JP': { 'drawer_title':'ロゲイニング参加者はログイン するとチェックポイントが参照 できます', @@ -110,6 +114,10 @@ class StringValues extends Translations{ 'finishing_rogaining' : 'ロゲイニングを終えて', 'take_photo of the clock' : '時計の写真を撮る', 'finish_goal': 'フィニッシュゴール', + 'goal_saved': "目標を保存しました", + 'goal_added_successfuly' : '目標が正常に追加されました', + 'goal_not_added' : '目標が追加されていません', + 'please_try_again' : 'もう一度お試しください' }, }; } \ No newline at end of file diff --git a/lib/widgets/bottom_sheet_new.dart b/lib/widgets/bottom_sheet_new.dart index abd0a2d..a9afd07 100644 --- a/lib/widgets/bottom_sheet_new.dart +++ b/lib/widgets/bottom_sheet_new.dart @@ -96,7 +96,6 @@ class BottomSheetNew extends GetView { @override Widget build(BuildContext context) { - return indexController.rog_mode == 0 ? detailsSheet(context) : destinationSheet(context); } diff --git a/lib/widgets/list_widget.dart b/lib/widgets/list_widget.dart index 255f29a..1b071ae 100644 --- a/lib/widgets/list_widget.dart +++ b/lib/widgets/list_widget.dart @@ -67,7 +67,7 @@ class ListWidget extends StatelessWidget { leading: getImage(index), title: indexController.locations[0].collection[index].properties!['location_name'] != null ? Text(indexController.locations[0].collection[index].properties!['location_name'].toString()) : Text(""), subtitle: indexController.locations[0].collection[index].properties!['category'] != null ? Text(indexController.locations[0].collection[index].properties!['category']) : Text(""), - trailing: Text(indexController.locations[0].collection[index].properties!['sub_loc_id'] ), + trailing: indexController.locations[0].collection[index].properties!['sub_loc_id'] != null ? Text(indexController.locations[0].collection[index].properties!['sub_loc_id']) : Text(""), ), ); }, diff --git a/pubspec.lock b/pubspec.lock index 20a59b2..df2d054 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -472,7 +472,7 @@ packages: source: hosted version: "2.6.1" intl: - dependency: transitive + dependency: "direct main" description: name: intl url: "https://pub.dartlang.org" diff --git a/pubspec.yaml b/pubspec.yaml index 62dbf7a..ddb281d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -70,6 +70,7 @@ dependencies: rename: ^2.0.1 circular_menu: ^2.0.1 camera_camera: ^3.0.0-dev + intl: ^0.17.0 flutter_icons: android: true