From cd5befddb5354cc4cf73595a3a5df1fe2c8de26e Mon Sep 17 00:00:00 2001 From: AKIRA Date: Fri, 5 Apr 2024 12:32:58 +0900 Subject: [PATCH] =?UTF-8?q?Fix=202800=20=E5=86=8D=E7=99=BA=E3=81=AE?= =?UTF-8?q?=E3=81=9F=E3=82=81=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/index/index_controller.dart | 110 ++++++++++++++------------ 1 file changed, 60 insertions(+), 50 deletions(-) diff --git a/lib/pages/index/index_controller.dart b/lib/pages/index/index_controller.dart index 23fbd6f..c3df902 100644 --- a/lib/pages/index/index_controller.dart +++ b/lib/pages/index/index_controller.dart @@ -164,10 +164,10 @@ class IndexController extends GetxController { void login(String email, String password, BuildContext context) { AuthService.login(email, password).then((value) { - //print("------- logged in user details ######## $value ###### --------"); + print("------- logged in user details ######## $value ###### --------"); if (value.isNotEmpty) { Navigator.pop(context); - //print("--------- user details login ----- $value"); + print("--------- user details login ----- $value"); changeUser(value); } else { isLoading.value = false; @@ -251,10 +251,11 @@ class IndexController extends GetxController { void saveToDevice(String val) async { final SharedPreferences prefs = await SharedPreferences.getInstance(); await prefs.setString("user_token", val); + print("saveToDevice: ${val}"); } void changeUser(Map value, {bool replace = true}) { - //print("---- change user to $value -----"); + print("---- change user to $value -----"); currentUser.clear(); currentUser.add(value); if (replace) { @@ -267,13 +268,13 @@ class IndexController extends GetxController { } else { rogMode.value = 1; } - //print('--- c rog mode --- ${rogMode.value}'); + print('--- c rog mode --- ${rogMode.value}'); Get.toNamed(AppPages.INDEX); } loadUserDetailsForToken(String token) async { AuthService.userForToken(token).then((value) { - ////print("----token val-- $value ------"); + print("----token val-- $value ------"); if (value![0]["user"].isEmpty) { Get.toNamed(AppPages.LOGIN); return; @@ -353,52 +354,61 @@ class IndexController extends GetxController { isLoading.value = true; // ローディング状態をtrueに設定 - LocationService.loadLocationsBound( - bounds.southWest.latitude, - bounds.southWest.longitude, - bounds.northWest.latitude, - bounds.northWest.longitude, - bounds.northEast.latitude, - bounds.northEast.longitude, - bounds.southEast.latitude, - bounds.southEast.longitude, - cat - ).then((value) { - isLoading.value = false; // ローディング状態をfalseに設定 - - if (value == null) { - // APIからのレスポンスがnullの場合は処理を中断 - return; - } - if (value.features.isEmpty) { - if (showPopup == false) { - return; - } - Get.snackbar( - "Too many Points", - "please zoom in", - icon: const Icon(Icons.assistant_photo_outlined, size: 40.0, color: Colors.blue), - snackPosition: SnackPosition.TOP, - duration: const Duration(seconds: 3), - backgroundColor: Colors.yellow, - ); - showPopup = false; - } - if (value.features.isNotEmpty) { - locations.add(value); - } - }).catchError((error) { - isLoading.value = false; // ローディング状態をfalseに設定 - - // エラーハンドリング: APIリクエストが失敗した場合 - Get.snackbar( - "Error", - "Failed to load locations. Please check your internet connection and try again.", - icon: const Icon(Icons.error, size: 40.0, color: Colors.red), - snackPosition: SnackPosition.TOP, - duration: const Duration(milliseconds: 800), - backgroundColor: Colors.yellow, + Future.delayed(const Duration(seconds: 1), () async { + + //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})"); + + var value = await LocationService.loadLocationsBound( + bounds.southWest.latitude, + bounds.southWest.longitude, + bounds.northWest.latitude, + bounds.northWest.longitude, + bounds.northEast.latitude, + bounds.northEast.longitude, + bounds.southEast.latitude, + bounds.southEast.longitude, + 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(); // 追加 + final tk = currentUser[0]["token"]; // 追加 + if (tk != null) { // 追加 + destinationController.fixMapBound(tk); // 追加 + } // 追加 + // return; + } + isLoading.value = false; // ローディング状態をfalseに設定 + + if (value!=null && value.features.isEmpty) { + if (showPopup == false) { + return; + } + Get.snackbar( + "Too many Points", + "please zoom in", + icon: const Icon(Icons.assistant_photo_outlined, size: 40.0, color: Colors.blue), + snackPosition: SnackPosition.TOP, + duration: const Duration(seconds: 3), + backgroundColor: Colors.yellow, + ); + showPopup = false; + } + if (value!=null && value.features.isNotEmpty) { + locations.add(value); + } + }); }