Fix all features

This commit is contained in:
2024-07-30 02:15:04 +09:00
parent 9c98d3ed53
commit 3d7a5ae0c1
11 changed files with 268 additions and 69 deletions

View File

@ -10,6 +10,7 @@ import 'package:geolocator/geolocator.dart';
import 'package:get/get.dart';
import 'package:latlong2/latlong.dart';
import 'package:rogapp/model/destination.dart';
import 'package:rogapp/model/entry.dart';
import 'package:rogapp/pages/destination/destination_controller.dart';
import 'package:rogapp/routes/app_pages.dart';
import 'package:rogapp/services/auth_service.dart';
@ -59,6 +60,9 @@ class IndexController extends GetxController with WidgetsBindingObserver {
String? userToken;
//late final ApiService _apiService;
final ApiService _apiService = Get.find<ApiService>();
// mode = 0 is map mode, mode = 1 list mode
var mode = 0.obs;
@ -79,6 +83,16 @@ class IndexController extends GetxController with WidgetsBindingObserver {
final Connectivity _connectivity = Connectivity();
late StreamSubscription<ConnectivityResult> _connectivitySubscription;
final Rx<DateTime> lastUserUpdateTime = DateTime.now().obs;
/*
void updateUserInfo(Map<String, dynamic> newUserInfo) {
currentUser.clear();
currentUser.add(newUserInfo);
lastUserUpdateTime.value = DateTime.now();
}
*/
void toggleMode() {
if (mode.value == 0) {
mode += 1;
@ -202,6 +216,7 @@ class IndexController extends GetxController with WidgetsBindingObserver {
if (currentUser.isNotEmpty) {
// 既にログインしている場合
await Get.putAsync(() => ApiService().init());
//await Get.putAsync(() => ApiService().init());
// 必要に応じて追加の初期化処理
}
}
@ -492,7 +507,7 @@ class IndexController extends GetxController with WidgetsBindingObserver {
saveToDevice(currentUser[0]["token"]);
}
isLoading.value = false;
loadLocationsBound();
loadLocationsBound( currentUser[0]["user"]["even_code"]);
if (currentUser.isNotEmpty) {
rogMode.value = 0;
restoreGame();
@ -577,7 +592,7 @@ class IndexController extends GetxController with WidgetsBindingObserver {
// 要検討Future.delayedを使用して非同期処理を待たずに先に進むようにしていますが、
// これによってメモリリークが発生する可能性があります。非同期処理の結果を適切に処理することを検討してください。
//
void loadLocationsBound() async {
void loadLocationsBound(String eventCode) async {
if (isCustomAreaSelected.value == true) {
return;
}
@ -609,12 +624,13 @@ class IndexController extends GetxController with WidgetsBindingObserver {
currentBound.clear();
currentBound.add(bounds);
isLoading.value = true; // ローディング状態をtrueに設定
//isLoading.value = true; // ローディング状態をtrueに設定
//print("bounds --- (${bounds.southWest.latitude},${bounds.southWest.longitude}),(${bounds.northWest.latitude},${bounds.northWest.longitude}),(${bounds.northEast.latitude},${bounds.northEast.longitude}),(${bounds.southEast.latitude},${bounds.southEast.longitude})");
// 要検討APIからのレスポンスがnullの場合のエラーハンドリングが不十分です。適切なエラーメッセージを表示するなどの処理を追加してください。
try {
final eventCode = currentUser[0]["user"]["event_code"];
final value = await LocationService.loadLocationsBound(
bounds.southWest.latitude,
bounds.southWest.longitude,
@ -624,7 +640,8 @@ class IndexController extends GetxController with WidgetsBindingObserver {
bounds.northEast.longitude,
bounds.southEast.latitude,
bounds.southEast.longitude,
cat
cat,
eventCode
);
/*
if (value == null) {
@ -728,4 +745,11 @@ class IndexController extends GetxController with WidgetsBindingObserver {
}
return null;
}
void reloadMap( String eventCode ) {
// マップをリロードするロジックを実装
// 例: 現在の位置情報を再取得し、マップを更新する
loadLocationsBound( eventCode );
}
}