import 'package:flutter/material.dart'; import 'package:geojson/geojson.dart'; import 'package:geolocator/geolocator.dart'; 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/model/location_response.dart'; import 'package:rogapp/routes/app_pages.dart'; import 'package:rogapp/screens/auth/controller/auth_controller.dart'; import 'package:rogapp/screens/home/home_controller.dart'; import 'package:rogapp/screens/home/location_controller.dart'; import 'package:rogapp/services/external_service.dart'; import 'package:rogapp/utils/checkin_db_helper.dart'; import 'package:rogapp/utils/const.dart'; import 'package:rogapp/utils/database_helper.dart'; import 'package:rogapp/utils/text_util.dart'; import 'package:rogapp/widgets/bottom_sheet_controller.dart'; import 'package:url_launcher/url_launcher.dart'; class BottomSheetNew extends GetView { BottomSheetNew({ Key? key }) : super(key: key); //final IndexController indexController = Get.find(); //final DestinationController destinationController = Get.find(); HomeController homeController = Get.find(); LocationController locationController = Get.find(); AuthController authController = Get.find(); CheckinDBHelper checkinDBHelper = CheckinDBHelper.instance; Image getImage(){ String server_url = ConstValues.currentServer(); //print("----- rogaining mode 1"); if(homeController.currentFeature.isEmpty || homeController.currentFeature[0].properties!.photos == ""){ return Image(image: AssetImage('assets/images/empty_image.png')); } else{ //print("@@@@@@@@@@@@@ rog mode -------------------- ${indexController.currentDestinationFeature[0].photos} @@@@@@@@@@@"); String _photo = homeController.currentFeature[0].properties!.photos!; if(_photo.contains('http')){ return Image(image: NetworkImage( homeController.currentFeature[0].properties!.photos!, ), errorBuilder: (BuildContext context, Object exception, StackTrace? stackTrace) { return Image.asset("assets/images/empty_image.png"); }, ); } else { return Image(image: NetworkImage( '${server_url}/media/compressed/' + homeController.currentFeature[0].properties!.photos!, ), errorBuilder: (BuildContext context, Object exception, StackTrace? stackTrace) { return Image.asset("assets/images/empty_image.png"); }, ); } } } void _launchURL(url) async { if (!await launch(url)) throw 'Could not launch $url'; } // bool isInDestination(String locationid){ // int lid = int.parse(locationid); // if(destinationController.destinations.where((element) => element.location_id == lid).length > 0){ // return true; // } // else{ // return false; // } // } @override Widget build(BuildContext context) { locationController.skip_gps = true; return destinationSheet(context); } // Show destination detais SingleChildScrollView destinationSheet(BuildContext context) { return SingleChildScrollView( child: Column( children: [ Padding( padding: const EdgeInsets.all(8.0), child: Container( child: Row( children: [ MaterialButton( onPressed: () { Get.back(); //destinationController.makePrevious(indexController.currentDestinationFeature[0]); }, color: Colors.blue, textColor: Colors.white, child: Icon( Icons.arrow_back_ios, size: 14, ), padding: EdgeInsets.all(16), shape: CircleBorder(), ), Expanded( child: Container( alignment: Alignment.center, child: Obx(() => authController.authList.isNotEmpty ? Text("${TextUtils.getDisplayText(homeController.currentFeature[0])} : ${TextUtils.getDisplayText(homeController.currentFeature[0])} : ${homeController.currentFeature[0].properties!.location_name}", style: TextStyle( fontSize: 15.0, fontWeight: FontWeight.bold, ), ) : Text("${homeController.currentFeature[0].properties!.location_name}", style: TextStyle( fontSize: 15.0, fontWeight: FontWeight.bold, ), ) ), ), ), ], ), ), ), Row( children: [ Expanded( child: SizedBox( height: 260.0, child: Obx(() => getImage()), ) ), ], ), Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Obx(() => homeController.currentBound.isNotEmpty && locationController.is_in_checkin.value == true && locationController.is_at_start.value == false ? Row( children: [ ElevatedButton( onPressed: () async { final _locId = homeController.currentFeature[0].location_id; final _exist = await checkinDBHelper.exists(_locId!); if(_exist){ if(homeController.currentFeature[0].properties!.hidden_location == 0){ locationController.skip_gps = false; locationController.is_photo_shoot.value = true; Get.back(); } else{ locationController.makeCheckin(homeController.currentFeature[0], true, ""); if(homeController.currentFeature[0].properties!.cp != -1){ locationController.rogaining_counted.value =true; } } } else{ locationController.makeCheckin(homeController.currentFeature[0], false, ""); } //Get.back(); }, child: FutureBuilder( future: checkinDBHelper.exists(homeController.currentFeature[0].location_id!), builder: (BuildContext context, AsyncSnapshot snapshot){ if (snapshot.connectionState == ConnectionState.waiting) { return CircularProgressIndicator(); // return a circular progress indicator while waiting } else { if (snapshot.hasError) return Text('Error: ${snapshot.error}'); // return error text if something went wrong else return snapshot.data! ? const Text("チェックイン") : // Widget to show if locationId exists const Text("チェックアウト"); } }, ), ), ], ) : Container(), ), Obx(() => locationController.is_at_start.value == true ? ElevatedButton( onPressed: (){ locationController.is_in_rog.value = true; locationController.addToRogaining(locationController.current_lat, locationController.current_lon, homeController.currentFeature[0].location_id!); ExternalService().StartRogaining().then((value) => Get.back()); }, child: FutureBuilder( future: checkinDBHelper.exists(homeController.currentFeature[0].location_id!), builder: (context, snapshot){ if (snapshot.connectionState == ConnectionState.waiting) { return CircularProgressIndicator(); // return a circular progress indicator while waiting } else { if (snapshot.hasError) return Text('Error: ${snapshot.error}'); // return error text if something went wrong else return snapshot.data! ? const Text("ロゲイニングを開始") : // Widget to show if locationId exists const Text("間違った目的地..."); } }, ) ) : Container(), ), Obx(() => locationController.is_at_goal.value == true && locationController.rogaining_counted ==true ? ElevatedButton( onPressed: (){ Get.toNamed(AppPages.CAMERA_PAGE); Get.back(); }, child: FutureBuilder( future: checkinDBHelper.exists(homeController.currentFeature[0].location_id!), builder: (context, snapshot){ if (snapshot.connectionState == ConnectionState.waiting) { return CircularProgressIndicator(); // return a circular progress indicator while waiting } else { if (snapshot.hasError) return Text('Error: ${snapshot.error}'); // return error text if something went wrong else return snapshot.data! ? const Text("ロゲイニングを終える") : // Widget to show if locationId exists const Text("間違った目的地 ..."); } }, ) ) : Container(), ), ], ), Obx(() => homeController.currentFeature[0].properties!.address != null ? getDetails(context, "address".tr, homeController.currentFeature[0].properties!.address! ?? '') : Container(width: 0.0, height: 0,), ), Obx(() => homeController.currentFeature[0].properties!.phone != null ? getDetails(context, "telephone".tr, homeController.currentFeature[0].properties!.phone! ?? '') : Container(width: 0.0, height: 0,), ), Obx(() => homeController.currentFeature[0].properties!.email != null ? getDetails(context, "email".tr, homeController.currentFeature[0].properties!.email! ?? '') : Container(width: 0.0, height: 0,), ), Obx(() => homeController.currentFeature[0].properties!.webcontents != null ? getDetails(context, "web".tr, homeController.currentFeature[0].properties!.webcontents! ?? '', isurl: true) : Container(width: 0.0, height: 0,), ), Obx(() => homeController.currentFeature[0].properties!.videos != null ? getDetails(context, "video".tr, homeController.currentFeature[0].properties!.videos! ?? '', isurl: true) : Container(width: 0.0, height: 0,), ), SizedBox(height: 20.0,), // Obx(() => // //wantToGo(context), // FutureBuilder( // future: wantToGo(context), // builder: (context, snapshot) { // return Container( // child: snapshot.data, // ); // }, // ), // ), SizedBox(height: 60.0,) ], ), ); } // show add location details SingleChildScrollView detailsSheet(BuildContext context) { return SingleChildScrollView( child: Column( children: [ Padding( padding: const EdgeInsets.all(8.0), child: Container( child: Row( children: [ MaterialButton( onPressed: () { Get.back(); //indexController.makePrevious(indexController.currentFeature[0]); }, color: Colors.blue, textColor: Colors.white, child: Icon( Icons.arrow_back_ios, //Icons.arrow_back_ios, size: 14, ), padding: EdgeInsets.all(16), shape: CircleBorder(), ), Expanded( child: Container( alignment: Alignment.center, child: Obx(() => Text(homeController.currentFeature[0].properties!.location_name!, style: TextStyle( fontSize: 15.0, fontWeight: FontWeight.bold, ), ) ), ), ), ], ), ), ), Row( children: [ Expanded( child: SizedBox( height: 260.0, child: Obx(() => getImage()), ) ), ], ), Obx(() => Padding( padding: const EdgeInsets.all(8.0), child: Column( children: [ Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Obx(() => FutureBuilder( future: checkinDBHelper.exists(homeController.currentFeature[0].location_id!), builder: (context, snapshot){ if (snapshot.connectionState == ConnectionState.waiting) { return CircularProgressIndicator(); // return a circular progress indicator while waiting } else { if (snapshot.hasError) return Text('Error: ${snapshot.error}'); // return error text if something went wrong else if(homeController.currentFeature[0].properties!.cp == -1 && locationController.is_at_start.value ==true){ return ElevatedButton( onPressed: (){ locationController.is_in_rog.value = true; locationController.addToRogaining(locationController.current_lat, locationController.current_lon, homeController.currentFeature[0].location_id!); ExternalService().StartRogaining().then((value) => Get.back()); }, child: Text( // start snapshot.data! == true ? "ロゲイニングを開始" : "間違った目的地..." ) ); } else { return Container(); } } }, ) ), Obx(() => locationController.is_at_goal.value == true && locationController.rogaining_counted ==true ? ElevatedButton( onPressed: (){ Get.toNamed(AppPages.CAMERA_PAGE); Get.back(); }, child: FutureBuilder( future: checkinDBHelper.exists(homeController.currentFeature[0].location_id!), builder: (context, snapshot){ if (snapshot.connectionState == ConnectionState.waiting) { return CircularProgressIndicator(); // return a circular progress indicator while waiting } else { if (snapshot.hasError) return Text('Error: ${snapshot.error}'); // return error text if something went wrong else return snapshot.data! ? const Text("ロゲイニングを終える") : // Widget to show if locationId exists const Text("間違った目的地 ..."); } }, ) ) : Container(), ), ], ), Row( children: [ Expanded( child: Row( mainAxisAlignment: MainAxisAlignment.start, children: [ FutureBuilder( future: checkinDBHelper.exists(homeController.currentFeature[0].location_id!), builder: (context, snapshot){ if (snapshot.connectionState == ConnectionState.waiting) { return CircularProgressIndicator(); // return a circular progress indicator while waiting } else { if (snapshot.hasError) return Text('Error: ${snapshot.error}'); // return error text if something went wrong else{ if(snapshot.data == true){ return Container(); } else{ return FutureBuilder( 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"])) // : // Container(width: 0.0, height: 0,), ], ), ), ElevatedButton( onPressed:() async { Feature mp = homeController.currentFeature[0]; Position position = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high); Feature ds = Feature( latitude: position.latitude, longitude: position.longitude ); Feature tp = Feature( latitude: mp.latitude, longitude: mp.longitude ); Get.back(); locationController.destinationMatrixFromCurrentPoint([ds, tp]); }, child:Text("ここへ行く")), ], ), SizedBox(height: 8.0,), Padding( padding: const EdgeInsets.all(8.0), child: Row( children: [ Icon(Icons.roundabout_left), SizedBox(width: 8.0,), homeController.currentFeature[0].properties!.address != null && homeController.currentFeature[0].properties!.address!.isNotEmpty ? getDetails(context, "address".tr, homeController.currentFeature[0].properties!.address ?? '') : Container(width: 0.0, height: 0,), ], ), ), Padding( padding: const EdgeInsets.all(8.0), child: Row( children: [ Icon(Icons.phone), SizedBox(width: 8.0,), homeController.currentFeature[0].properties!.phone != null && homeController.currentFeature[0].properties!.phone!.isNotEmpty ? getDetails(context, "telephone".tr, homeController.currentFeature[0].properties!.phone ?? '') : Container(width: 0.0, height: 0,), ], ), ), Padding( padding: const EdgeInsets.all(8.0), child: Row( children: [ Icon(Icons.email), SizedBox(width: 8.0,), homeController.currentFeature[0].properties!.email != null && homeController.currentFeature[0].properties!.email!.isNotEmpty ? getDetails(context, "email".tr, homeController.currentFeature[0].properties!.email ?? '') : Container(width: 0.0, height: 0,), ], ), ), Padding( padding: const EdgeInsets.all(8.0), child: Row( children: [ Icon(Icons.language), SizedBox(width: 8.0,), homeController.currentFeature[0].properties!.webcontents != null && homeController.currentFeature[0].properties!.webcontents!.isNotEmpty ? getDetails(context, "web".tr, homeController.currentFeature[0].properties!.webcontents ?? '', isurl: true) : Container(width: 0.0, height: 0,), ], ), ), Padding( padding: const EdgeInsets.all(8.0), child: Row( children: [ SizedBox(width: 8.0,), homeController.currentFeature[0].properties!.remark != null && homeController.currentFeature[0].properties!.remark!.isNotEmpty ? getDetails(context, "remarks".tr, homeController.currentFeature[0].properties!.remark ?? '', isurl: false) : Container(width: 0.0, height: 0,), ], ), ), // Text('${TextUtils.getDisplayText(indexController.currentFeature[0].properties!["cp"].toString())} - id: ${TextUtils.getDisplayText(indexController.currentFeature[0].properties!["checkin_point"].toString())}'), ], ), ) ), SizedBox(height: 60.0,) ], ), ); } Future wantToGo(BuildContext context)async { bool _selected = await checkinDBHelper.exists(homeController.currentFeature[0].location_id!); DatabaseHelper db = DatabaseHelper.instance; return Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ ElevatedButton( onPressed: () async { Feature dest = homeController.currentFeature[0]; //print("------ curent destination is ${dest!.checkedIn}-------"); if(dest != null){ //print("------ curent destination is ${dest!.checkedin}-------::::::::::"); bool checkin = await checkinDBHelper.exists(homeController.currentFeature[0].location_id!); locationController.makeCheckin(dest, checkin, ""); } }, child: FutureBuilder( future: checkinDBHelper.exists(homeController.currentFeature[0].location_id!), builder: (context, snapshot){ if (snapshot.connectionState == ConnectionState.waiting) { return CircularProgressIndicator(); }else { if (snapshot.hasError) return Text('Error: ${snapshot.error}'); // return error text if something went wrong else return snapshot.data! ? const Text("チェックイン") : // Widget to show if locationId exists const Text("チェックアウト"); } }, ) ) ], ), ], ); } // Widget getCheckin(BuildContext context){ // //print("------ currentAction ----- ${indexController.currentAction}-----"); // return Row( // mainAxisAlignment: MainAxisAlignment.center, // children: [ // Row( // mainAxisAlignment: MainAxisAlignment.center, // children: [ // indexController.currentAction[0][0]["checkin"] == false ? // Column( // children: [ // Row( // mainAxisSize: MainAxisSize.max, // children: [ // ElevatedButton( // child: Text("Image"), onPressed: (){ // final ImagePicker _picker = ImagePicker(); // _picker.pickImage(source: ImageSource.camera).then((value){ // //print("----- image---- ${value!.path}"); // }); // }, // ) // ], // ), // ElevatedButton( // onPressed: (){}, // //onPressed: (){ // // if(indexController.currentAction.isNotEmpty){ // // //print(indexController.currentAction[0]); // // indexController.currentAction[0][0]["checkin"] = true; // // Map temp = Map.from(indexController.currentAction[0][0]); // // indexController.currentAction.clear(); // // //print("---temp---${temp}"); // // indexController.currentAction.add([temp]); // // } // // indexController.makeAction(context); // // }, // child: Text("checkin".tr) // ) // ], // ) // : // ElevatedButton( // onPressed: (){}, // // onPressed: (){ // // if(indexController.currentAction.isNotEmpty){ // // //print(indexController.currentAction[0]); // // indexController.currentAction[0][0]["checkin"] = false; // // Map temp = Map.from(indexController.currentAction[0][0]); // // indexController.currentAction.clear(); // // //print("---temp---${temp}"); // // indexController.currentAction.add([temp]); // // } // // indexController.makeAction(context); // // }, // child: Icon( // Icons.favorite, color: Colors.red) // , // ) // ], // ) // ], // ); // } Widget getDetails(BuildContext context, String label, String text, {bool isurl=false}){ return Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Text(label), SizedBox(width: 10.0,), InkWell( onTap: (){ if(isurl){ _launchURL(homeController.currentFeature[0].properties!.webcontents); } }, child: Container( width: MediaQuery.of(context).size.width - 160, child: Text(text, style: TextStyle( color: isurl ? Colors.blue : Colors.black, ), ), ), ), ], ); } }