update new features and flutter 3.13
This commit is contained in:
@ -20,6 +20,7 @@ import 'package:rogapp/services/cat_service.dart';
|
||||
import 'package:rogapp/services/location_service.dart';
|
||||
import 'package:rogapp/services/perfecture_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;
|
||||
@ -51,6 +52,8 @@ class IndexController extends GetxController {
|
||||
MapController mapController = MapController();
|
||||
MapController rogMapController = MapController();
|
||||
|
||||
String? userToken;
|
||||
|
||||
var mode = 0.obs;
|
||||
|
||||
// master mode, rog or selection
|
||||
@ -191,50 +194,27 @@ List<LatLng> getLocationsList(){
|
||||
}
|
||||
|
||||
|
||||
void login(String email, String password, BuildContext context){
|
||||
AuthService.login(email, password).then((value){
|
||||
void login(String email, String password, BuildContext context) {
|
||||
AuthService.login(email, password).then((value) {
|
||||
print("------- logged in user details ######## $value ###### --------");
|
||||
if(value.isNotEmpty){
|
||||
currentUser.clear();
|
||||
currentUser.add(value);
|
||||
is_loading.value = false;
|
||||
Navigator.pop(context);
|
||||
loadUserDetails();
|
||||
loadLocationsBound();
|
||||
cats.clear();
|
||||
if(currentFeature.isNotEmpty){
|
||||
getAction();
|
||||
}
|
||||
|
||||
if(currentUser.isNotEmpty){
|
||||
rog_mode.value = 0 ;
|
||||
}
|
||||
else{
|
||||
rog_mode.value = 1;
|
||||
}
|
||||
|
||||
if(rog_mode.value == 1){
|
||||
switchPage(AppPages.TRAVEL);
|
||||
}
|
||||
else{
|
||||
switchPage(AppPages.INITIAL);
|
||||
}
|
||||
//Get.toNamed(AppPages.INITIAL);
|
||||
}else{
|
||||
if (value.isNotEmpty) {
|
||||
Navigator.pop(context);
|
||||
print("--------- user details login ----- $value");
|
||||
changeUser(value);
|
||||
} else {
|
||||
is_loading.value = false;
|
||||
Get.snackbar(
|
||||
"Failed",
|
||||
"User login failed, please try again.",
|
||||
icon: const Icon(Icons.error, size: 40.0, color: Colors.blue),
|
||||
snackPosition: SnackPosition.TOP,
|
||||
duration: const Duration(milliseconds: 800),
|
||||
backgroundColor: Colors.yellow,
|
||||
//icon:Image(image:AssetImage("assets/images/dora.png"))
|
||||
);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
"Failed",
|
||||
"User login failed, please try again.",
|
||||
icon: const Icon(Icons.error, size: 40.0, color: Colors.blue),
|
||||
snackPosition: SnackPosition.TOP,
|
||||
duration: const Duration(milliseconds: 800),
|
||||
backgroundColor: Colors.yellow,
|
||||
//icon:Image(image:AssetImage("assets/images/dora.png"))
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void changePassword(String oldpassword, String newpassword, BuildContext context){
|
||||
String _token = currentUser[0]['token'];
|
||||
@ -407,6 +387,58 @@ void login(String email, String password, BuildContext context){
|
||||
}
|
||||
}
|
||||
|
||||
void saveToDevice(String val) async {
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString("user_token", val);
|
||||
}
|
||||
|
||||
void changeUser(Map<String, dynamic> value, {bool replace = true}) {
|
||||
print("---- change user to ${value} -----");
|
||||
currentUser.clear();
|
||||
currentUser.add(value);
|
||||
if(replace){
|
||||
saveToDevice(currentUser[0]["token"]);
|
||||
}
|
||||
is_loading.value = false;
|
||||
loadUserDetails();
|
||||
loadLocationsBound();
|
||||
cats.clear();
|
||||
if (currentFeature.isNotEmpty) {
|
||||
getAction();
|
||||
}
|
||||
|
||||
if (currentUser.isNotEmpty) {
|
||||
rog_mode.value = 0;
|
||||
} else {
|
||||
rog_mode.value = 1;
|
||||
}
|
||||
|
||||
if (rog_mode.value == 1) {
|
||||
switchPage(AppPages.TRAVEL);
|
||||
} else {
|
||||
switchPage(AppPages.INITIAL);
|
||||
}
|
||||
//Get.toNamed(AppPages.INITIAL);
|
||||
}
|
||||
|
||||
loadUserDetailsForToken(String token) async {
|
||||
AuthService.userForToken(token).then((value) {
|
||||
print("----token val-- $value ------");
|
||||
if(value![0]["user"].isEmpty){
|
||||
Get.toNamed(AppPages.LOGIN);
|
||||
return;
|
||||
}
|
||||
changeUser(value[0], replace:false);
|
||||
print("--------- user details ----- $value");
|
||||
// if (value != null && value.isNotEmpty) {
|
||||
// bool paid = value[0]["paid"] as bool;
|
||||
// if (paid) {
|
||||
// loadCustomAreas();
|
||||
// }
|
||||
// }
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
void loadCustomAreas(){
|
||||
customAreas.clear();
|
||||
|
||||
Reference in New Issue
Block a user