不明
This commit is contained in:
@ -11,6 +11,7 @@ import 'package:rogapp/pages/settings/settings_controller.dart';
|
||||
|
||||
import 'package:rogapp/pages/destination/destination_controller.dart';
|
||||
import 'package:rogapp/pages/index/index_binding.dart';
|
||||
import 'package:rogapp/pages/index/index_controller.dart';
|
||||
import 'package:rogapp/routes/app_pages.dart';
|
||||
import 'package:rogapp/utils/location_controller.dart';
|
||||
import 'package:rogapp/utils/string_values.dart';
|
||||
@ -25,6 +26,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
Map<String, dynamic> deviceInfo = {};
|
||||
|
||||
/*
|
||||
void saveGameState() async {
|
||||
DestinationController destinationController =
|
||||
Get.find<DestinationController>();
|
||||
@ -34,7 +36,22 @@ void saveGameState() async {
|
||||
"rogaining_counted", destinationController.rogainingCounted.value);
|
||||
pref.setBool("ready_for_goal", DestinationController.ready_for_goal);
|
||||
}
|
||||
*/
|
||||
|
||||
// 現在のユーザーのIDも一緒に保存するようにします。
|
||||
void saveGameState() async {
|
||||
DestinationController destinationController =
|
||||
Get.find<DestinationController>();
|
||||
IndexController indexController = Get.find<IndexController>();
|
||||
SharedPreferences pref = await SharedPreferences.getInstance();
|
||||
pref.setInt("user_id", indexController.currentUser[0]["user"]["id"]);
|
||||
pref.setBool("is_in_rog", destinationController.isInRog.value);
|
||||
pref.setBool(
|
||||
"rogaining_counted", destinationController.rogainingCounted.value);
|
||||
pref.setBool("ready_for_goal", DestinationController.ready_for_goal);
|
||||
}
|
||||
|
||||
/*
|
||||
void restoreGame() async {
|
||||
SharedPreferences pref = await SharedPreferences.getInstance();
|
||||
DestinationController destinationController =
|
||||
@ -48,6 +65,24 @@ void restoreGame() async {
|
||||
//print(
|
||||
// "--restored -- destinationController.isInRog.value ${pref.getBool("is_in_rog")} -- ${pref.getBool("rogaining_counted")}");
|
||||
}
|
||||
*/
|
||||
|
||||
void restoreGame() async {
|
||||
SharedPreferences pref = await SharedPreferences.getInstance();
|
||||
IndexController indexController = Get.find<IndexController>();
|
||||
int? savedUserId = pref.getInt("user_id");
|
||||
if (indexController.currentUser.isNotEmpty &&
|
||||
indexController.currentUser[0]["user"]["id"] == savedUserId) {
|
||||
DestinationController destinationController =
|
||||
Get.find<DestinationController>();
|
||||
destinationController.skipGps = false;
|
||||
destinationController.isInRog.value = pref.getBool("is_in_rog") ?? false;
|
||||
destinationController.rogainingCounted.value =
|
||||
pref.getBool("rogaining_counted") ?? false;
|
||||
DestinationController.ready_for_goal =
|
||||
pref.getBool("ready_for_goal") ?? false;
|
||||
}
|
||||
}
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user