まだ#2800検証中

This commit is contained in:
2024-04-07 10:56:51 +09:00
parent cd5befddb5
commit a0c1efc522
6 changed files with 420 additions and 56 deletions

View File

@ -16,6 +16,7 @@ import 'package:rogapp/services/location_service.dart';
import 'package:rogapp/utils/database_helper.dart';
import 'package:shared_preferences/shared_preferences.dart';
class IndexController extends GetxController {
List<GeoJSONFeatureCollection> locations = <GeoJSONFeatureCollection>[].obs;
List<GeoJSONFeature> currentFeature = <GeoJSONFeature>[].obs;
@ -42,8 +43,11 @@ class IndexController extends GetxController {
var isCustomAreaSelected = false.obs;
RxBool isMapControllerReady = RxBool(false); // MapControllerの初期化状態を管理するフラグ
//final mapControllerReadyStream = Stream<bool>.value(false); // MapControllerの初期化状態を通知するためのストリーム
MapController mapController = MapController();
MapController rogMapController = MapController();
//MapController rogMapController = MapController();
String? userToken;
@ -166,8 +170,9 @@ class IndexController extends GetxController {
AuthService.login(email, password).then((value) {
print("------- logged in user details ######## $value ###### --------");
if (value.isNotEmpty) {
Navigator.pop(context);
// Navigator.pop(context);
print("--------- user details login ----- $value");
//await Future.delayed(const Duration(milliseconds: 500)); // Added Akira:2024-4-6, #2800
changeUser(value);
} else {
isLoading.value = false;
@ -283,7 +288,7 @@ class IndexController extends GetxController {
});
}
/*
/* Old code
void loadLocationsBound() {
if (isCustomAreaSelected.value == true) {
return;
@ -337,17 +342,33 @@ class IndexController extends GetxController {
}
*/
// 2024-04-03 Akira .. Update the code . See ticket 2800.
//
void loadLocationsBound() {
void loadLocationsBound() async {
if (isCustomAreaSelected.value == true) {
return;
}
// Akira 追加:2024-4-6 #2800
await waitForMapControllerReady(); // MapControllerの初期化が完了するまで待機
// Akira 追加:2024-4-6 #2800
locations.clear();
String cat = currentCat.isNotEmpty ? currentCat[0] : "";
if (currentCat.isNotEmpty && currentCat[0] == "-all-") {
cat = "";
}
/*
// Akira Add 2024-4-6
if( mapController.controller == null ) {
print("操作が完了する前にMapControllerまたはウィジェットが破棄されました。");
isLoading.value = true; // ローディング状態をtrueに設定
return;
}
//
*/
LatLngBounds bounds = mapController.bounds!;
currentBound.clear();
currentBound.add(bounds);
@ -370,24 +391,14 @@ class IndexController extends GetxController {
cat
);
if ( value == null ) {
// エラーハンドリング: APIからのレスポンスがnullの場合
/*
Get.snackbar(
"Error",
"Failed to load locations. Please try again. === 1",
icon: const Icon(Icons.error, size: 40.0, color: Colors.red),
snackPosition: SnackPosition.TOP,
duration: const Duration(seconds: 3),
backgroundColor: Colors.yellow,
);
*/
// APIからのレスポンスがnullの場合
DestinationController destinationController = Get.find<DestinationController>(); // 追加
final tk = currentUser[0]["token"]; // 追加
if (tk != null) { // 追加
destinationController.fixMapBound(tk); // 追加
} // 追加
// return;
print("LocationService.loadLocationsBound からの回答がnullのため、マップをリロード");
//DestinationController destinationController = Get.find<DestinationController>(); // 追加
//final tk = currentUser[0]["token"]; // 追加
//if (tk != null) { // 追加
// destinationController.fixMapBound(tk); // 追加
//} // 追加
return;
}
isLoading.value = false; // ローディング状態をfalseに設定
@ -412,6 +423,18 @@ class IndexController extends GetxController {
});
}
//===Akira 追加:2024-4-6 #2800
Future<void> waitForMapControllerReady() async {
if (!isMapControllerReady.value) {
await Future.doWhile(() async {
await Future.delayed(const Duration(milliseconds: 500));
return !isMapControllerReady.value;
});
}
}
//===Akira 追加:2024-4-6 #2800
void setBound(LatLngBounds bounds) {
currentBound.clear();
currentBound.add(bounds);