Fixed Cameraでクラッシュ、日付ズレ、遠くのチェックポイント表示、1日1回のプロテクト

This commit is contained in:
2024-08-07 21:17:13 +09:00
parent 347861e5a1
commit bdf6dd3c04
7 changed files with 227 additions and 21 deletions

View File

@ -23,10 +23,14 @@ import 'package:shared_preferences/shared_preferences.dart';
import 'package:rogapp/services/api_service.dart';
import 'package:rogapp/model/user.dart';
import 'package:rogapp/model/rog.dart';
import 'package:rogapp/main.dart';
import 'package:rogapp/widgets/helper_dialog.dart';
import 'package:timezone/timezone.dart' as tz;
import 'package:timezone/data/latest.dart' as tz;
class IndexController extends GetxController with WidgetsBindingObserver {
List<GeoJSONFeatureCollection> locations = <GeoJSONFeatureCollection>[].obs;
@ -66,6 +70,7 @@ class IndexController extends GetxController with WidgetsBindingObserver {
//late final ApiService _apiService;
final ApiService _apiService = Get.find<ApiService>();
final DatabaseHelper _dbHelper = DatabaseHelper.instance;
// mode = 0 is map mode, mode = 1 list mode
var mode = 0.obs;
@ -237,6 +242,7 @@ class IndexController extends GetxController with WidgetsBindingObserver {
print('IndexController onInit called'); // デバッグ用の出力を追加
tz.initializeTimeZones();
//teamController = Get.find<TeamController>();
}
@ -562,6 +568,10 @@ class IndexController extends GetxController with WidgetsBindingObserver {
saveToDevice(currentUser[0]["token"]);
}
isLoading.value = false;
// ユーザーのイベント情報を取得
await fetchUserEventInfo();
loadLocationsBound( currentUser[0]["user"]["event_code"]);
if (currentUser.isNotEmpty) {
rogMode.value = 0;
@ -575,6 +585,58 @@ class IndexController extends GetxController with WidgetsBindingObserver {
Get.toNamed(AppPages.INDEX);
}
Future<void> fetchUserEventInfo() async {
try {
final List<Entry> entries = await _apiService.getEntries();
if (entries.isNotEmpty) {
final Entry latestEntry = entries.last;
final tokyo = tz.getLocation('Asia/Tokyo');
final eventDate = latestEntry.date!.toUtc();
//final eventDate = tz.TZDateTime.from(utcDate, tokyo);
final eventDateOnly = tz.TZDateTime(tokyo, eventDate.year, eventDate.month, eventDate.day);
currentUser[0]['user']['event_date'] = eventDateOnly.toIso8601String().split('T')[0];
currentUser[0]['user']['event_code'] = latestEntry.event.eventName;
currentUser[0]['user']['team_name'] = latestEntry.team.teamName;
currentUser[0]['user']['group'] = latestEntry.team.category.categoryName;
currentUser[0]['user']['zekken_number'] = latestEntry.zekkenNumber;
// 最後のゴール日時を取得
final lastGoalTime = await getLastGoalTime();
currentUser[0]['user']['last_goal_time'] = lastGoalTime?.toIso8601String();
print('Updated user event info: ${currentUser[0]['user']}');
} else {
print('No entries found for the user');
_clearUserEventInfo();
}
} catch (e) {
print('Error fetching user event info: $e');
_clearUserEventInfo();
}
}
Future<DateTime?> getLastGoalTime() async {
try {
final userId = currentUser[0]['user']['id'];
return await _apiService.getLastGoalTime(userId);
} catch (e) {
print('Error getting last goal time: $e');
}
return null;
}
void _clearUserEventInfo() {
currentUser[0]['user']['event_date'] = null;
currentUser[0]['user']['event_code'] = null;
currentUser[0]['user']['team_name'] = null;
currentUser[0]['user']['group'] = null;
currentUser[0]['user']['zekken_number'] = null;
}
Future<void> fetchTeamData() async {
try {
Get.put(TeamController());
@ -589,6 +651,8 @@ class IndexController extends GetxController with WidgetsBindingObserver {
}
}
loadUserDetailsForToken(String token) async {
AuthService.userForToken(token).then((value) {
print("----token val-- $value ------");