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

518 lines
20 KiB
Dart
Raw Normal View History

2023-01-26 23:30:48 +05:30
import 'dart:async';
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';
2023-11-20 14:01:28 +05:30
String getTagText(bool isRecept, String? tags) {
if (tags == null || tags.isEmpty) {
return "";
}
List<String> tts = tags.split(" ");
List<String> ttt = tags.split(" ");
if (isRecept) {
if (ttt.length > tts.length && ttt.length > 1) {
return ttt[1];
}
}
if (!isRecept) {
if (ttt.length > tts.length && ttt.length > 1) {
return ttt[0];
}
}
if (!isRecept) {
return tts[0];
}
return "";
}
2023-11-07 17:17:47 +05:30
Image getDisplayImage(Destination destination) {
String serverUrl = ConstValues.currentServer();
Image img = Image.asset("assets/images/empty_image.png");
if (destination.phone == null) {
return img;
}
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
2023-09-14 22:53:51 +05:30
ImageProvider getFinishImage() {
DestinationController destinationController =
Get.find<DestinationController>();
2023-09-15 16:50:59 +05:30
if (destinationController.photos.isNotEmpty) {
return FileImage(destinationController.photos[0]);
} else {
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
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');
}
}
2022-10-12 21:46:17 +05:30
class CameraPage extends StatelessWidget {
2023-09-14 22:53:51 +05:30
bool? manulaCheckin = false;
bool? buyPointPhoto = false;
2023-09-15 01:06:21 +05:30
Destination destination;
2023-09-14 00:08:53 +05:30
Destination? dbDest;
2023-11-07 17:17:47 +05:30
String? initImage;
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;
2023-07-16 00:17:42 +05:30
Widget getAction(BuildContext context) {
2023-09-14 22:53:51 +05:30
//print("----cccheckin is --- ${dbDest?.checkedin} ----");
if (manulaCheckin == true) {
return Row(
2023-09-15 16:50:59 +05:30
mainAxisSize: MainAxisSize.min,
2023-09-14 22:53:51 +05:30
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
2023-09-15 16:50:59 +05:30
ElevatedButton(
2023-09-14 22:53:51 +05:30
onPressed: () {
destinationController.openCamera(context, destination);
},
2023-09-15 16:50:59 +05:30
child: const Text("撮影")),
2023-09-14 22:53:51 +05:30
Obx(() => destinationController.photos.isNotEmpty
? ElevatedButton(
style: ElevatedButton.styleFrom(backgroundColor: Colors.red),
onPressed: () async {
2023-09-15 16:50:59 +05:30
await destinationController.makeCheckin(destination, true,
2023-09-14 22:53:51 +05:30
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-09-15 16:50:59 +05:30
Get.snackbar("チェックインしました。",
"${destination.sub_loc_id} : ${destination.name}");
2023-09-14 22:53:51 +05:30
},
child: const Text("チェックイン"))
: Container())
],
);
}
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) {
//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;
2023-09-14 00:08:53 +05:30
Get.snackbar("目標が保存されました", "目標が正常に追加されました");
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']} ---- ");
2023-09-14 00:08:53 +05:30
Get.snackbar("目標が追加されていません", "please_try_again");
}
});
} 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())
],
);
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) {
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("お買い物加点を行いました。",
2023-10-06 16:25:21 +05:30
"${destination.sub_loc_id} : ${destination.name}");
2023-09-14 00:08:53 +05:30
},
child: const Text("レシートの写真を撮る"))
: Container())
],
);
} else {
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 ??
"");
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) {
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);
2023-10-06 16:25:21 +05:30
} else if (destinationController.isInRog.value) {
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 {
2022-10-30 21:43:29 +05:30
return StartRogaining();
}
}
}
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
),
),
);
}
}
2023-09-14 22:53:51 +05:30
class BuyPointCamera extends StatelessWidget {
BuyPointCamera({Key? key, required this.destination}) : super(key: key);
Destination destination;
2022-10-30 21:43:29 +05:30
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) {
2024-03-02 11:11:46 +05:30
//print("in camera purchase 1 ${destinationController.isInRog.value}");
2022-10-30 21:43:29 +05:30
return Scaffold(
appBar: AppBar(
2023-09-15 16:50:59 +05:30
automaticallyImplyLeading: false,
2023-09-14 00:08:53 +05:30
title: Text(
2023-09-15 01:06:21 +05:30
"${destination.sub_loc_id} : ${destination.name}",
2023-09-14 00:08:53 +05:30
),
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
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-24 11:58:17 +05:30
image: getReceiptImage(), fit: BoxFit.cover)),
2023-09-14 22:53:51 +05:30
),
2023-09-14 00:08:53 +05:30
),
2023-09-14 22:53:51 +05:30
),
2023-09-15 16:50:59 +05:30
),
2023-11-20 14:01:28 +05:30
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(getTagText(true, destination.tags)),
2023-09-15 16:50:59 +05:30
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
mainAxisSize: MainAxisSize.min,
children: [
Obx(() => Row(
2023-10-06 16:25:21 +05:30
mainAxisSize: MainAxisSize.min,
2023-09-15 16:50:59 +05:30
children: [
ElevatedButton(
onPressed: () {
2024-03-02 11:11:46 +05:30
// print(
// "in camera purchase 2 ${destinationController.isInRog.value}");
2023-09-15 16:50:59 +05:30
destinationController.openCamera(
context, destination);
},
child: destinationController.photos.isNotEmpty
? const Text("再撮影")
: const Text("撮影")),
2023-10-06 16:25:21 +05:30
const SizedBox(
width: 10,
),
2023-09-15 16:50:59 +05:30
ElevatedButton(
2023-09-15 17:19:26 +05:30
onPressed: () async {
2023-10-06 16:25:21 +05:30
await destinationController
.cancelBuyPoint(destination);
2024-01-18 22:24:51 +05:30
Navigator.of(Get.context!).pop();
//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
},
child: const Text("買い物なし"))
],
)),
Obx(() => destinationController.photos.isNotEmpty
? Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
// ElevatedButton(
// style: ElevatedButton.styleFrom(
// backgroundColor: Colors.red),
// onPressed: () async {},
// child: const Text("買物なし")),
// const SizedBox(
// width: 10,
// ),
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red),
onPressed: () async {
2024-03-02 11:11:46 +05:30
// print(
// "in camera purchase 3 ${destinationController.isInRog.value}");
2023-09-15 16:50:59 +05:30
await destinationController.makeBuyPoint(
destination,
destinationController.photos[0].path);
Get.back();
2024-03-02 11:11:46 +05:30
// print(
// "in camera purchase 4 ${destinationController.isInRog.value}");
2023-10-06 16:25:21 +05:30
destinationController.rogainingCounted.value =
2023-09-15 16:50:59 +05:30
true;
2023-10-06 16:25:21 +05:30
destinationController.skipGps = false;
destinationController.isPhotoShoot.value = false;
2023-09-15 16:50:59 +05:30
Get.snackbar("お買い物加点を行いました",
"${destination.sub_loc_id} : ${destination.name}");
},
child: const Text("完了"))
],
)
: Container())
],
),
2023-09-14 22:53:51 +05:30
],
2022-10-12 21:46:17 +05:30
),
);
}
2023-09-14 00:08:53 +05:30
}