#2832 まで解決
This commit is contained in:
@ -8,39 +8,103 @@ import 'package:rogapp/pages/destination/destination_controller.dart';
|
||||
import 'package:rogapp/pages/index/index_controller.dart';
|
||||
import 'package:rogapp/services/external_service.dart';
|
||||
import 'package:rogapp/utils/const.dart';
|
||||
import 'package:qr_code_scanner/qr_code_scanner.dart';
|
||||
|
||||
// 関数 getTagText は、特定の条件に基づいて文字列から特定の部分を抽出し、返却するためのものです。
|
||||
// 関数は2つのパラメータを受け取り、条件分岐を通じて結果を返します。
|
||||
//
|
||||
// この関数は、タグのリスト(空白を含む文字列)を適切に解析し、条件に応じて特定のタグを抽出するために設計されています。
|
||||
// 異なる種類の空白文字(半角、全角)で異なる分割を行い、与えられた条件(isRecept)に応じて適切なタグを選択して返却します。
|
||||
//
|
||||
String getTagText(bool isRecept, String? tags) {
|
||||
// bool isRecept: 真偽値を受け取り、この値によって処理の分岐が行われます。
|
||||
// String? tags: オプショナルな文字列(null が許容される)。空白文字を含む可能性のあるタグのリストを表します。
|
||||
|
||||
// 空のチェック:
|
||||
// tags が null または空文字列 ("") の場合、何も含まれていないことを意味し、関数はただちに空文字列を返します。
|
||||
//
|
||||
if (tags == null || tags.isEmpty) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// タグの分割:
|
||||
// tags が空ではない場合、文字列を空白文字で分割します。
|
||||
// ここで2種類の空白文字(半角 " " と全角 " ")に対応するため、2回分割を行っています。
|
||||
// tts: 半角スペース " " で分割した結果のリスト。
|
||||
// ttt: 全角スペース " " で分割した結果のリスト。
|
||||
//
|
||||
List<String> tts = tags.split(" ");
|
||||
List<String> ttt = tags.split(" ");
|
||||
|
||||
// 条件分岐:
|
||||
// isRecept の値によって、処理が分岐します。
|
||||
//
|
||||
if (isRecept) {
|
||||
// isRecept が true の場合:
|
||||
// 全角スペースで分割した結果 (ttt) の長さが半角スペースで分割した結果 (tts) の長さより大きく、
|
||||
// かつ ttt が1つ以上の要素を持つ場合、ttt[1] (全角スペースで分割後の2番目の要素)を返します。
|
||||
if (ttt.length > tts.length && ttt.length > 1) {
|
||||
return ttt[1];
|
||||
}
|
||||
}
|
||||
if (!isRecept) {
|
||||
// isRecept が false の場合:
|
||||
// 全角スペースで分割したリストが半角スペースで分割したリストよりも長い場合、ttt[0] (全角スペースで分割後の最初の要素)を返します。
|
||||
// 上記の条件に当てはまらない場合、半角スペースで分割したリストの最初の要素 tts[0] を返します。
|
||||
//
|
||||
if (ttt.length > tts.length && ttt.length > 1) {
|
||||
return ttt[0];
|
||||
}
|
||||
}
|
||||
if (!isRecept) {
|
||||
// 最終的な返却:
|
||||
// 上記の条件に何も該当しない場合(主に isRecept が true であり、全角スペースの条件に該当しない場合)、空文字列 "" を返します。
|
||||
return tts[0];
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
// 要修正:画像の読み込みエラーが発生した場合のエラーハンドリングが不十分です。エラーメッセージを表示するなどの処理を追加してください。
|
||||
// getDisplayImage は、Destination オブジェクトを受け取り、特定の条件に基づいて表示する画像を返す機能を持っています。
|
||||
// Flutterの Image ウィジェットを使用して、適切な画像を表示します。
|
||||
//
|
||||
// この関数は、提供された Destination オブジェクトに基づいて適切な画像を動的に選択し、
|
||||
// その画像を表示するための Image ウィジェットを生成します。
|
||||
// デフォルトの画像、完全なURL、またはサーバーURLと組み合わされた画像パスを使用して、条件に応じた画像の取得を試みます。
|
||||
// また、エラー発生時にはデフォルト画像にフォールバックすることでユーザー体験を向上させます。
|
||||
//
|
||||
Image getDisplayImage(Destination destination) {
|
||||
// Destination destination: これは Destination クラスのインスタンスで、
|
||||
// CheckPointのデータを持っているオブジェクトです。
|
||||
// このクラスには少なくとも phone と photos というプロパティが含まれている
|
||||
//
|
||||
|
||||
// サーバーURLの取得:
|
||||
// serverUrl 変数には ConstValues.currentServer() メソッドから現在のサーバーのURLが取得されます。
|
||||
// これは画像を取得する際の基本URLとして使用される可能性があります。
|
||||
//
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
|
||||
// デフォルト画像の設定:
|
||||
// img 変数にはデフォルトの画像が設定されます。
|
||||
// これは、アセットから "assets/images/empty_image.png" をロードするための Image.asset コンストラクタを使用しています。
|
||||
//
|
||||
Image img = Image.asset("assets/images/empty_image.png");
|
||||
|
||||
// 電話番号のチェック:
|
||||
// destination.phone が null の場合、関数は img(デフォルト画像)を返します。
|
||||
// これは、phone プロパティが画像URLの代用として何らかの形で使用されることを示唆していますが、
|
||||
// それが null であればデフォルト画像を使用するという意味です。
|
||||
//
|
||||
if (destination.phone == null) {
|
||||
return img;
|
||||
}
|
||||
|
||||
// 画像URLの構築と画像の返却:
|
||||
// destination.photos が http を含む場合、これはすでに完全なURLとして提供されていることを意味します。
|
||||
// このURLを NetworkImage コンストラクタに渡し、Image ウィジェットを生成して返します。
|
||||
// そうでない場合は、serverUrl と destination.photos を組み合わせたURLを生成して NetworkImage に渡し、画像を取得します。
|
||||
//
|
||||
if (destination.photos!.contains('http')) {
|
||||
return Image(
|
||||
image: NetworkImage(
|
||||
@ -64,16 +128,51 @@ Image getDisplayImage(Destination destination) {
|
||||
}
|
||||
}
|
||||
|
||||
// getFinishImage は、ImageProvider 型のオブジェクトを返す関数で、Flutterアプリケーションで使用される画像を提供します。
|
||||
// この関数は、DestinationController というクラスのインスタンスに依存しており、特定の状態に基づいて適切な画像を返します。
|
||||
//
|
||||
// この関数は、アプリケーションの現在の状態に依存して動的に画像を提供します。
|
||||
// DestinationController の photos リストに基づいて画像を選択し、リストが空の場合はデフォルトの画像を提供します。
|
||||
// これにより、画像の動的な管理が可能になり、ユーザーインターフェースの柔軟性が向上します。
|
||||
// また、ImageProvider クラスを使用することで、
|
||||
// 画像の具体的な取得方法(ファイルからの読み込みやアセットからのロードなど)を抽象化し、
|
||||
// Flutterの Image ウィジェットで直接使用できる形式で画像を返します。
|
||||
//
|
||||
ImageProvider getFinishImage() {
|
||||
|
||||
// DestinationControllerの取得:
|
||||
// destinationController は Get.find<DestinationController>() を使用して取得されます。
|
||||
// これは、GetXというFlutterの状態管理ライブラリの機能を使用して、
|
||||
// 現在のアプリケーションコンテキストから DestinationController タイプのインスタンスを取得するものです。
|
||||
// これにより、アプリケーションの他の部分で共有されている DestinationController の現在のインスタンスにアクセスします。
|
||||
//
|
||||
DestinationController destinationController =
|
||||
Get.find<DestinationController>();
|
||||
|
||||
// 画像の決定:
|
||||
// destinationController.photos リストが空でないかどうかをチェックします。
|
||||
// このリストは、ファイルパスまたは画像リソースへの参照を含む可能性があります。
|
||||
//
|
||||
if (destinationController.photos.isNotEmpty) {
|
||||
// リストが空でない場合、最初の要素 (destinationController.photos[0]) が使用されます。
|
||||
// FileImage コンストラクタを使用して、このパスから ImageProvider を生成します。
|
||||
// これは、ローカルファイルシステム上の画像ファイルを参照するためのものです。
|
||||
//
|
||||
return FileImage(destinationController.photos[0]);
|
||||
|
||||
} else {
|
||||
// destinationController.photos が空の場合、
|
||||
// AssetImage を使用してアプリケーションのアセットからデフォルトの画像('assets/images/empty_image.png')を
|
||||
// ロードします。これはビルド時にアプリケーションに組み込まれる静的なリソースです。
|
||||
//
|
||||
return const AssetImage('assets/images/empty_image.png');
|
||||
}
|
||||
}
|
||||
|
||||
// getReceiptImage は、ImageProvider 型を返す関数です。
|
||||
// この関数は DestinationController オブジェクトに依存しており、条件に応じて特定の画像を返します。
|
||||
// この関数は getFinishImage 関数と非常に似ており、ほぼ同じロジックを使用していますが、返されるデフォルトの画像が異なります。
|
||||
//
|
||||
ImageProvider getReceiptImage() {
|
||||
DestinationController destinationController =
|
||||
Get.find<DestinationController>();
|
||||
@ -84,12 +183,21 @@ ImageProvider getReceiptImage() {
|
||||
}
|
||||
}
|
||||
|
||||
// CameraPageクラスは、目的地に応じて適切なカメラ機能とアクションボタンを提供します。
|
||||
// 手動チェックイン、ゴール撮影、購入ポイント撮影など、様々なシナリオに対応しています。
|
||||
// また、ロゲイニングが開始されていない場合は、StartRogainingウィジェットを表示して、ユーザーにロゲイニングの開始を促します。
|
||||
// CameraPageクラスは、IndexControllerとDestinationControllerを使用して、
|
||||
// 現在の状態や目的地の情報を取得し、適切なUIを構築します。
|
||||
// また、写真の撮影や購入ポイントの処理など、様々な機能を提供しています。
|
||||
//
|
||||
class CameraPage extends StatelessWidget {
|
||||
bool? manulaCheckin = false;
|
||||
bool? buyPointPhoto = false;
|
||||
Destination destination;
|
||||
Destination? dbDest;
|
||||
String? initImage;
|
||||
bool? manulaCheckin = false; // 手動チェックインを示すブール値(デフォルトはfalse)
|
||||
bool? buyPointPhoto = false; // 購入ポイントの写真を示すブール値(デフォルトはfalse)
|
||||
Destination destination; // 目的地オブジェクト
|
||||
Destination? dbDest; // データベースから取得した目的地オブジェクト(オプショナル)
|
||||
String? initImage; // 初期画像のパス(オプショナル)
|
||||
bool? buyQrCode = false;
|
||||
|
||||
CameraPage(
|
||||
{Key? key,
|
||||
required this.destination,
|
||||
@ -106,11 +214,15 @@ class CameraPage extends StatelessWidget {
|
||||
|
||||
Timer? timer;
|
||||
|
||||
// 現在の状態に基づいて、適切なアクションボタンを返します。
|
||||
// 要修正:エラーハンドリングが不十分です。例外が発生した場合の処理を追加することをお勧めします。
|
||||
//
|
||||
Widget getAction(BuildContext context) {
|
||||
|
||||
//print("----cccheckin is --- ${dbDest?.checkedin} ----");
|
||||
|
||||
if (manulaCheckin == true) {
|
||||
// manulaCheckinがtrueの場合は、撮影ボタンとチェックインボタンを表示します。
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
@ -142,6 +254,7 @@ class CameraPage extends StatelessWidget {
|
||||
if (destinationController.isAtGoal.value &&
|
||||
destinationController.isInRog.value &&
|
||||
destination.cp == -1) {
|
||||
// isAtGoalがtrueで、isInRogがtrue、destination.cpが-1の場合は、ゴール用の撮影ボタンとゴール完了ボタンを表示します。
|
||||
//goal
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
@ -215,10 +328,12 @@ class CameraPage extends StatelessWidget {
|
||||
: Container())
|
||||
],
|
||||
);
|
||||
|
||||
} else if (destinationController.isInRog.value &&
|
||||
dbDest?.checkedin != null &&
|
||||
destination.cp != -1 &&
|
||||
dbDest?.checkedin == true) {
|
||||
// isInRogがtrueで、dbDest?.checkedinがtrue、destination.cpが-1以外の場合は、購入ポイントの撮影ボタンと完了ボタンを表示します。
|
||||
//make buypoint image
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
@ -245,11 +360,49 @@ class CameraPage extends StatelessWidget {
|
||||
Get.snackbar("お買い物加点を行いました。",
|
||||
"${destination.sub_loc_id} : ${destination.name}");
|
||||
},
|
||||
child: const Text("レシートの写真を撮る"))
|
||||
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}");
|
||||
},
|
||||
child: const Text("QRコードを読み取ってください"))
|
||||
: Container())
|
||||
],
|
||||
);
|
||||
} else {
|
||||
// それ以外の場合は、撮影ボタンとチェックインボタンを表示します。
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
@ -294,9 +447,15 @@ class CameraPage extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
//print("---- photos ${destination.photos} ----");
|
||||
if (buyPointPhoto == true) {
|
||||
// buyPointPhotoがtrueの場合は、BuyPointCameraウィジェットを返します。
|
||||
//print("--- buy point camera ${destination.toString()}");
|
||||
return BuyPointCamera(destination: destination);
|
||||
}else if(destination.use_qr_code){
|
||||
return QRCodeScannerPage(destination: destination);
|
||||
} else if (destinationController.isInRog.value) {
|
||||
// isInRogがtrueの場合は、カメラページのUIを構築します。
|
||||
// AppBarには、目的地の情報を表示します。
|
||||
// ボディには、目的地の画像、タグ、アクションボタンを表示します。
|
||||
//print("-----tags camera page----- ${destination.tags}");
|
||||
//print("--- in normal camera ${destination.toString()}");
|
||||
return Scaffold(
|
||||
@ -361,11 +520,15 @@ class CameraPage extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
} else {
|
||||
// isInRogがfalseの場合は、StartRogainingウィジェットを返します。
|
||||
return StartRogaining();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ロゲイニングが開始されていない場合に表示されるウィジェットです。
|
||||
// "You have not started rogaining yet."というメッセージと、戻るボタンを表示します。
|
||||
//
|
||||
class StartRogaining extends StatelessWidget {
|
||||
StartRogaining({Key? key}) : super(key: key);
|
||||
|
||||
@ -404,6 +567,12 @@ class StartRogaining extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
// 購入ポイントの写真撮影用のウィジェットです。
|
||||
// 目的地の画像、タグ、撮影ボタン、完了ボタン、購入なしボタンを表示します。
|
||||
// 撮影ボタンをタップすると、カメラが起動します。
|
||||
// 完了ボタンをタップすると、購入ポイントの処理が行われます。
|
||||
// 購入なしボタンをタップすると、購入ポイントがキャンセルされます。
|
||||
//
|
||||
class BuyPointCamera extends StatelessWidget {
|
||||
BuyPointCamera({Key? key, required this.destination}) : super(key: key);
|
||||
|
||||
@ -521,3 +690,41 @@ class BuyPointCamera extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class QRCodeScannerPage extends StatefulWidget {
|
||||
@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,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user