Files
rog_app/lib/pages/camera/camera_page.dart

763 lines
33 KiB
Dart
Raw Normal View History

2023-01-26 23:30:48 +05:30
import 'dart:async';
2024-08-01 20:08:12 +09:00
import 'dart:convert'; // この行を追加または確認
2023-01-26 23:30:48 +05:30
2022-10-12 21:46:17 +05:30
import 'package:flutter/material.dart';
import 'package:get/get.dart';
2022-10-19 08:53:17 +05:30
import 'package:intl/intl.dart';
2023-03-03 17:45:03 +05:30
import 'package:rogapp/model/destination.dart';
2022-10-12 21:46:17 +05:30
import 'package:rogapp/pages/destination/destination_controller.dart';
2022-10-19 08:53:17 +05:30
import 'package:rogapp/pages/index/index_controller.dart';
import 'package:rogapp/services/external_service.dart';
2023-11-07 17:17:47 +05:30
import 'package:rogapp/utils/const.dart';
2024-04-20 12:34:49 +09:00
import 'package:qr_code_scanner/qr_code_scanner.dart';
2023-11-07 17:17:47 +05:30
2024-08-01 20:08:12 +09:00
import 'package:http/http.dart' as http; // この行を追加
2024-04-20 12:34:49 +09:00
// 関数 getTagText は、特定の条件に基づいて文字列から特定の部分を抽出し、返却するためのものです。
// 関数は2つのパラメータを受け取り、条件分岐を通じて結果を返します。
//
// この関数は、タグのリスト(空白を含む文字列)を適切に解析し、条件に応じて特定のタグを抽出するために設計されています。
// 異なる種類の空白文字半角、全角で異なる分割を行い、与えられた条件isReceptに応じて適切なタグを選択して返却します。
//
2023-11-20 14:01:28 +05:30
String getTagText(bool isRecept, String? tags) {
2024-04-20 12:34:49 +09:00
// bool isRecept: 真偽値を受け取り、この値によって処理の分岐が行われます。
// String? tags: オプショナルな文字列null が許容される)。空白文字を含む可能性のあるタグのリストを表します。
// 空のチェック:
// tags が null または空文字列 ("") の場合、何も含まれていないことを意味し、関数はただちに空文字列を返します。
//
2023-11-20 14:01:28 +05:30
if (tags == null || tags.isEmpty) {
return "";
}
2024-04-20 12:34:49 +09:00
// タグの分割:
// tags が空ではない場合、文字列を空白文字で分割します。
// ここで2種類の空白文字半角 " " と全角 " "に対応するため、2回分割を行っています。
// tts: 半角スペース " " で分割した結果のリスト。
// ttt: 全角スペース " " で分割した結果のリスト。
//
2023-11-20 14:01:28 +05:30
List<String> tts = tags.split(" ");
List<String> ttt = tags.split(" ");
2024-04-20 12:34:49 +09:00
// 条件分岐:
// isRecept の値によって、処理が分岐します。
//
2023-11-20 14:01:28 +05:30
if (isRecept) {
2024-04-20 12:34:49 +09:00
// isRecept が true の場合:
// 全角スペースで分割した結果 (ttt) の長さが半角スペースで分割した結果 (tts) の長さより大きく、
// かつ ttt が1つ以上の要素を持つ場合、ttt[1] 全角スペースで分割後の2番目の要素を返します。
2023-11-20 14:01:28 +05:30
if (ttt.length > tts.length && ttt.length > 1) {
return ttt[1];
}
}
if (!isRecept) {
2024-04-20 12:34:49 +09:00
// isRecept が false の場合:
// 全角スペースで分割したリストが半角スペースで分割したリストよりも長い場合、ttt[0] (全角スペースで分割後の最初の要素)を返します。
// 上記の条件に当てはまらない場合、半角スペースで分割したリストの最初の要素 tts[0] を返します。
//
2023-11-20 14:01:28 +05:30
if (ttt.length > tts.length && ttt.length > 1) {
return ttt[0];
}
}
if (!isRecept) {
2024-04-20 12:34:49 +09:00
// 最終的な返却:
// 上記の条件に何も該当しない場合(主に isRecept が true であり、全角スペースの条件に該当しない場合)、空文字列 "" を返します。
2023-11-20 14:01:28 +05:30
return tts[0];
}
return "";
}
// 要修正:画像の読み込みエラーが発生した場合のエラーハンドリングが不十分です。エラーメッセージを表示するなどの処理を追加してください。
2024-04-20 12:34:49 +09:00
// getDisplayImage は、Destination オブジェクトを受け取り、特定の条件に基づいて表示する画像を返す機能を持っています。
// Flutterの Image ウィジェットを使用して、適切な画像を表示します。
//
// この関数は、提供された Destination オブジェクトに基づいて適切な画像を動的に選択し、
// その画像を表示するための Image ウィジェットを生成します。
// デフォルトの画像、完全なURL、またはサーバーURLと組み合わされた画像パスを使用して、条件に応じた画像の取得を試みます。
// また、エラー発生時にはデフォルト画像にフォールバックすることでユーザー体験を向上させます。
//
2023-11-07 17:17:47 +05:30
Image getDisplayImage(Destination destination) {
2024-04-20 12:34:49 +09:00
// Destination destination: これは Destination クラスのインスタンスで、
// CheckPointのデータを持っているオブジェクトです。
// このクラスには少なくとも phone と photos というプロパティが含まれている
//
// サーバーURLの取得:
// serverUrl 変数には ConstValues.currentServer() メソッドから現在のサーバーのURLが取得されます。
// これは画像を取得する際の基本URLとして使用される可能性があります。
//
2023-11-07 17:17:47 +05:30
String serverUrl = ConstValues.currentServer();
2024-04-20 12:34:49 +09:00
// デフォルト画像の設定:
// img 変数にはデフォルトの画像が設定されます。
// これは、アセットから "assets/images/empty_image.png" をロードするための Image.asset コンストラクタを使用しています。
//
2023-11-07 17:17:47 +05:30
Image img = Image.asset("assets/images/empty_image.png");
2024-04-20 12:34:49 +09:00
// 電話番号のチェック:
// destination.phone が null の場合、関数は imgデフォルト画像を返します。
// これは、phone プロパティが画像URLの代用として何らかの形で使用されることを示唆していますが、
// それが null であればデフォルト画像を使用するという意味です。
//
2023-11-07 17:17:47 +05:30
if (destination.phone == null) {
return img;
}
2024-04-20 12:34:49 +09:00
// 画像URLの構築と画像の返却:
// destination.photos が http を含む場合、これはすでに完全なURLとして提供されていることを意味します。
// このURLを NetworkImage コンストラクタに渡し、Image ウィジェットを生成して返します。
// そうでない場合は、serverUrl と destination.photos を組み合わせたURLを生成して NetworkImage に渡し、画像を取得します。
//
2023-11-07 17:17:47 +05:30
if (destination.photos!.contains('http')) {
return Image(
image: NetworkImage(
destination.phone!,
),
errorBuilder:
(BuildContext context, Object exception, StackTrace? stackTrace) {
return Image.asset("assets/images/empty_image.png");
},
);
} else {
return Image(
image: NetworkImage(
'$serverUrl/media/compressed/${destination.photos}',
),
errorBuilder:
(BuildContext context, Object exception, StackTrace? stackTrace) {
return Image.asset("assets/images/empty_image.png");
},
);
}
}
2022-10-12 21:46:17 +05:30
2024-04-20 12:34:49 +09:00
// getFinishImage は、ImageProvider 型のオブジェクトを返す関数で、Flutterアプリケーションで使用される画像を提供します。
// この関数は、DestinationController というクラスのインスタンスに依存しており、特定の状態に基づいて適切な画像を返します。
//
// この関数は、アプリケーションの現在の状態に依存して動的に画像を提供します。
// DestinationController の photos リストに基づいて画像を選択し、リストが空の場合はデフォルトの画像を提供します。
// これにより、画像の動的な管理が可能になり、ユーザーインターフェースの柔軟性が向上します。
// また、ImageProvider クラスを使用することで、
// 画像の具体的な取得方法(ファイルからの読み込みやアセットからのロードなど)を抽象化し、
// Flutterの Image ウィジェットで直接使用できる形式で画像を返します。
//
2023-09-14 22:53:51 +05:30
ImageProvider getFinishImage() {
2024-04-20 12:34:49 +09:00
// DestinationControllerの取得:
// destinationController は Get.find<DestinationController>() を使用して取得されます。
// これは、GetXというFlutterの状態管理ライブラリの機能を使用して、
// 現在のアプリケーションコンテキストから DestinationController タイプのインスタンスを取得するものです。
// これにより、アプリケーションの他の部分で共有されている DestinationController の現在のインスタンスにアクセスします。
//
2023-09-14 22:53:51 +05:30
DestinationController destinationController =
Get.find<DestinationController>();
2024-04-20 12:34:49 +09:00
// 画像の決定:
// destinationController.photos リストが空でないかどうかをチェックします。
// このリストは、ファイルパスまたは画像リソースへの参照を含む可能性があります。
//
2023-09-15 16:50:59 +05:30
if (destinationController.photos.isNotEmpty) {
2024-04-20 12:34:49 +09:00
// リストが空でない場合、最初の要素 (destinationController.photos[0]) が使用されます。
// FileImage コンストラクタを使用して、このパスから ImageProvider を生成します。
// これは、ローカルファイルシステム上の画像ファイルを参照するためのものです。
//
2023-09-15 16:50:59 +05:30
return FileImage(destinationController.photos[0]);
2024-04-20 12:34:49 +09:00
2023-09-15 16:50:59 +05:30
} else {
2024-04-20 12:34:49 +09:00
// destinationController.photos が空の場合、
// AssetImage を使用してアプリケーションのアセットからデフォルトの画像('assets/images/empty_image.png')を
// ロードします。これはビルド時にアプリケーションに組み込まれる静的なリソースです。
//
2023-09-15 16:50:59 +05:30
return const AssetImage('assets/images/empty_image.png');
2023-09-14 22:53:51 +05:30
}
2023-09-15 16:50:59 +05:30
}
2023-09-14 00:08:53 +05:30
2024-04-20 12:34:49 +09:00
// getReceiptImage は、ImageProvider 型を返す関数です。
// この関数は DestinationController オブジェクトに依存しており、条件に応じて特定の画像を返します。
// この関数は getFinishImage 関数と非常に似ており、ほぼ同じロジックを使用していますが、返されるデフォルトの画像が異なります。
//
2023-11-24 11:58:17 +05:30
ImageProvider getReceiptImage() {
DestinationController destinationController =
Get.find<DestinationController>();
if (destinationController.photos.isNotEmpty) {
return FileImage(destinationController.photos[0]);
} else {
return const AssetImage('assets/images/money.png');
}
}
2024-04-20 12:34:49 +09:00
// CameraPageクラスは、目的地に応じて適切なカメラ機能とアクションボタンを提供します。
// 手動チェックイン、ゴール撮影、購入ポイント撮影など、様々なシナリオに対応しています。
// また、ロゲイニングが開始されていない場合は、StartRogainingウィジェットを表示して、ユーザーにロゲイニングの開始を促します。
// CameraPageクラスは、IndexControllerとDestinationControllerを使用して、
// 現在の状態や目的地の情報を取得し、適切なUIを構築します。
// また、写真の撮影や購入ポイントの処理など、様々な機能を提供しています。
//
2022-10-12 21:46:17 +05:30
class CameraPage extends StatelessWidget {
2024-04-20 12:34:49 +09:00
bool? manulaCheckin = false; // 手動チェックインを示すブール値デフォルトはfalse
bool? buyPointPhoto = false; // 購入ポイントの写真を示すブール値デフォルトはfalse
Destination destination; // 目的地オブジェクト
Destination? dbDest; // データベースから取得した目的地オブジェクト(オプショナル)
String? initImage; // 初期画像のパス(オプショナル)
bool? buyQrCode = false;
2023-09-15 16:50:59 +05:30
CameraPage(
{Key? key,
required this.destination,
this.dbDest,
this.manulaCheckin,
2023-11-07 17:17:47 +05:30
this.buyPointPhoto,
this.initImage})
2023-09-14 22:53:51 +05:30
: super(key: key);
2023-09-14 00:08:53 +05:30
DestinationController destinationController =
Get.find<DestinationController>();
2022-10-19 08:53:17 +05:30
IndexController indexController = Get.find<IndexController>();
2022-10-12 21:46:17 +05:30
2023-07-16 00:17:42 +05:30
var settingGoal = false.obs;
2023-01-26 23:30:48 +05:30
Timer? timer;
2024-04-20 12:34:49 +09:00
// 現在の状態に基づいて、適切なアクションボタンを返します。
// 要修正:エラーハンドリングが不十分です。例外が発生した場合の処理を追加することをお勧めします。
//
2023-07-16 00:17:42 +05:30
Widget getAction(BuildContext context) {
2023-09-14 22:53:51 +05:30
if (manulaCheckin == true) {
2024-05-25 11:05:02 +09:00
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Wrap(
spacing: 16.0,
runSpacing: 8.0,
children: [
Obx(() => ElevatedButton(
2023-09-14 22:53:51 +05:30
onPressed: () {
destinationController.openCamera(context, destination);
},
2024-05-25 11:05:02 +09:00
style: ElevatedButton.styleFrom(
shape: const CircleBorder(),
padding: const EdgeInsets.all(20),
backgroundColor: destinationController.photos.isEmpty
? Colors.red
: Colors.grey[300],
),
child: destinationController.photos.isEmpty
? const Text("撮影", style: TextStyle(color: Colors.white))
: const Text("再撮影", style: TextStyle(color: Colors.black)),
)),
Obx(() => destinationController.photos.isNotEmpty
? ElevatedButton(
style: ElevatedButton.styleFrom(backgroundColor: Colors.red),
onPressed: () async {
await destinationController.makeCheckin(destination, true,
destinationController.photos[0].path);
destinationController.rogainingCounted.value = true;
destinationController.skipGps = false;
destinationController.isPhotoShoot.value = false;
2024-05-25 11:05:02 +09:00
Get.snackbar("チェックインしました。",
"${destination.sub_loc_id} : ${destination.name}",
backgroundColor: Colors.green,
colorText: Colors.white,
duration: const Duration(seconds: 2),
);
await Future.delayed(const Duration(seconds: 2));
2024-05-25 11:05:02 +09:00
Navigator.of(context).pop(true);
},
child: const Text("チェックイン", style: TextStyle(color: Colors.white)),
)
: Container())
],
),
2023-09-14 22:53:51 +05:30
);
}
2023-09-12 12:57:45 +05:30
2023-10-06 16:25:21 +05:30
if (destinationController.isAtGoal.value &&
2024-03-08 15:31:49 +05:30
destinationController.isInRog.value &&
destination.cp == -1) {
2024-04-20 12:34:49 +09:00
// isAtGoalがtrueで、isInRogがtrue、destination.cpが-1の場合は、ゴール用の撮影ボタンとゴール完了ボタンを表示します。
2024-03-08 15:31:49 +05:30
//goal
2022-11-04 14:11:18 +05:30
return Row(
2023-09-14 00:08:53 +05:30
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ElevatedButton(
onPressed: () {
if (settingGoal.value == false) {
2023-09-14 22:53:51 +05:30
destinationController.openCamera(context, destination);
2023-09-14 00:08:53 +05:30
}
},
child: Text("take_photo of the clock".tr)),
Obx(() => destinationController.photos.isNotEmpty
? settingGoal.value == false
? ElevatedButton(
style:
ElevatedButton.styleFrom(backgroundColor: Colors.red),
onPressed: () async {
2023-10-06 16:25:21 +05:30
// print(
// "----- user isss ${indexController.currentUser[0]} -----");
2023-09-14 00:08:53 +05:30
settingGoal.value = true;
try {
int userId =
indexController.currentUser[0]["user"]["id"];
//print("--- Pressed -----");
2023-10-06 16:25:21 +05:30
String team = indexController.currentUser[0]["user"]
2023-09-14 00:08:53 +05:30
['team_name'];
//print("--- _team : ${_team}-----");
2023-10-06 16:25:21 +05:30
String eventCode = indexController.currentUser[0]
2023-09-14 00:08:53 +05:30
["user"]["event_code"];
//print("--- _event_code : ${_event_code}-----");
2023-10-06 16:25:21 +05:30
String token =
2023-09-14 00:08:53 +05:30
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(
userId,
2023-10-06 16:25:21 +05:30
token,
team,
2023-09-14 00:08:53 +05:30
destinationController.photos[0].path,
formattedDate,
2023-10-06 16:25:21 +05:30
eventCode)
2023-09-14 00:08:53 +05:30
.then((value) {
2023-10-06 16:25:21 +05:30
// print(
// "---called ext api ${value['status']} ------");
2023-09-14 00:08:53 +05:30
if (value['status'] == 'OK') {
Get.back();
2023-10-06 16:25:21 +05:30
destinationController.skipGps = false;
Get.snackbar("目標が保存されました", "目標が正常に追加されました",
backgroundColor: Colors.green,
colorText: Colors.white
);
2024-03-08 19:14:03 +05:30
destinationController.resetRogaining(
isgoal: true);
2023-09-14 00:08:53 +05:30
} else {
2024-03-02 11:11:46 +05:30
//print("---- status ${value['status']} ---- ");
Get.snackbar("目標が追加されていません", "please_try_again",
backgroundColor: Colors.green,
colorText: Colors.white
);
2023-09-14 00:08:53 +05:30
}
});
} on Exception catch (_) {
settingGoal.value = false;
} finally {
settingGoal.value = false;
}
},
child: Text("finish_goal".tr))
2023-10-06 16:25:21 +05:30
: const Center(
child: CircularProgressIndicator(),
2023-09-14 00:08:53 +05:30
)
: Container())
],
);
2024-04-20 12:34:49 +09:00
2023-10-06 16:25:21 +05:30
} else if (destinationController.isInRog.value &&
2023-09-14 00:08:53 +05:30
dbDest?.checkedin != null &&
2024-03-08 15:31:49 +05:30
destination.cp != -1 &&
2023-09-14 00:08:53 +05:30
dbDest?.checkedin == true) {
2024-04-20 12:34:49 +09:00
// isInRogがtrueで、dbDest?.checkedinがtrue、destination.cpが-1以外の場合は、購入ポイントの撮影ボタンと完了ボタンを表示します。
2023-09-14 22:53:51 +05:30
//make buypoint image
2023-09-14 00:08:53 +05:30
return Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Obx(() => ElevatedButton(
onPressed: () {
2023-09-14 22:53:51 +05:30
destinationController.openCamera(context, destination);
2023-09-14 00:08:53 +05:30
},
child: destinationController.photos.isNotEmpty
? const Text("再撮影")
: const Text("撮影"))),
Obx(() => destinationController.photos.isNotEmpty
? ElevatedButton(
style: ElevatedButton.styleFrom(backgroundColor: Colors.red),
onPressed: () async {
2023-10-06 16:25:21 +05:30
// print(
// "##### current destination ${indexController.currentDestinationFeature[0].sub_loc_id} #######");
2023-09-14 00:08:53 +05:30
await destinationController.makeBuyPoint(
2023-10-06 16:25:21 +05:30
destination, destinationController.photos[0].path);
2023-09-14 00:08:53 +05:30
Get.back();
2023-10-06 16:25:21 +05:30
destinationController.rogainingCounted.value = true;
destinationController.skipGps = false;
destinationController.isPhotoShoot.value = false;
2023-09-15 16:50:59 +05:30
Get.snackbar("お買い物加点を行いました。",
"${destination.sub_loc_id} : ${destination.name}",
backgroundColor: Colors.green,
colorText: Colors.white
);
Navigator.of(context).pop(true); // ここを修正
2023-09-14 00:08:53 +05:30
},
2024-04-20 12:34:49 +09:00
child: const Text("レシートの写真を撮ってください"))
: Container())
],
);
} else if (destinationController.isInRog.value &&
dbDest?.checkedin != null &&
destination.cp != -1 &&
destination.use_qr_code == true &&
dbDest?.checkedin == true) {
// isInRogがtrueで、dbDest?.checkedinがtrue、destination.cpが-1以外、qrCode == true の場合は、
// QRCode 撮影ボタンを表示
return Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Obx(() => ElevatedButton(
onPressed: () {
destinationController.openCamera(context, destination);
},
child: destinationController.photos.isNotEmpty
? const Text("再QR読込")
: const Text("QR読込"))),
Obx(() => destinationController.photos.isNotEmpty
? ElevatedButton(
style: ElevatedButton.styleFrom(backgroundColor: Colors.red),
onPressed: () async {
// print(
// "##### current destination ${indexController.currentDestinationFeature[0].sub_loc_id} #######");
await destinationController.makeBuyPoint(
destination, destinationController.photos[0].path);
Get.back();
destinationController.rogainingCounted.value = true;
destinationController.skipGps = false;
destinationController.isPhotoShoot.value = false;
Get.snackbar("お買い物加点を行いました。",
"${destination.sub_loc_id} : ${destination.name}",
backgroundColor: Colors.green,
colorText: Colors.white
);
2024-04-20 12:34:49 +09:00
},
child: const Text("QRコードを読み取ってください"))
2023-09-14 00:08:53 +05:30
: Container())
],
);
} else {
2024-04-20 12:34:49 +09:00
// それ以外の場合は、撮影ボタンとチェックインボタンを表示します。
2023-09-14 00:08:53 +05:30
return Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Obx(() => ElevatedButton(
onPressed: () {
2023-09-14 22:53:51 +05:30
destinationController.openCamera(context, destination);
2023-09-14 00:08:53 +05:30
},
child: destinationController.photos.isNotEmpty
? const Text("再撮影")
: const Text("撮影"))),
Obx(() => destinationController.photos.isNotEmpty
? ElevatedButton(
style: ElevatedButton.styleFrom(backgroundColor: Colors.red),
onPressed: () async {
2023-10-06 16:25:21 +05:30
// print(
// "##### current destination ${indexController.currentDestinationFeature[0].sub_loc_id} #######");
2023-09-14 00:08:53 +05:30
await destinationController.makeCheckin(
indexController.currentDestinationFeature[0],
true,
destinationController.photos[0].path);
//Get.back();
2023-10-06 16:25:21 +05:30
destinationController.rogainingCounted.value = true;
destinationController.skipGps = false;
destinationController.isPhotoShoot.value = false;
2023-11-07 17:17:47 +05:30
Get.snackbar(
"チェックインしました",
indexController.currentDestinationFeature[0].name ??
"",
backgroundColor: Colors.green,
colorText: Colors.white,
duration: const Duration(seconds: 2), // 表示時間を1秒に設定
);
// SnackBarの表示が終了するのを待ってからCameraPageを閉じる
await Future.delayed(const Duration(seconds: 2));
Navigator.of(context).pop(true); // ここを修正
2023-09-14 00:08:53 +05:30
},
child: const Text("チェックイン"))
: Container())
],
);
2022-10-30 21:43:29 +05:30
}
}
// void finishRog(){
// destinationController.addToRogaining(destinationController.current_lat, destinationController.current_lon, destination_id)
// }
@override
Widget build(BuildContext context) {
2023-11-27 14:57:25 +05:30
//print("---- photos ${destination.photos} ----");
2023-09-15 16:50:59 +05:30
if (buyPointPhoto == true) {
2024-04-20 12:34:49 +09:00
// buyPointPhotoがtrueの場合は、BuyPointCameraウィジェットを返します。
2023-10-06 16:25:21 +05:30
//print("--- buy point camera ${destination.toString()}");
2023-09-15 16:50:59 +05:30
return BuyPointCamera(destination: destination);
2024-04-24 11:30:38 +09:00
//}else if(destination.use_qr_code){
// return QRCodeScannerPage(destination: destination);
2023-10-06 16:25:21 +05:30
} else if (destinationController.isInRog.value) {
2024-04-20 12:34:49 +09:00
// isInRogがtrueの場合は、カメラページのUIを構築します。
// AppBarには、目的地の情報を表示します。
// ボディには、目的地の画像、タグ、アクションボタンを表示します。
2023-11-20 14:01:28 +05:30
//print("-----tags camera page----- ${destination.tags}");
2023-10-06 16:25:21 +05:30
//print("--- in normal camera ${destination.toString()}");
2022-10-30 21:43:29 +05:30
return Scaffold(
2023-10-06 16:25:21 +05:30
appBar: destinationController.isInRog.value &&
destinationController.rogainingCounted.value == true
2023-09-14 00:08:53 +05:30
? AppBar(
2023-09-15 16:50:59 +05:30
automaticallyImplyLeading: false,
2023-09-15 12:05:05 +05:30
title: destination.cp == -1
2023-09-14 00:08:53 +05:30
? Text("finishing_rogaining".tr)
2023-09-15 12:05:05 +05:30
: Text("${destination.sub_loc_id} : ${destination.name}"),
2023-09-14 00:08:53 +05:30
leading: IconButton(
icon: Text("cancel".tr),
onPressed: () {
Navigator.of(context).pop();
destinationController.skip_10s = true;
timer =
Timer.periodic(const Duration(seconds: 10), (Timer t) {
destinationController.skip_10s = false;
});
},
2022-10-30 21:43:29 +05:30
),
2023-09-14 00:08:53 +05:30
centerTitle: true,
)
: AppBar(
2023-09-15 16:50:59 +05:30
automaticallyImplyLeading: false,
2023-09-15 12:05:05 +05:30
title: Text("${destination.sub_loc_id} : ${destination.name}"),
2022-10-30 21:43:29 +05:30
),
2023-09-15 16:50:59 +05:30
body: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Center(
child: Obx(
() => Container(
width: MediaQuery.of(context).size.width,
height: 370,
decoration: BoxDecoration(
image: DecorationImage(
2023-11-07 17:17:47 +05:30
image: destinationController.photos.isEmpty
? getDisplayImage(destination).image
: getFinishImage(),
fit: BoxFit.cover)),
2023-09-15 16:50:59 +05:30
),
2023-09-14 00:08:53 +05:30
),
),
2022-10-30 21:43:29 +05:30
),
2023-09-15 16:50:59 +05:30
Padding(
2023-11-20 14:01:28 +05:30
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Text(getTagText(
false,
destination.tags,
))
// child: Obx(() => destinationController.photos.isEmpty == true
// ? const Text("撮影してチェックインしてください。")
// : const Text("チェックインをタップしてください。")),
),
2023-09-15 16:50:59 +05:30
getAction(context),
],
),
2023-09-14 00:08:53 +05:30
),
);
} else {
2024-04-20 12:34:49 +09:00
// isInRogがfalseの場合は、StartRogainingウィジェットを返します。
2022-10-30 21:43:29 +05:30
return StartRogaining();
}
}
}
2024-04-20 12:34:49 +09:00
// ロゲイニングが開始されていない場合に表示されるウィジェットです。
// "You have not started rogaining yet."というメッセージと、戻るボタンを表示します。
//
2022-10-30 21:43:29 +05:30
class StartRogaining extends StatelessWidget {
StartRogaining({Key? key}) : super(key: key);
2023-09-14 00:08:53 +05:30
DestinationController destinationController =
Get.find<DestinationController>();
2022-10-30 21:43:29 +05:30
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
2023-09-15 16:50:59 +05:30
automaticallyImplyLeading: false,
2023-09-14 00:08:53 +05:30
title: Text(
"Not started yet".tr,
),
2022-10-30 21:43:29 +05:30
),
2023-10-06 16:25:21 +05:30
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("You have not started rogaining yet.".tr,
style: const TextStyle(fontSize: 24)),
const SizedBox(
height: 40.0,
),
ElevatedButton(
onPressed: () {
Get.back();
destinationController.skipGps = false;
},
child: const Text("Back"),
),
],
2022-10-30 21:43:29 +05:30
),
),
);
}
}
2024-04-20 12:34:49 +09:00
// 購入ポイントの写真撮影用のウィジェットです。
// 目的地の画像、タグ、撮影ボタン、完了ボタン、購入なしボタンを表示します。
// 撮影ボタンをタップすると、カメラが起動します。
// 完了ボタンをタップすると、購入ポイントの処理が行われます。
// 購入なしボタンをタップすると、購入ポイントがキャンセルされます。
//
2024-08-01 20:08:12 +09:00
class BuyPointCamera extends StatefulWidget {
final Destination destination;
2023-09-14 22:53:51 +05:30
2024-08-01 20:08:12 +09:00
const BuyPointCamera({Key? key, required this.destination}) : super(key: key);
2024-05-25 11:05:02 +09:00
@override
2024-08-01 20:08:12 +09:00
_BuyPointCameraState createState() => _BuyPointCameraState();
2024-05-25 11:05:02 +09:00
}
2024-08-01 20:08:12 +09:00
class _BuyPointCameraState extends State<BuyPointCamera> {
final GlobalKey qrKey = GlobalKey(debugLabel: 'QR');
QRViewController? controller;
bool isQRScanned = false;
2024-05-25 11:05:02 +09:00
2024-08-01 20:08:12 +09:00
final DestinationController destinationController = Get.find<DestinationController>();
2022-10-30 21:43:29 +05:30
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
2023-09-15 16:50:59 +05:30
automaticallyImplyLeading: false,
2024-08-01 20:08:12 +09:00
title: Text("${widget.destination.sub_loc_id} : ${widget.destination.name}"),
2022-10-30 21:43:29 +05:30
),
2023-09-14 22:53:51 +05:30
body: Column(
2023-09-15 16:50:59 +05:30
children: [
2024-08-01 20:08:12 +09:00
Expanded(
flex: 4,
child: QRView(
key: qrKey,
onQRViewCreated: _onQRViewCreated,
2023-09-14 22:53:51 +05:30
),
2023-09-15 16:50:59 +05:30
),
2024-08-01 20:08:12 +09:00
Expanded(
flex: 1,
child: Center(
child: Text('QRコードをスキャンしてください'),
),
2023-09-15 16:50:59 +05:30
),
2023-09-14 22:53:51 +05:30
],
2022-10-12 21:46:17 +05:30
),
);
}
2024-08-01 20:08:12 +09:00
void _onQRViewCreated(QRViewController controller) {
this.controller = controller;
controller.scannedDataStream.listen((scanData) {
if (!isQRScanned && scanData.code != null && scanData.code!.startsWith('https://rogaining.sumasen.net/api/activate_buy_point/')) {
isQRScanned = true;
_activateBuyPoint(scanData.code!);
}
});
}
void _activateBuyPoint(String qrCode) async {
final IndexController indexController = Get.find<IndexController>();
final userId = indexController.currentUser[0]["user"]["id"];
final token = indexController.currentUser[0]["token"];
final teamName = indexController.currentUser[0]["user"]['team_name'];
final eventCode = indexController.currentUser[0]["user"]["event_code"];
//final cpNumber = destinationController.currentDestinationFeature[0].cp;
final cpNumber = widget.destination.cp;
try {
final response = await http.post(
Uri.parse('https://rogaining.sumasen.net/api/activate_buy_point/'),
headers: {
'Content-Type': 'application/json',
'Authorization': 'Token $token',
},
body: jsonEncode({
'user_id': userId,
'team_name': teamName,
'event_code': eventCode,
'cp_number': cpNumber,
'qr_code': qrCode,
}),
);
if (response.statusCode == 200) {
Get.snackbar('成功', 'お買い物ポイントが有効化されました');
Navigator.of(context).pop();
} else {
Get.snackbar('エラー', 'お買い物ポイントの有効化に失敗しました');
}
} catch (e) {
Get.snackbar('エラー', 'ネットワークエラーが発生しました');
} finally {
isQRScanned = false;
}
}
@override
void dispose() {
controller?.dispose();
super.dispose();
}
2023-09-14 00:08:53 +05:30
}
2024-08-01 20:08:12 +09:00
2024-04-20 12:34:49 +09:00
class QRCodeScannerPage extends StatefulWidget {
QRCodeScannerPage({Key? key, required this.destination}) : super(key: key);
Destination destination;
2024-04-20 12:34:49 +09:00
@override
_QRCodeScannerPageState createState() => _QRCodeScannerPageState();
}
class _QRCodeScannerPageState extends State<QRCodeScannerPage> {
final GlobalKey qrKey = GlobalKey(debugLabel: 'QR');
QRViewController? controller;
@override
void dispose() {
controller?.dispose();
super.dispose();
}
void _onQRViewCreated(QRViewController controller) {
this.controller = controller;
controller.scannedDataStream.listen((scanData) {
// QRコードのデータを処理する
debugPrint("scan data = ${scanData}");
String? qrCodeData = scanData.code;
// qrCodeDataを使用してチェックポイントの処理を行う
// 例えば、qrCodeDataからCPのIDと店名を取得し、加点処理を行う
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: QRView(
key: qrKey,
onQRViewCreated: _onQRViewCreated,
),
);
}
}