diff --git a/lib/pages/camera/camera_page.dart b/lib/pages/camera/camera_page.dart index 142a406..2e6d8b6 100644 --- a/lib/pages/camera/camera_page.dart +++ b/lib/pages/camera/camera_page.dart @@ -53,12 +53,12 @@ class CameraPage extends StatelessWidget { if(value['status'] == 'OK'){ Get.back(); destinationController.skip_gps = false; - Get.snackbar("goal_saved", "goal_added_successfuly"); + Get.snackbar("目標が保存されました", "目標が正常に追加されました"); destinationController.resetRogaining(); } else{ print("---- status ${value['status']} ---- "); - Get.snackbar("goal_not_added", "please_try_again"); + Get.snackbar("目標が追加されていません", "please_try_again"); } }); }, @@ -77,7 +77,7 @@ class CameraPage extends StatelessWidget { onPressed: (){ destinationController.openCamera(context); }, - child: Text("take checkin photo".tr) + child: Text("再撮影") ), Obx(() => destinationController.photos.isNotEmpty ? @@ -86,18 +86,13 @@ 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); - destinationController.makeCheckin(indexController.currentDestinationFeature[0], true); + destinationController.makeCheckin(indexController.currentDestinationFeature[0], true, destinationController.photos[0].path); + Get.back(); + destinationController.rogaining_counted.value = true; + destinationController.skip_gps = false; + destinationController.is_photo_shoot.value = false; + Get.snackbar("チェックインした", "正常にチェックインしました"); // ExternalService().makeGoal(user_id, _token, _team, destinationController.photos[0].path, formattedDate, _event_code).then((value){ // print("---called ext api ${value['status']} ------"); @@ -112,7 +107,7 @@ class CameraPage extends StatelessWidget { // } // }); }, - child: Text("Check In".tr) + child: Text("チェックイン") ): Container() ) @@ -129,8 +124,15 @@ class CameraPage extends StatelessWidget { Widget build(BuildContext context) { if(destinationController.is_in_rog.value){ return Scaffold( - appBar: AppBar( - title: Text("finishing_rogaining".tr), + appBar: + destinationController.is_in_rog.value && destinationController.rogaining_counted.value == true ? + AppBar( + title: Text("finishing_rogaining".tr) + , + ) + : + AppBar( + title: Text("チェックポイント"), ), body: Column( mainAxisAlignment: MainAxisAlignment.spaceAround, diff --git a/lib/pages/destination/destination_controller.dart b/lib/pages/destination/destination_controller.dart index b1a3686..21d9b5f 100644 --- a/lib/pages/destination/destination_controller.dart +++ b/lib/pages/destination/destination_controller.dart @@ -9,6 +9,7 @@ import 'package:flutter/material.dart'; import 'package:geojson/geojson.dart'; import 'package:geolocator/geolocator.dart'; import 'package:get/get.dart'; +import 'package:intl/intl.dart'; import 'package:latlong2/latlong.dart'; import 'package:rogapp/model/Rogaining.dart'; import 'package:rogapp/model/destination.dart'; @@ -26,6 +27,7 @@ import 'dart:async'; import 'package:rogapp/widgets/bottom_sheet_widget.dart'; import 'package:sqflite/sqlite_api.dart'; +import 'package:modal_bottom_sheet/modal_bottom_sheet.dart'; class DestinationController extends GetxController { @@ -42,6 +44,7 @@ class DestinationController extends GetxController { var is_in_rog = false.obs; var is_at_start = false.obs; var is_at_goal = false.obs; + var is_photo_shoot = false.obs; //List rogainings = [].obs; bool checking_in = false; @@ -139,6 +142,17 @@ class DestinationController extends GetxController { return; } + if(is_photo_shoot.value == true){ + showModalBottomSheet(context: Get.context!, isScrollControlled: true, + builder:((context) => CameraPage()) + ).whenComplete((){ + skip_gps = false; + chekcs = 0; + is_in_checkin.value = false; + }); + return; + } + DatabaseHelper db = DatabaseHelper.instance; List ds = await db.getDestinationByLatLon(d.lat!, d.lon!); if(ds.isEmpty){ @@ -159,7 +173,7 @@ class DestinationController extends GetxController { is_in_checkin.value = false; }); } - else if(is_in_rog.value == false) + else if(is_in_rog.value == true) { print("----- in location popup checkin cp - ${d.cp}----"); chekcs = 2; @@ -176,10 +190,10 @@ class DestinationController extends GetxController { print("---- location checkin radious ${d.checkin_radious} ----"); print("---- already checked in ${location_already_checked_in} ----"); - if(checkin_radious >= distance && location_already_checked_in == false){ + if(checkin_radious >= distance && location_already_checked_in == false && is_in_rog.value == true){ if(auto_checkin){ if(!checking_in){ - makeCheckin(d, true); + makeCheckin(d, true,""); if(d.cp != -1){ rogaining_counted.value =true; } @@ -190,26 +204,36 @@ class DestinationController extends GetxController { print("--- hidden loc ${d.hidden_location} ----"); // ask for checkin if(d.hidden_location != null && d.hidden_location == 0 && is_in_rog.value == true && d.cp != -1){ - chekcs = 3; - is_in_checkin.value = true; - showModalBottomSheet(context: Get.context!, isScrollControlled: true, - builder:((context) => CameraPage()) - ).whenComplete((){ - skip_gps = false; - chekcs = 0; - is_in_checkin.value = false; - }); + // chekcs = 3; + // is_in_checkin.value = true; + // showModalBottomSheet(context: Get.context!, isScrollControlled: true, + // builder:((context) => CameraPage()) + // ).whenComplete((){ + // skip_gps = false; + // chekcs = 0; + // is_in_checkin.value = false; + // }); } else if(is_in_rog.value == true && d.cp != -1){ chekcs = 4; is_in_checkin.value = true; - showModalBottomSheet(context: Get.context!, isScrollControlled: true, - builder:((context) => BottomSheetNew()) - ).whenComplete((){ - skip_gps = false; - chekcs = 0; - is_in_checkin.value = false; - }); + showMaterialModalBottomSheet( + expand: true, + context: Get.context!, + backgroundColor: Colors.transparent, + builder: (context) => BottomSheetNew() + ).whenComplete(() { + skip_gps = false; + chekcs = 0; + is_in_checkin.value = false; + }); + // showModalBottomSheet(context: Get.context!, isScrollControlled: true, + // builder:((context) => BottomSheetNew()) + // ).whenComplete((){ + // skip_gps = false; + // chekcs = 0; + // is_in_checkin.value = false; + // }); } } @@ -349,6 +373,7 @@ class DestinationController extends GetxController { is_in_rog.value = false; is_at_start.value = false; is_at_goal.value = false; + destinations.clear(); _start = 0; chekcs = 0; @@ -448,7 +473,7 @@ class DestinationController extends GetxController { if(d.isEmpty){ Destination df = festuretoDestination(indexController.currentFeature[0]); print("--- made checkin ${df.location_id} ----"); - makeCheckin(df, true); + makeCheckin(df, true, ""); } Rogaining rog = Rogaining( @@ -466,8 +491,8 @@ class DestinationController extends GetxController { is_in_rog.value = true; } - void makeCheckin(Destination destination, bool action, {String imageurl = ""}) async { - // print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ressssss ${action}@@@@@@@@@@@"); + void makeCheckin(Destination destination, bool action, String imageurl) async { + //print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ressssss ${action}@@@@@@@@@@@"); DatabaseHelper db = DatabaseHelper.instance; List ddd = await db.getDestinationByLatLon(destination.lat!, destination.lon!); @@ -475,18 +500,30 @@ class DestinationController extends GetxController { destination.checkedin = true; await db.insertDestination(destination); } - //int res = await db.updateAction(destination, action); PopulateDestinations(); + /// post to NATNAT if(indexController.currentUser.length > 0){ - int cp_num = int.parse(destination.cp!.toString()); - String _team = indexController.currentUser[0]["user"]["team_name"]; + double cp_num = destination.cp!; + + 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"]; - ExternalService().makeCheckpoint(_team, cp_num, _event_code, imageurl).then((value){ + //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); + + print("------ checkin event ${_event_code} ------"); + ExternalService().makeCheckpoint(user_id, _token, formattedDate, _team,cp_num.round(), _event_code, imageurl).then((value){ print("------Ext service check point ${value} ------"); }); } + } diff --git a/lib/services/external_service.dart b/lib/services/external_service.dart index aa766a3..50f639e 100644 --- a/lib/services/external_service.dart +++ b/lib/services/external_service.dart @@ -1,7 +1,7 @@ import 'dart:io'; - -import 'package:flutter/foundation.dart'; +import 'package:get/get.dart'; import 'package:http/http.dart' as http; +import 'package:rogapp/pages/index/index_controller.dart'; import 'dart:convert'; import '../utils/const.dart'; @@ -15,8 +15,17 @@ class ExternalService { ExternalService._internal(); - Future> StartRogaining(String teamname, String eventcode) async { + Future> StartRogaining() async { Map _res = {}; + + final IndexController indexController = Get.find(); + + 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"]; + String url = 'https://natnats.mobilous.com/start_from_rogapp'; //print('---- toekn is ${token} -----'); final http.Response response = await http.post( @@ -25,11 +34,13 @@ class ExternalService { 'Content-Type': 'application/json; charset=UTF-8', }, body: jsonEncode({ - 'team_name': teamname, - 'event_code': eventcode + 'team_name': _team, + 'event_code': _event_code }), ); + print("---- start rogianing api status ---- ${response.statusCode}"); + if (response.statusCode == 200) { _res = json.decode(utf8.decode(response.bodyBytes)); print('----_res : ${_res} ----'); @@ -37,29 +48,80 @@ class ExternalService { return _res; } - Future> makeCheckpoint(String teamname, int cp, String eventcode, String imageurl) async { + Future> makeCheckpoint(int user_id, String token, String checkin_time, String teamname, int cp, String eventcode, String imageurl) 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, - 'image': imageurl - }), - ); - if (response.statusCode == 200) { + if(imageurl != null){ + String server_url = ConstValues.currentServer(); + String url1 = "${server_url}/api/checkinimage/"; + final im1Bytes = File(imageurl!).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, + 'checkinimage' : im1_64, + 'checkintime' : checkin_time, + 'cp_number' : cp.toString() + }), + ); + _res = json.decode(utf8.decode(response.bodyBytes)); - print('----_res : ${_res} ----'); + + print("-----@@@@@ ${_res} -----"); + + if(response.statusCode == 201){ + //print('---- toekn is ${token} -----'); + final http.Response response2 = 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, + 'image': _res["checkinimage"].toString().replaceAll('http://localhost:8100', 'http://rogaining.sumasen.net') + }), + ); + print("--- checnin response ${response2.statusCode}----"); + if (response2.statusCode == 200) { + _res = json.decode(utf8.decode(response2.bodyBytes)); + print('----checkin res _res : ${_res} ----'); + } + } + } + else{ + final http.Response response3 = 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, + 'image': "" + }), + ); + print("--- checnin response ${response3.statusCode}----"); + if (response3.statusCode == 200) { + _res = json.decode(utf8.decode(response3.bodyBytes)); + print('----checkin res _res : ${_res} ----'); + } } return _res; } + Future> makeGoal(int user_id, String token, String teamname, String image, String goal_time, String eventcode) async { Map _res2 = {}; @@ -86,7 +148,7 @@ class ExternalService { }), ); - String url = 'https://natnats.mobilous.com/start_from_rogapp'; + String url = 'https://natnats.mobilous.com/goal_from_rogapp'; //print("---response is : ${response.statusCode}----"); if (response.statusCode == 201) { Map _res = json.decode(utf8.decode(response.bodyBytes)); @@ -101,7 +163,7 @@ class ExternalService { 'team_name': teamname, 'event_code': eventcode, 'goal_time' : goal_time, - 'image' : _res["goalimage"] + 'image' : _res["goalimage"].toString().replaceAll('http://localhost:8100', 'http://rogaining.sumasen.net') } ), ); diff --git a/lib/widgets/bottom_sheet_new.dart b/lib/widgets/bottom_sheet_new.dart index 4b382dd..fc30335 100644 --- a/lib/widgets/bottom_sheet_new.dart +++ b/lib/widgets/bottom_sheet_new.dart @@ -5,10 +5,13 @@ import 'package:get/get.dart'; import 'package:get/get_state_manager/get_state_manager.dart'; import 'package:image_picker/image_picker.dart'; import 'package:latlong2/latlong.dart'; +import 'package:modal_bottom_sheet/modal_bottom_sheet.dart'; import 'package:rogapp/model/destination.dart'; +import 'package:rogapp/pages/camera/camera_page.dart'; import 'package:rogapp/pages/destination/destination_controller.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/utils/const.dart'; import 'package:rogapp/utils/database_helper.dart'; import 'package:rogapp/utils/text_util.dart'; @@ -173,21 +176,47 @@ class BottomSheetNew extends GetView { ElevatedButton( onPressed: (){ if(indexController.currentDestinationFeature[0].checkedin == null || indexController.currentDestinationFeature[0].checkedin == false){ - destinationController.makeCheckin(indexController.currentDestinationFeature[0], true); - if(indexController.currentDestinationFeature[0].cp != -1){ - destinationController.rogaining_counted.value =true; + if(indexController.currentDestinationFeature[0].hidden_location == 0){ + destinationController.skip_gps = false; + destinationController.is_photo_shoot.value = true; + Get.back(); + + // showMaterialModalBottomSheet( + // expand: true, + // context: Get.context!, + // backgroundColor: Colors.transparent, + // builder: (context) => BottomSheetNew() + // ).whenComplete(() { + // }); + + // showModalBottomSheet(context: Get.context!, isScrollControlled: true, + // //builder:((context) => CameraPage()) + // builder:((context) => Container(child: Text("model"),)) + // ).whenComplete((){ + // // destinationController.makeCheckin(indexController.currentDestinationFeature[0], true); + // // if(indexController.currentDestinationFeature[0].cp != -1){ + // // destinationController.rogaining_counted.value =true; + // // } + // }); } + else{ + destinationController.makeCheckin(indexController.currentDestinationFeature[0], true, ""); + if(indexController.currentDestinationFeature[0].cp != -1){ + destinationController.rogaining_counted.value =true; + } + } + } else{ - destinationController.makeCheckin(indexController.currentDestinationFeature[0], false); + destinationController.makeCheckin(indexController.currentDestinationFeature[0], false, ""); } - Get.back(); + //Get.back(); }, child: Text( indexController.currentDestinationFeature[0].checkedin == null || indexController.currentDestinationFeature[0].checkedin == false ? - "Chekin" + "チェックイン" : - "Checkput" + "チェックアウト" ) ), ], @@ -201,13 +230,13 @@ class BottomSheetNew extends GetView { onPressed: (){ destinationController.is_in_rog.value = true; destinationController.addToRogaining(destinationController.current_lat, destinationController.current_lon, indexController.currentDestinationFeature[0].location_id!); - Get.back(); + ExternalService().StartRogaining().then((value) => Get.back()); }, child: Text( indexController.currentDestinationFeature[0].checkedin != null || indexController.currentDestinationFeature[0].checkedin == true ? - "Start Rogaining" + "ロゲイニングを開始" : - "Wrong destination ..." + "間違った目的地..." ) ) : @@ -223,9 +252,9 @@ class BottomSheetNew extends GetView { }, child: Text( indexController.currentDestinationFeature[0].checkedin != null || indexController.currentDestinationFeature[0].checkedin == true ? - "Finish Rogaining" + "ロゲイニングを終える" : - "Wrong destination ..." + "間違った目的地 ..." ) ) : @@ -350,21 +379,21 @@ class BottomSheetNew extends GetView { ElevatedButton( onPressed: (){ if(indexController.currentDestinationFeature[0].checkedin == null || indexController.currentDestinationFeature[0].checkedin == false){ - destinationController.makeCheckin(indexController.currentDestinationFeature[0], true); + destinationController.makeCheckin(indexController.currentDestinationFeature[0], true, ""); if(indexController.currentDestinationFeature[0].cp != -1){ destinationController.rogaining_counted.value =true; } } else{ - destinationController.makeCheckin(indexController.currentDestinationFeature[0], false); + destinationController.makeCheckin(indexController.currentDestinationFeature[0], false, ""); } Get.back(); }, child: Text( indexController.currentDestinationFeature[0].checkedin == null || indexController.currentDestinationFeature[0].checkedin == false ? - "Chekin" + "チェックイン" : - "Checkput" + "チェックアウト" ) ), ], @@ -604,13 +633,13 @@ class BottomSheetNew extends GetView { //print("------ curent destination is ${dest!.checkedIn}-------"); if(dest != null){ //print("------ curent destination is ${dest!.checkedin}-------::::::::::"); - destinationController.makeCheckin(dest, !dest.checkedin!); + destinationController.makeCheckin(dest, !dest.checkedin!, ""); } }, child: indexController.currentDestinationFeature[0].checkedin == false ? - Text("Check in") + Text("チェックイン") : - Text("Check out") + Text("チェックアウト") ): Container() diff --git a/lib/widgets/destination_widget.dart b/lib/widgets/destination_widget.dart index c57cb51..c10b9a9 100644 --- a/lib/widgets/destination_widget.dart +++ b/lib/widgets/destination_widget.dart @@ -5,6 +5,7 @@ import 'package:get/get.dart'; import 'package:rogapp/model/destination.dart'; import 'package:rogapp/pages/destination/destination_controller.dart'; import 'package:rogapp/pages/index/index_controller.dart'; +import 'package:rogapp/utils/const.dart'; import 'package:rogapp/utils/database_helper.dart'; import 'package:rogapp/widgets/bottom_sheet_new.dart'; import 'package:rogapp/widgets/bottom_sheet_widget.dart'; @@ -35,8 +36,9 @@ class DestinationWidget extends StatelessWidget { ); } else { + String server_url = ConstValues.currentServer(); return Image(image: NetworkImage( - 'http://container.intranet.sumasen.net:8100/media/' + destinationController.destinations[index].photos!), + '${server_url}/media/' + destinationController.destinations[index].photos!), errorBuilder: (BuildContext context, Object exception, StackTrace? stackTrace) { return Image.asset("assets/images/empty_image.png"); }, diff --git a/pubspec.lock b/pubspec.lock index df2d054..5354119 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -562,6 +562,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.0" + modal_bottom_sheet: + dependency: "direct main" + description: + name: modal_bottom_sheet + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.2" path: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index ddb281d..34866ee 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -71,6 +71,7 @@ dependencies: circular_menu: ^2.0.1 camera_camera: ^3.0.0-dev intl: ^0.17.0 + modal_bottom_sheet: ^2.1.2 flutter_icons: android: true