This commit is contained in:
2024-04-30 17:08:23 +09:00
parent 3be78ab97c
commit bbf3be7a62
2 changed files with 74 additions and 0 deletions

View File

@ -16,6 +16,8 @@ import 'package:rogapp/services/location_service.dart';
import 'package:rogapp/utils/database_helper.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../../main.dart';
class IndexController extends GetxController {
List<GeoJSONFeatureCollection> locations = <GeoJSONFeatureCollection>[].obs;
@ -250,6 +252,7 @@ class IndexController extends GetxController {
isLoading.value = false;
}
/*
void logout() async {
locations.clear();
DatabaseHelper db = DatabaseHelper.instance;
@ -265,6 +268,23 @@ class IndexController extends GetxController {
final SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.remove("user_token");
}
*/
void logout() async {
saveGameState();
locations.clear();
DatabaseHelper db = DatabaseHelper.instance;
db.deleteAllDestinations().then((value) {
DestinationController destinationController =
Get.find<DestinationController>();
destinationController.populateDestinations();
});
currentUser.clear();
cats.clear();
final SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.remove("user_token");
}
// 要検討:エラーハンドリングが行われていますが、エラーメッセージをローカライズすることを検討してください。
//
@ -299,6 +319,7 @@ class IndexController extends GetxController {
print("saveToDevice: ${val}");
}
/*
void changeUser(Map<String, dynamic> value, {bool replace = true}) {
print("---- change user to $value -----");
currentUser.clear();
@ -316,6 +337,24 @@ class IndexController extends GetxController {
print('--- c rog mode --- ${rogMode.value}');
Get.toNamed(AppPages.INDEX);
}
*/
void changeUser(Map<String, dynamic> value, {bool replace = true}) {
currentUser.clear();
currentUser.add(value);
if (replace) {
saveToDevice(currentUser[0]["token"]);
}
isLoading.value = false;
loadLocationsBound();
if (currentUser.isNotEmpty) {
rogMode.value = 0;
restoreGame();
} else {
rogMode.value = 1;
}
Get.toNamed(AppPages.INDEX);
}
loadUserDetailsForToken(String token) async {
AuthService.userForToken(token).then((value) {