Files
rog_app/lib/widgets/bottom_sheet_new.dart

1007 lines
45 KiB
Dart
Raw Normal View History

2023-11-21 22:43:28 +05:30
import 'dart:ui' as ui;
2024-04-24 11:30:38 +09:00
import 'dart:io';
import 'package:http/http.dart' as http;
import 'package:path_provider/path_provider.dart';
2022-06-27 12:15:54 +05:30
import 'package:flutter/material.dart';
2023-12-06 11:16:17 +05:30
import 'package:geojson_vi/geojson_vi.dart';
2023-02-16 19:36:39 +05:30
import 'package:geolocator/geolocator.dart';
2022-06-27 12:15:54 +05:30
import 'package:get/get.dart';
import 'package:image_picker/image_picker.dart';
2023-09-11 00:45:54 +05:30
import 'package:latlong2/latlong.dart';
import 'package:rogapp/main.dart';
2022-07-09 22:51:34 +05:30
import 'package:rogapp/model/destination.dart';
2023-11-21 22:43:28 +05:30
import 'package:rogapp/pages/camera/camera_page.dart';
2022-07-09 22:51:34 +05:30
import 'package:rogapp/pages/destination/destination_controller.dart';
2022-06-27 12:15:54 +05:30
import 'package:rogapp/pages/index/index_controller.dart';
2022-11-05 22:02:21 +05:30
import 'package:rogapp/services/external_service.dart';
2022-10-30 21:43:29 +05:30
import 'package:rogapp/utils/const.dart';
2022-07-09 22:51:34 +05:30
import 'package:rogapp/utils/database_helper.dart';
2022-10-12 21:46:17 +05:30
import 'package:rogapp/utils/text_util.dart';
2022-06-27 12:15:54 +05:30
import 'package:rogapp/widgets/bottom_sheet_controller.dart';
2023-11-28 15:58:37 +05:30
import 'package:rogapp/widgets/debug_widget.dart';
2022-06-27 12:15:54 +05:30
import 'package:url_launcher/url_launcher.dart';
2024-04-07 10:56:51 +09:00
// BottomSheetNewは、StatelessWidgetを継承したクラスで、目的地の詳細情報を表示するボトムシートのUIを構築します。
// コンストラクタでは、destination目的地オブジェクトとisAlreadyCheckedInすでにチェックイン済みかどうかのフラグを受け取ります。
// buildメソッドでは、detailsSheetメソッドを呼び出して、目的地の詳細情報を表示します。
//
2022-06-27 12:15:54 +05:30
class BottomSheetNew extends GetView<BottomSheetController> {
2023-11-21 22:43:28 +05:30
BottomSheetNew(
{this.isAlreadyCheckedIn = false, Key? key, required this.destination})
: super(key: key);
2022-06-27 12:15:54 +05:30
final IndexController indexController = Get.find<IndexController>();
2023-09-04 22:46:53 +05:30
final DestinationController destinationController =
Get.find<DestinationController>();
2024-04-07 10:56:51 +09:00
final Destination destination; // 目的地オブジェクト
final bool isAlreadyCheckedIn; // すでにチェックイン済みかどうかのフラグ
2022-07-14 23:10:24 +05:30
2024-04-07 10:56:51 +09:00
// 目的地の画像を取得するためのメソッドです。
// indexController.rogModeの値に基づいて、適切な画像を返します。画像が見つからない場合は、デフォルトの画像を返します。
//
2023-09-04 22:46:53 +05:30
Image getImage() {
2023-08-16 14:53:32 +05:30
String serverUrl = ConstValues.currentServer();
2023-10-06 16:25:21 +05:30
if (indexController.rogMode == 1) {
2023-09-04 22:46:53 +05:30
if (indexController.currentDestinationFeature.isEmpty ||
indexController.currentDestinationFeature[0].photos! == "") {
return const Image(image: AssetImage('assets/images/empty_image.png'));
} else {
//print("@@@@@@@@@@@@@ rog mode -------------------- ${indexController.currentDestinationFeature[0].photos} @@@@@@@@@@@");
2023-10-06 16:25:21 +05:30
String photo = indexController.currentDestinationFeature[0].photos!;
if (photo.contains('http')) {
2023-09-04 22:46:53 +05:30
return Image(
image: NetworkImage(
indexController.currentDestinationFeature[0].photos!,
2022-09-27 17:52:54 +05:30
),
2023-09-04 22:46:53 +05:30
errorBuilder: (BuildContext context, Object exception,
StackTrace? stackTrace) {
2022-09-27 17:52:54 +05:30
return Image.asset("assets/images/empty_image.png");
},
);
2023-09-04 22:46:53 +05:30
} else {
return Image(
image: NetworkImage(
2023-10-06 16:25:21 +05:30
'$serverUrl/media/compressed/${indexController.currentDestinationFeature[0].photos!}',
2022-09-27 17:52:54 +05:30
),
2023-09-04 22:46:53 +05:30
errorBuilder: (BuildContext context, Object exception,
StackTrace? stackTrace) {
2022-09-27 17:52:54 +05:30
return Image.asset("assets/images/empty_image.png");
},
2022-07-14 23:10:24 +05:30
);
2022-09-27 17:52:54 +05:30
}
2022-07-14 23:10:24 +05:30
}
2023-09-04 22:46:53 +05:30
} else {
2023-12-06 11:16:17 +05:30
GeoJSONFeature gf = indexController.currentFeature[0];
print("=== photo sss ${gf.properties!["photos"]}");
2023-09-04 22:46:53 +05:30
if (gf.properties!["photos"] == null || gf.properties!["photos"] == "") {
return const Image(image: AssetImage('assets/images/empty_image.png'));
} else {
2023-10-06 16:25:21 +05:30
String photo = gf.properties!["photos"];
if (photo.contains('http')) {
2023-09-04 22:46:53 +05:30
return Image(
image: NetworkImage(
gf.properties!["photos"],
2022-09-27 17:52:54 +05:30
),
2023-09-04 22:46:53 +05:30
errorBuilder: (BuildContext context, Object exception,
StackTrace? stackTrace) {
2022-09-27 17:52:54 +05:30
return Image.asset("assets/images/empty_image.png");
},
2023-09-04 22:46:53 +05:30
);
} else {
2023-11-24 11:58:17 +05:30
String imageUrl = Uri.encodeFull(
'$serverUrl/media/compressed/${gf.properties!["photos"]}');
2023-09-04 22:46:53 +05:30
return Image(
image: NetworkImage(
2023-11-24 11:58:17 +05:30
imageUrl,
2022-09-27 17:52:54 +05:30
),
2023-09-04 22:46:53 +05:30
errorBuilder: (BuildContext context, Object exception,
StackTrace? stackTrace) {
2022-09-27 17:52:54 +05:30
return Image.asset("assets/images/empty_image.png");
},
2023-09-04 22:46:53 +05:30
);
2022-09-27 17:52:54 +05:30
}
2023-09-04 22:46:53 +05:30
}
2022-07-14 23:10:24 +05:30
}
2022-06-27 12:15:54 +05:30
}
2024-04-07 10:56:51 +09:00
// URLを開くためのメソッドです。
// url_launcherパッケージを使用して、指定されたURLを開きます。
//
2022-06-27 12:15:54 +05:30
void _launchURL(url) async {
2023-10-06 16:25:21 +05:30
if (!await launchUrl(url)) throw 'Could not launch $url';
2022-06-27 12:15:54 +05:30
}
2024-04-07 10:56:51 +09:00
// 指定されたlocationidが目的地リストに含まれているかどうかを確認するメソッドです。
// destinationController.destinationsリストを走査し、locationidが一致する目的地があるかどうかを返します。
//
2023-09-04 22:46:53 +05:30
bool isInDestination(String locationid) {
2022-07-22 19:36:04 +05:30
int lid = int.parse(locationid);
2023-09-04 22:46:53 +05:30
if (destinationController.destinations
.where((element) => element.location_id == lid)
.isNotEmpty) {
2022-07-22 19:36:04 +05:30
return true;
2023-09-04 22:46:53 +05:30
} else {
2022-07-22 19:36:04 +05:30
return false;
}
}
2024-04-24 11:30:38 +09:00
Future<void> saveTemporaryImage(Destination destination) async {
final serverUrl = ConstValues.currentServer();
final imagePath = '${serverUrl}/media/compressed/${destination.photos}';
final tempDir = await getTemporaryDirectory();
final tempFile = await File('${tempDir.path}/temp_image.jpg').create(recursive: true);
final response = await http.get(Uri.parse(imagePath));
await tempFile.writeAsBytes(response.bodyBytes);
destinationController.photos.clear();
destinationController.photos.add(tempFile);
}
2024-04-07 10:56:51 +09:00
// アクションボタン(チェックイン、ゴールなど)を表示するためのメソッドです。
// 現在の状態に基づいて、適切なボタンを返します。
// ボタンがタップされたときの処理も含まれています。
//
2024-03-02 11:11:46 +05:30
Widget getActionButton(BuildContext context, Destination destination) {
2024-04-20 12:34:49 +09:00
/*
debugPrint("getActionButton ${destinationController.rogainingCounted.value}");
debugPrint("getActionButton ${destinationController.distanceToStart()}");
debugPrint("getActionButton ${destination.cp}");
debugPrint("getActionButton ${DestinationController.ready_for_goal}");
2024-04-03 21:39:12 +09:00
// ...2024-04-03 Akira デバッグモードのみ出力するようにした。
2024-04-20 12:34:49 +09:00
*/
2024-03-02 11:11:46 +05:30
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!));
2024-04-24 11:30:38 +09:00
// Check conditions to show confirmation dialog
if (destinationController.isInRog.value == false &&
(destinationController.distanceToStart() <= 500 || destinationController.isGpsSignalWeak() ) && //追加 Akira 2024-4-5
(destination.cp == -1 || destination.cp == 0 ) &&
destinationController.rogainingCounted.value == false) {
// ゲームが始まってなければ
return ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.secondary,
),
onPressed: destinationController.isInRog.value == false &&
(destinationController.distanceToStart() <= 100 || destinationController.isGpsSignalWeak() ) && //追加 Akira 2024-4-5
(destination.cp == -1 || destination.cp == 0 ) &&
destinationController.rogainingCounted.value == false ? () async {
// Show confirmation dialog
Get.dialog(
AlertDialog(
title: Text("confirm".tr), //confirm
content: Text(
"clear_rog_data_message".tr), //are you sure
2024-04-24 11:30:38 +09:00
actions: <Widget>[
TextButton(
child: Text("no".tr), //no
2024-04-24 11:30:38 +09:00
onPressed: () {
Get.back(); // Close the dialog
},
),
TextButton(
child: Text("yes".tr), //yes
2024-04-24 11:30:38 +09:00
onPressed: () async {
await saveTemporaryImage(destination);
// Clear data and start game logic here
destinationController.isInRog.value = true;
destinationController.resetRogaining();
2024-04-24 11:30:38 +09:00
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
);
}
: null,
child: Obx(
()=> Text(
destinationController.isInRog.value ? 'in_game'.tr : 'start_rogaining'.tr,
2024-04-24 11:30:38 +09:00
style: TextStyle(color: Colors.white),
),
),
);
//print("counted ${destinationController.rogainingCounted.value}");
}else if (destinationController.rogainingCounted.value == true &&
2024-04-07 10:56:51 +09:00
// destinationController.distanceToStart() <= 500 && ... GPS信号が弱い時でもOKとする。
(destinationController.distanceToStart() <= 500 || destinationController.isGpsSignalWeak() ) &&
2024-04-24 11:30:38 +09:00
(destination.cp == 0 || destination.cp == -2 || destination.cp == -1) &&
// (destination.cp == 0 || destination.cp == -2 ) &&
2024-03-02 11:11:46 +05:30
DestinationController.ready_for_goal == true) {
//goal
return ElevatedButton(
style: ElevatedButton.styleFrom(backgroundColor: Colors.red),
onPressed: destinationController.rogainingCounted.value == true &&
destinationController.distanceToStart() <= 500 &&
2024-04-24 11:30:38 +09:00
(destination.cp == 0 || destination.cp == -2|| destination.cp == -1) &&
2024-03-02 11:11:46 +05:30
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: Text(
"finish_rogaining".tr,
2024-03-02 11:11:46 +05:30
style: TextStyle(color: Colors.white),
));
} else if (distanceToDest <=
destinationController.getForcedChckinDistance(destination)) {
//start
return ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.secondary,
),
2024-04-20 12:34:49 +09:00
onPressed: isAlreadyCheckedIn == true
? null
: () async {
try{
destinationController.isCheckingIn.value = true; // ここを追加
2024-04-20 12:34:49 +09:00
Get.back();
await destinationController.callforCheckin(destination);
destinationController.isCheckingIn.value = false;
2024-04-20 12:34:49 +09:00
} catch (e) {
// エラーハンドリング
Get.snackbar(
'Error',
'An error occurred while processing check-in.',
backgroundColor: Colors.red,
colorText: Colors.white,
duration: Duration(seconds: 3),
);
// 必要に応じてエラーログを記録
print('Error processing check-in: $e');
}
},
2024-04-24 11:30:38 +09:00
/*
2024-03-02 11:11:46 +05:30
// Check conditions to show confirmation dialog
if (destinationController.isInRog.value == false &&
2024-04-07 10:56:51 +09:00
(destinationController.distanceToStart() <= 500 || destinationController.isGpsSignalWeak() ) && //追加 Akira 2024-4-5
destination.cp == -1 &&
2024-03-02 11:11:46 +05:30
destinationController.rogainingCounted.value == false) {
print("counted ${destinationController.rogainingCounted.value}");
2024-03-02 11:11:46 +05:30
// Show confirmation dialog
Get.dialog(
AlertDialog(
title: const Text("確認"), //confirm
content: const Text(
"ロゲを開始すると、今までのロゲデータが全てクリアされます。本当に開始しますか?"), //are you sure
actions: <Widget>[
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();
2024-03-02 11:11:46 +05:30
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
);
2024-03-08 15:31:49 +05:30
} else if (destinationController.isInRog.value == true &&
destination.cp != -1) {
//print("counted ${destinationController.rogainingCounted.value}");
2024-03-02 11:11:46 +05:30
// Existing logic for other conditions
2024-03-08 15:31:49 +05:30
2024-03-02 11:11:46 +05:30
Get.back();
await destinationController.callforCheckin(destination);
} else {
return;
2024-03-02 11:11:46 +05:30
}
},
2024-04-24 11:30:38 +09:00
*/
2024-03-02 11:11:46 +05:30
child: Text(
destination.cp == -1 &&
destinationController.isInRog.value == false &&
destinationController.rogainingCounted.value == false
? "ロゲ開始"
: destinationController.isInRog.value == true &&
destination.cp == -1
? "in_game".tr
2024-03-02 11:11:46 +05:30
: isAlreadyCheckedIn == true
? "in_game".tr
: destinationController.isInRog.value == true
? "checkin".tr
: "rogaining_not_started".tr,
2024-03-02 11:11:46 +05:30
style: TextStyle(color: Theme.of(context).colorScheme.onSecondary),
),
);
}
return Container();
}
2024-04-07 10:56:51 +09:00
// 継承元のbuild をオーバーライドし、detailsSheetメソッドを呼び出して、目的地の詳細情報を表示します。
2022-06-27 12:15:54 +05:30
@override
Widget build(BuildContext context) {
2024-03-02 11:11:46 +05:30
//print("to start ${destinationController.distanceToStart()}");
2023-10-06 16:25:21 +05:30
destinationController.skipGps = true;
2023-11-18 21:02:00 +05:30
// print('--- c use --- ${indexController.currentUser[0].values}');
// print('---- rog_mode ----- ${indexController.rogMode.value} -----');
2023-11-21 15:45:03 +05:30
// return indexController.rogMode.value == 0
// ? detailsSheet(context)
// : destinationSheet(context);
return Obx(() {
if (!destinationController.isCheckingIn.value) {
return detailsSheet(context);
} else {
return Container(); // チェックイン操作中は空のコンテナを返す
}
});
2022-07-14 23:10:24 +05:30
}
2024-04-07 10:56:51 +09:00
// 指定された目的地がすでにチェックイン済みかどうかを確認するメソッドです。
// DatabaseHelperを使用して、目的地の位置情報に基づいてデータベースを検索し、結果を返します。
//
2023-11-21 22:43:28 +05:30
Future<bool> isDestinationCheckedIn(Destination d) async {
DatabaseHelper db = DatabaseHelper.instance;
List<Destination> ds = await db.getDestinationByLatLon(d.lat!, d.lon!);
return ds.isNotEmpty;
2023-09-04 22:46:53 +05:30
}
// show add location details
2024-04-07 10:56:51 +09:00
// 目的地の詳細情報を表示するためのUIを構築するメソッドです。
// 目的地の画像、名前、住所、電話番号、Webサイト、備考などの情報を表示します。
// また、アクションボタンや「ここへ行く」ボタンも表示されます。
//
2023-09-04 22:46:53 +05:30
SingleChildScrollView detailsSheet(BuildContext context) {
2023-10-06 16:25:21 +05:30
Destination cdest = destinationController
.festuretoDestination(indexController.currentFeature[0]);
2023-09-11 00:45:54 +05:30
var distance = const Distance();
2023-10-06 16:25:21 +05:30
double distanceToDest = distance.as(
LengthUnit.Meter,
LatLng(
destinationController.currentLat, destinationController.currentLon),
LatLng(cdest.lat!, cdest.lon!));
2023-09-11 00:45:54 +05:30
2023-11-28 15:58:37 +05:30
LogManager().addLog("Distance from current point : $distanceToDest");
LogManager().addLog(
"forced distance for point : ${destinationController.getForcedChckinDistance(destination)}");
2023-11-29 10:20:19 +05:30
LogManager().addLog(
"current point : ${destinationController.currentLat}, ${destinationController.currentLon} - ${DateTime.now().hour}:${DateTime.now().minute}:${DateTime.now().second}:${DateTime.now().microsecond}");
//LogManager().addLog("is already checked in : $isAlreadyCheckedIn");
2023-11-28 15:58:37 +05:30
LogManager().addLog("Checkin radius : ${destination.checkin_radious}");
LogManager().addLog("--${destination.cp}--");
2023-09-04 22:46:53 +05:30
return SingleChildScrollView(
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
2023-10-06 16:25:21 +05:30
child: Row(
children: [
MaterialButton(
onPressed: () {
Get.back();
//indexController.makePrevious(indexController.currentFeature[0]);
},
color: Colors.blue,
textColor: Colors.white,
padding: const EdgeInsets.all(16),
shape: const CircleBorder(),
child: const Icon(
Icons.arrow_back_ios,
//Icons.arrow_back_ios,
size: 14,
2023-09-04 22:46:53 +05:30
),
2023-10-06 16:25:21 +05:30
),
Expanded(
child: Container(
alignment: Alignment.centerLeft,
2023-10-06 16:25:21 +05:30
child: Obx(() => Text(
2023-11-18 21:02:00 +05:30
"${TextUtils.getDisplayTextFeture(indexController.currentFeature[0])} : ${indexController.currentFeature[0].properties!["location_name"]}",
// indexController
// .currentFeature[0].properties!["location_name"],
2023-10-06 16:25:21 +05:30
style: const TextStyle(
fontSize: 15.0,
fontWeight: FontWeight.bold,
),
)),
2023-09-04 22:46:53 +05:30
),
2023-10-06 16:25:21 +05:30
),
],
2022-09-29 15:32:33 +05:30
),
2023-09-04 22:46:53 +05:30
),
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: [
// Finish or Goal
2024-03-02 11:11:46 +05:30
getActionButton(context, destination),
2023-11-21 22:43:28 +05:30
//remove checkin
isAlreadyCheckedIn == true && destination.cp != 0 && destination.cp != -1 && destination.cp != -2
2023-11-21 22:43:28 +05:30
? ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blueAccent),
2023-11-21 22:43:28 +05:30
onPressed: () async {
try {
await destinationController
.removeCheckin(destination.cp!.toInt());
destinationController
.deleteDestination(destination);
Get.back();
Get.snackbar(
'チェックイン取り消し',
'${destination
.name}',
backgroundColor: Colors.green,
colorText: Colors.white,
duration: Duration(seconds: 3),
);
} catch (e ) {
// エラーハンドリング
Get.snackbar(
'Error',
'An error occurred while canceling check-in.',
backgroundColor: Colors.red,
colorText: Colors.white,
duration: Duration(seconds: 3),
);
// 必要に応じてエラーログを記録
print('Error canceling check-in: $e');
}
2023-11-21 22:43:28 +05:30
},
child: Text(
"cancel_checkin".tr,
2024-03-02 11:11:46 +05:30
style: TextStyle(color: Colors.white),
)) //remove checkin
2023-11-21 22:43:28 +05:30
: Container(),
2023-09-04 22:46:53 +05:30
],
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context)
.colorScheme
.onPrimaryContainer),
2024-03-06 15:07:14 +05:30
onPressed: () async {
// print(
// "dist to start ${destinationController.distanceToStart()}");
Get.back();
//print("---- go to ----");
// GeoJSONMultiPoint mp = indexController
// .currentFeature[0] as GeoJSONMultiPoint;
Position position =
await Geolocator.getCurrentPosition(
desiredAccuracy:
LocationAccuracy.bestForNavigation,
forceAndroidLocationManager: true);
//print("------- position -------- $position");
Destination ds = Destination(
lat: position.latitude,
lon: position.longitude);
2023-09-04 22:46:53 +05:30
2024-03-06 15:07:14 +05:30
Destination tp = Destination(
lat: destination.lat, lon: destination.lon);
2023-09-04 22:46:53 +05:30
2024-03-06 15:07:14 +05:30
destinationController
.destinationMatrixFromCurrentPoint([ds, tp]);
},
//go here
2023-09-04 22:46:53 +05:30
child: Text(
"go_here".tr,
2023-09-04 22:46:53 +05:30
style: TextStyle(
color:
Theme.of(context).colorScheme.onPrimary),
)),
2023-10-06 16:25:21 +05:30
const SizedBox(
2023-09-06 15:25:12 +05:30
width: 10,
),
2023-09-11 00:45:54 +05:30
// forced start / checkin
2023-09-04 22:46:53 +05:30
],
),
Row(
children: [
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
indexController.currentDestinationFeature
.isNotEmpty &&
2023-10-06 16:25:21 +05:30
destinationController.isInCheckin.value ==
2023-09-04 22:46:53 +05:30
true
? Container()
: FutureBuilder<Widget>(
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"]))
: const SizedBox(
width: 0.0,
height: 0,
),
],
),
),
],
),
const SizedBox(
height: 8.0,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
const Icon(Icons.roundabout_left),
const SizedBox(
width: 8.0,
),
indexController.currentFeature[0]
.properties!["address"] !=
null &&
(indexController.currentFeature[0]
.properties!["address"] as String)
.isNotEmpty
? getDetails(
context,
"address".tr,
indexController.currentFeature[0]
.properties!["address"] ??
'')
: const SizedBox(
width: 0.0,
height: 0,
),
],
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
const Icon(Icons.phone),
const SizedBox(
width: 8.0,
),
indexController.currentFeature[0]
.properties!["phone"] !=
null &&
(indexController.currentFeature[0]
.properties!["phone"] as String)
.isNotEmpty
? getDetails(
context,
"telephone".tr,
indexController.currentFeature[0]
.properties!["phone"] ??
'')
: const SizedBox(
width: 0.0,
height: 0,
),
],
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
const Icon(Icons.email),
const SizedBox(
width: 8.0,
),
indexController.currentFeature[0]
.properties!["email"] !=
null &&
(indexController.currentFeature[0]
.properties!["email"] as String)
.isNotEmpty
? getDetails(
context,
"email".tr,
indexController.currentFeature[0]
.properties!["email"] ??
'')
: const SizedBox(
width: 0.0,
height: 0,
),
],
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
const Icon(Icons.language),
const SizedBox(
width: 8.0,
),
indexController.currentFeature[0]
.properties!["webcontents"] !=
null &&
(indexController.currentFeature[0]
.properties!["webcontents"] as String)
.isNotEmpty
? getDetails(
context,
"web".tr,
indexController.currentFeature[0]
.properties!["webcontents"] ??
'',
isurl: true)
: const SizedBox(
width: 0.0,
height: 0,
),
],
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
const SizedBox(
width: 8.0,
),
indexController.currentFeature[0]
.properties!["remark"] !=
null &&
(indexController.currentFeature[0]
.properties!["remark"] as String)
.isNotEmpty
? getDetails(
context,
"remarks".tr,
indexController.currentFeature[0]
.properties!["remark"] ??
'',
isurl: false)
: const SizedBox(
width: 0.0,
height: 0,
),
],
),
),
// Text('${TextUtils.getDisplayText(indexController.currentFeature[0].properties!["cp"].toString())} - id: ${TextUtils.getDisplayText(indexController.currentFeature[0].properties!["checkin_point"].toString())}'),
],
),
)),
const SizedBox(
height: 60.0,
)
],
),
);
2022-06-27 12:15:54 +05:30
}
2024-04-07 10:56:51 +09:00
// 「行きたい」ボタンを表示するためのUIを構築するメソッドです。
// 目的地が選択されているかどうかに基づいて、適切なアイコンとテキストを表示します。
// ボタンがタップされたときの処理も含まれています。
//
2023-09-04 22:46:53 +05:30
Future<Widget> wantToGo(BuildContext context) async {
2023-10-06 16:25:21 +05:30
bool selected = false;
// print(
// '---target-- ${indexController.currentFeature[0].properties!["location_id"]}----');
2023-09-04 22:46:53 +05:30
for (Destination d in destinationController.destinations) {
2023-10-06 16:25:21 +05:30
//print('---- ${d.location_id.toString()} ----');
2023-09-04 22:46:53 +05:30
if (d.location_id ==
indexController.currentFeature[0].properties!["location_id"]) {
2023-10-06 16:25:21 +05:30
selected = true;
2022-09-27 17:52:54 +05:30
break;
}
}
2022-07-14 23:10:24 +05:30
2022-07-10 23:50:43 +05:30
DatabaseHelper db = DatabaseHelper.instance;
2023-09-04 22:46:53 +05:30
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
// indexController.rog_mode == 0 ?
// // IconButton(
// // icon: Icon(Icons.pin_drop_sharp, size: 32, color: _selected == true ? Colors.amber : Colors.blue,),
// // onPressed: (){
// // if(_selected){
// // // show remove from destination
// // Get.defaultDialog(
// // title: "本当にこのポイントを通過順から外しますか?",
// // middleText: "場所は目的地リストから削除されます",
// // backgroundColor: Colors.blue.shade300,
// // titleStyle: TextStyle(color: Colors.white),
// // middleTextStyle: TextStyle(color: Colors.white),
// // textConfirm: "はい",
// // textCancel: "いいえ",
// // cancelTextColor: Colors.white,
// // confirmTextColor: Colors.blue,
// // buttonColor: Colors.white,
// // barrierDismissible: false,
// // radius: 10,
// // content: Column(
// // children: [
// // ],
// // ),
// // onConfirm: (){
// // int _id = indexController.currentFeature[0].properties!["location_id"];
// // Destination? d = destinationController.destinationById(_id);
// // print('--- des id is : ${d} -----');
// // if(d != null) {
// // //print('--- des id is : ${d.location_id} -----');
// // destinationController.deleteDestination(d);
// // Get.back();
// // Get.back();
// // Get.snackbar("追加した", "場所が削除されました");
// // }
// // }
// // );
// // return;
// // }
// // // show add to destination
// // Get.defaultDialog(
// // title: "この場所を登録してもよろしいですか",
// // middleText: "ロケーションがロガニング リストに追加されます",
// // backgroundColor: Colors.blue.shade300,
// // titleStyle: TextStyle(color: Colors.white),
// // middleTextStyle: TextStyle(color: Colors.white),
// // textConfirm: "はい",
// // textCancel: "いいえ",
// // cancelTextColor: Colors.white,
// // confirmTextColor: Colors.blue,
// // buttonColor: Colors.white,
// // barrierDismissible: false,
// // radius: 10,
// // content: Column(
// // children: [
// // ],
// // ),
// // onConfirm: (){
// // GeoJsonMultiPoint mp = indexController.currentFeature[0].geometry as GeoJsonMultiPoint;
// // LatLng pt = LatLng(mp.geoSerie!.geoPoints[0].latitude, mp.geoSerie!.geoPoints[0].longitude);
// // print("----- want to go sub location is ---- ${indexController.currentFeature[0].properties!["sub_loc_id"]} -----");
// // Destination dest = Destination(
// // name: indexController.currentFeature[0].properties!["location_name"],
// // address: indexController.currentFeature[0].properties!["address"],
// // phone: indexController.currentFeature[0].properties!["phone"],
// // email: indexController.currentFeature[0].properties!["email"],
// // webcontents: indexController.currentFeature[0].properties!["webcontents"],
// // videos: indexController.currentFeature[0].properties!["videos"],
// // category: indexController.currentFeature[0].properties!["category"],
// // series: 1,
// // lat: pt.latitude,
// // lon: pt.longitude,
// // sub_loc_id: indexController.currentFeature[0].properties!["sub_loc_id"],
// // location_id: indexController.currentFeature[0].properties!["location_id"],
// // list_order: 1,
// // photos: indexController.currentFeature[0].properties!["photos"],
// // checkin_radious: indexController.currentFeature[0].properties!["checkin_radius"],
// // auto_checkin: indexController.currentFeature[0].properties!["auto_checkin"] == true ? 1 : 0,
// // cp: indexController.currentFeature[0].properties!["cp"],
// // checkin_point: indexController.currentFeature[0].properties!["checkin_point"],
// // buy_point: indexController.currentFeature[0].properties!["buy_point"],
// // selected: false,
// // checkedin: false,
// // hidden_location: indexController.currentFeature[0].properties!["hidden_location"] == true ?1 : 0
// // );
// // destinationController.addDestinations(dest);
// // Get.back();
// // Get.back();
// // Get.snackbar("追加した", "場所が追加されました");
// // }
// // );
// // },
// // ):
// // Container(),
const SizedBox(
width: 8.0,
),
2023-10-06 16:25:21 +05:30
Obx((() => indexController.rogMode.value == 1
2023-09-04 22:46:53 +05:30
? ElevatedButton(
onPressed: () async {
Destination dest =
indexController.currentDestinationFeature[0];
2023-10-06 16:25:21 +05:30
//print("~~~~ before checking button ~~~~");
2023-09-04 22:46:53 +05:30
//print("------ curent destination is ${dest!.checkedIn}-------");
destinationController.makeCheckin(
dest, !dest.checkedin!, "");
},
child: indexController
.currentDestinationFeature[0].checkedin ==
false
? const Text("チェックイン")
: const Text("チェックアウト"))
: Container())),
],
),
],
);
2022-07-09 22:51:34 +05:30
}
2023-09-04 22:46:53 +05:30
Widget getCheckin(BuildContext context) {
2022-07-25 19:56:32 +05:30
//print("------ currentAction ----- ${indexController.currentAction}-----");
2022-07-09 22:51:34 +05:30
2022-06-27 12:15:54 +05:30
return Row(
2023-09-04 22:46:53 +05:30
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
indexController.currentAction[0][0]["checkin"] == false
? Column(
children: [
Row(
mainAxisSize: MainAxisSize.max,
2022-07-14 23:10:24 +05:30
children: [
2023-09-04 22:46:53 +05:30
ElevatedButton(
child: const Text("Image"),
onPressed: () {
2023-10-06 16:25:21 +05:30
final ImagePicker picker = ImagePicker();
picker
2023-09-04 22:46:53 +05:30
.pickImage(source: ImageSource.camera)
.then((value) {
2022-07-25 19:56:32 +05:30
//print("----- image---- ${value!.path}");
2022-07-14 23:10:24 +05:30
});
},
2023-09-04 22:46:53 +05:30
)
2022-07-14 23:10:24 +05:30
],
2023-09-04 22:46:53 +05:30
),
2022-07-14 23:10:24 +05:30
ElevatedButton(
2023-09-04 22:46:53 +05:30
onPressed: () {
if (indexController.currentAction.isNotEmpty) {
//print(indexController.currentAction[0]);
indexController.currentAction[0][0]["checkin"] =
true;
Map<String, dynamic> temp =
Map<String, dynamic>.from(
indexController.currentAction[0][0]);
indexController.currentAction.clear();
//print("---temp---${temp}");
indexController.currentAction.add([temp]);
}
},
child: Text("checkin".tr))
],
)
: ElevatedButton(
onPressed: () {
if (indexController.currentAction.isNotEmpty) {
//print(indexController.currentAction[0]);
indexController.currentAction[0][0]["checkin"] = false;
Map<String, dynamic> temp = Map<String, dynamic>.from(
indexController.currentAction[0][0]);
indexController.currentAction.clear();
//print("---temp---${temp}");
indexController.currentAction.add([temp]);
2022-07-15 21:50:14 +05:30
}
},
2023-09-04 22:46:53 +05:30
child: const Icon(Icons.favorite, color: Colors.red),
)
],
)
],
);
2022-06-27 12:15:54 +05:30
}
2024-04-07 10:56:51 +09:00
// 目的地の詳細情報住所、電話番号、Webサイトなどを表示するためのUIを構築するメソッドです。
// ラベルとテキストを受け取り、適切なアイコンとともに表示します。
//
2023-09-04 22:46:53 +05:30
Widget getDetails(BuildContext context, String label, String text,
{bool isurl = false}) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(label),
const SizedBox(
width: 10.0,
),
InkWell(
onTap: () {
if (isurl) {
2023-10-06 16:25:21 +05:30
if (indexController.rogMode.value == 0) {
2023-09-04 22:46:53 +05:30
_launchURL(indexController
.currentFeature[0].properties!["webcontents"]);
} else {
indexController.currentDestinationFeature[0].webcontents;
}
}
},
child: SizedBox(
2023-10-06 16:25:21 +05:30
width: MediaQuery.of(context).size.width -
2023-11-19 15:30:26 +05:30
(MediaQuery.of(context).size.width * 0.35),
2023-09-11 18:04:29 +05:30
child: Text(
text,
textAlign: TextAlign.justify,
style: TextStyle(
color: isurl ? Colors.blue : Colors.black,
2023-09-04 22:46:53 +05:30
),
),
),
),
],
);
}
2023-09-06 15:25:12 +05:30
}