Fix 2800 再発のため修正

This commit is contained in:
2024-04-05 12:32:58 +09:00
parent 299769ec60
commit cd5befddb5

View File

@ -164,10 +164,10 @@ class IndexController extends GetxController {
void login(String email, String password, BuildContext context) { void login(String email, String password, BuildContext context) {
AuthService.login(email, password).then((value) { AuthService.login(email, password).then((value) {
//print("------- logged in user details ######## $value ###### --------"); print("------- logged in user details ######## $value ###### --------");
if (value.isNotEmpty) { if (value.isNotEmpty) {
Navigator.pop(context); Navigator.pop(context);
//print("--------- user details login ----- $value"); print("--------- user details login ----- $value");
changeUser(value); changeUser(value);
} else { } else {
isLoading.value = false; isLoading.value = false;
@ -251,10 +251,11 @@ class IndexController extends GetxController {
void saveToDevice(String val) async { void saveToDevice(String val) async {
final SharedPreferences prefs = await SharedPreferences.getInstance(); final SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setString("user_token", val); await prefs.setString("user_token", val);
print("saveToDevice: ${val}");
} }
void changeUser(Map<String, dynamic> value, {bool replace = true}) { void changeUser(Map<String, dynamic> value, {bool replace = true}) {
//print("---- change user to $value -----"); print("---- change user to $value -----");
currentUser.clear(); currentUser.clear();
currentUser.add(value); currentUser.add(value);
if (replace) { if (replace) {
@ -267,13 +268,13 @@ class IndexController extends GetxController {
} else { } else {
rogMode.value = 1; rogMode.value = 1;
} }
//print('--- c rog mode --- ${rogMode.value}'); print('--- c rog mode --- ${rogMode.value}');
Get.toNamed(AppPages.INDEX); Get.toNamed(AppPages.INDEX);
} }
loadUserDetailsForToken(String token) async { loadUserDetailsForToken(String token) async {
AuthService.userForToken(token).then((value) { AuthService.userForToken(token).then((value) {
////print("----token val-- $value ------"); print("----token val-- $value ------");
if (value![0]["user"].isEmpty) { if (value![0]["user"].isEmpty) {
Get.toNamed(AppPages.LOGIN); Get.toNamed(AppPages.LOGIN);
return; return;
@ -353,7 +354,11 @@ class IndexController extends GetxController {
isLoading.value = true; // ローディング状態をtrueに設定 isLoading.value = true; // ローディング状態をtrueに設定
LocationService.loadLocationsBound( 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.latitude,
bounds.southWest.longitude, bounds.southWest.longitude,
bounds.northWest.latitude, bounds.northWest.latitude,
@ -363,14 +368,30 @@ class IndexController extends GetxController {
bounds.southEast.latitude, bounds.southEast.latitude,
bounds.southEast.longitude, bounds.southEast.longitude,
cat cat
).then((value) { );
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;
}
isLoading.value = false; // ローディング状態をfalseに設定 isLoading.value = false; // ローディング状態をfalseに設定
if (value == null) { if (value!=null && value.features.isEmpty) {
// APIからのレスポンスがnullの場合は処理を中断
return;
}
if (value.features.isEmpty) {
if (showPopup == false) { if (showPopup == false) {
return; return;
} }
@ -384,21 +405,10 @@ class IndexController extends GetxController {
); );
showPopup = false; showPopup = false;
} }
if (value.features.isNotEmpty) { if (value!=null && value.features.isNotEmpty) {
locations.add(value); 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,
);
}); });
} }