Snackbar の色を変更。ロゲ開始時のエラーを回避。
This commit is contained in:
@ -33,6 +33,7 @@ import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'package:image_gallery_saver/image_gallery_saver.dart';
|
||||
import 'package:rogapp/utils/const.dart';
|
||||
import 'package:logger/logger.dart';
|
||||
|
||||
// 目的地に関連する状態管理とロジックを担当するクラスです。
|
||||
//
|
||||
@ -325,6 +326,16 @@ class DestinationController extends GetxController {
|
||||
ds.isNotEmpty && ds[0].checkedin == true ? true : false;
|
||||
bool isuserLoggedIn = indexController.currentUser.isNotEmpty ? true : false; // ログイン済みか
|
||||
|
||||
/*
|
||||
// スタートとゴールは除外
|
||||
debugPrint("startTimer CP=${d.cp}");
|
||||
if (d.cp == -1 || d.cp == 0 || d.cp == -2) {
|
||||
skipGps = false;
|
||||
return;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
// 初期化。GPS信号が強くても弱くても
|
||||
if (checkinRadious >= distance || checkinRadious == -1) {
|
||||
//currentSelectedDestinations.add(d);
|
||||
@ -835,11 +846,13 @@ class DestinationController extends GetxController {
|
||||
Get.snackbar(
|
||||
"ロゲが始まっていません",
|
||||
"ロゲ開始ボタンをタップして、ロゲイニングを始める必要があります",
|
||||
icon: const Icon(
|
||||
backgroundColor: Colors.yellow,
|
||||
colorText: Colors.white,
|
||||
icon: const Icon(
|
||||
Icons.assistant_photo_outlined, size: 40.0, color: Colors.blue),
|
||||
snackPosition: SnackPosition.TOP,
|
||||
duration: const Duration(seconds: 3),
|
||||
backgroundColor: Colors.yellow,
|
||||
duration: const Duration(seconds: 3)
|
||||
// backgroundColor: Colors.yellow,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -940,6 +953,8 @@ class DestinationController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ロゲイニングにデータを追加する関数です。
|
||||
//
|
||||
void addToRogaining(double lat, double lon, int destinationId) async {
|
||||
@ -966,13 +981,18 @@ class DestinationController extends GetxController {
|
||||
// 指定されたパスの画像をギャラリーに保存する関数です。
|
||||
//
|
||||
_saveImageFromPath(String imagePath) async {
|
||||
// Read the image file from the given path
|
||||
File imageFile = File(imagePath);
|
||||
Uint8List imageBytes = await imageFile.readAsBytes();
|
||||
try {
|
||||
// Read the image file from the given path
|
||||
File imageFile = File(imagePath);
|
||||
Uint8List imageBytes = await imageFile.readAsBytes();
|
||||
|
||||
// Save the image to the gallery
|
||||
final result = await ImageGallerySaver.saveImage(imageBytes);
|
||||
//print("--- save result --- ${result}");
|
||||
// Save the image to the gallery
|
||||
final result = await ImageGallerySaver.saveImage(imageBytes);
|
||||
//print("--- save result --- ${result}");
|
||||
} catch(e, stackTrace){
|
||||
print('エラーが発生しました: $e');
|
||||
print('スタックトレース: $stackTrace');
|
||||
}
|
||||
}
|
||||
|
||||
// 買い物ポイントを作成する関数です。 指定された目的地に対して買い物ポイントの処理を行います。
|
||||
@ -1009,64 +1029,82 @@ class DestinationController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// チェックインを行う関数です。 指定された目的地に対してチェックインの処理を行います。
|
||||
//
|
||||
// 要検討:チェックインのリクエストが失敗した場合のエラーハンドリングを追加することをお勧めします。
|
||||
//
|
||||
Future<void> makeCheckin(
|
||||
Destination destination, bool action, String imageurl) async {
|
||||
// print("~~~~ calling checkin function ~~~~");
|
||||
// print(
|
||||
// "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ressssss ${destination.sub_loc_id}@@@@@@@@@@@");
|
||||
DatabaseHelper db = DatabaseHelper.instance;
|
||||
List<Destination> ddd =
|
||||
await db.getDestinationByLatLon(destination.lat!, destination.lon!);
|
||||
|
||||
if (ddd.isEmpty) {
|
||||
destination.checkedin = true;
|
||||
destination.checkin_image = imageurl;
|
||||
await db.insertDestination(destination);
|
||||
// print("~~~~ inserted into db ~~~~");
|
||||
}
|
||||
try {
|
||||
// print("~~~~ calling checkin function ~~~~");
|
||||
// print(
|
||||
// "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ressssss ${destination.sub_loc_id}@@@@@@@@@@@");
|
||||
DatabaseHelper db = DatabaseHelper.instance;
|
||||
List<Destination> ddd =
|
||||
await db.getDestinationByLatLon(destination.lat!, destination.lon!);
|
||||
|
||||
if (imageurl == null || imageurl.isEmpty) {
|
||||
if (photos.isNotEmpty) {
|
||||
// imageurlが空の場合は、destinationのcheckin_imageプロパティを使用する
|
||||
debugPrint("photos = ${photos}");
|
||||
imageurl = photos[0].path;
|
||||
if (ddd.isEmpty) {
|
||||
destination.checkedin = true;
|
||||
destination.checkin_image = imageurl;
|
||||
await db.insertDestination(destination);
|
||||
// print("~~~~ inserted into db ~~~~");
|
||||
}
|
||||
debugPrint("imageurl = ${imageurl}");
|
||||
await _saveImageFromPath(imageurl!);
|
||||
|
||||
if (imageurl == null || imageurl.isEmpty) {
|
||||
if (photos.isNotEmpty) {
|
||||
// imageurlが空の場合は、destinationのcheckin_imageプロパティを使用する
|
||||
debugPrint("photos = ${photos}");
|
||||
imageurl = photos[0].path;
|
||||
}
|
||||
debugPrint("imageurl = ${imageurl}");
|
||||
await _saveImageFromPath(imageurl!);
|
||||
}
|
||||
|
||||
populateDestinations();
|
||||
|
||||
/// post to NATNAT
|
||||
if (indexController.currentUser.isNotEmpty) {
|
||||
double cpNum = destination.cp!;
|
||||
|
||||
int userId = indexController.currentUser[0]["user"]["id"];
|
||||
//print("--- Pressed -----");
|
||||
String team = indexController.currentUser[0]["user"]['team_name'];
|
||||
//print("--- _team : ${_team}-----");
|
||||
String eventCode = indexController.currentUser[0]["user"]["event_code"];
|
||||
//print("--- _event_code : ${_event_code}-----");
|
||||
String token = indexController.currentUser[0]["token"];
|
||||
//print("--- _token : ${_token}-----");
|
||||
DateTime now = DateTime.now();
|
||||
String formattedDate = DateFormat('yyyy-MM-dd HH:mm:ss').format(now);
|
||||
|
||||
await addGPStoDB(currentLat, currentLon, isCheckin: 1);
|
||||
|
||||
// print("------ checkin event $eventCode ------");
|
||||
ExternalService()
|
||||
.makeCheckpoint(
|
||||
userId,
|
||||
token,
|
||||
formattedDate,
|
||||
team,
|
||||
cpNum.round(),
|
||||
eventCode,
|
||||
imageurl)
|
||||
.then((value) {
|
||||
// print("------Ext service check point $value ------");
|
||||
});
|
||||
}
|
||||
// dbService.updateDatabase();
|
||||
|
||||
}catch(e, stacktrace){
|
||||
print("エラー:${e}");
|
||||
//print("stack : ${stacktrace}");
|
||||
}finally{
|
||||
dbService.updateDatabase();
|
||||
}
|
||||
|
||||
|
||||
populateDestinations();
|
||||
|
||||
/// post to NATNAT
|
||||
if (indexController.currentUser.isNotEmpty) {
|
||||
double cpNum = destination.cp!;
|
||||
|
||||
int userId = indexController.currentUser[0]["user"]["id"];
|
||||
//print("--- Pressed -----");
|
||||
String team = indexController.currentUser[0]["user"]['team_name'];
|
||||
//print("--- _team : ${_team}-----");
|
||||
String eventCode = indexController.currentUser[0]["user"]["event_code"];
|
||||
//print("--- _event_code : ${_event_code}-----");
|
||||
String token = indexController.currentUser[0]["token"];
|
||||
//print("--- _token : ${_token}-----");
|
||||
DateTime now = DateTime.now();
|
||||
String formattedDate = DateFormat('yyyy-MM-dd HH:mm:ss').format(now);
|
||||
|
||||
await addGPStoDB(currentLat, currentLon, isCheckin: 1);
|
||||
|
||||
// print("------ checkin event $eventCode ------");
|
||||
ExternalService()
|
||||
.makeCheckpoint(userId, token, formattedDate, team, cpNum.round(),
|
||||
eventCode, imageurl)
|
||||
.then((value) {
|
||||
// print("------Ext service check point $value ------");
|
||||
});
|
||||
}
|
||||
dbService.updateDatabase();
|
||||
}
|
||||
|
||||
// チェックインを削除する関数です。
|
||||
@ -1580,11 +1618,13 @@ class DestinationController extends GetxController {
|
||||
Get.snackbar(
|
||||
"画面切り替えでエラー",
|
||||
"画面の切り替えができませんでした",
|
||||
icon: const Icon(
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
icon: const Icon(
|
||||
Icons.assistant_photo_outlined, size: 40.0, color: Colors.blue),
|
||||
snackPosition: SnackPosition.TOP,
|
||||
duration: const Duration(seconds: 3),
|
||||
backgroundColor: Colors.yellow,
|
||||
//backgroundColor: Colors.yellow,
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user