wt1.1.2f fix for 1.1.3

This commit is contained in:
Bossanyi Tibor
2020-10-28 14:05:31 +01:00
parent 27c1d26dfd
commit db95c9a6f7
26 changed files with 672 additions and 510 deletions
+19 -6
View File
@@ -40,6 +40,7 @@ class Cache {
// Keys to store and fetch data from SharedPreferences
static final String authTokenKey = 'auth_token';
static final String customerIdKey = 'customer_id';
static final String firebaseUidKey = 'firebase_uid';
static final String lastStoreDateKey = 'last_date';
static final String isRegisteredKey = 'is_registered';
static final String isLoggedInKey = 'is_logged_in';
@@ -52,6 +53,8 @@ class Cache {
String authToken = "";
Customer userLoggedIn;
String firebaseUid;
bool firstLoad = true;
List<ExerciseType> _exerciseTypes;
@@ -108,18 +111,24 @@ class Cache {
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
userLoggedIn = customer;
setPreferences(prefs, SharePrefsChange.registration, customer.customerId);
setPreferences(prefs, SharePrefsChange.registration, customer.customerId, Cache().firebaseUid);
}
afterLogin(Customer customer) async {
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
userLoggedIn = customer;
await setPreferences(prefs, SharePrefsChange.login, customer.customerId);
await setPreferences(prefs, SharePrefsChange.login, customer.customerId, Cache().firebaseUid);
}
afterFirebaseLogin() async {
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
await setPreferences(prefs, SharePrefsChange.login, userLoggedIn.customerId, Cache().firebaseUid);
}
logout() async {
userLoggedIn = null;
firebaseUid = null;
authToken = "";
_trainee = null;
_percentExercises = -1;
@@ -129,12 +138,13 @@ class Cache {
_myExercisesPlanDetails = LinkedHashMap();
print("Trainees is null? " + (_trainee == null).toString() );
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
await setPreferences(prefs, SharePrefsChange.logout, 0);
await setPreferences(prefs, SharePrefsChange.logout, 0, "");
}
setPreferences(Future<SharedPreferences> prefs,
SharePrefsChange type,
int customerId) async {
int customerId,
String firebaseUid) async {
SharedPreferences sharedPreferences;
sharedPreferences = await prefs;
@@ -146,19 +156,22 @@ class Cache {
sharedPreferences.setInt(Cache.customerIdKey, customerId);
sharedPreferences.setBool(Cache.isRegisteredKey, true);
sharedPreferences.setBool(Cache.isLoggedInKey, true);
sharedPreferences.setString(Cache.firebaseUidKey, firebaseUid);
await ExerciseTypeApi().getExerciseTypes();
await ExerciseTreeApi().getExerciseTree();
exerciseRepository.getExercisesByCustomer(customerId);
await exerciseRepository.getExercisesByCustomer(customerId);
} else if ( type == SharePrefsChange.login ) {
Cache().startPage = "home";
sharedPreferences.setInt(Cache.customerIdKey, customerId);
sharedPreferences.setString(Cache.firebaseUidKey, firebaseUid);
sharedPreferences.setBool(Cache.isLoggedInKey, true);
await ExerciseTypeApi().getExerciseTypes();
await ExerciseTreeApi().getExerciseTree();
exerciseRepository.getExercisesByCustomer(customerId);
await exerciseRepository.getExercisesByCustomer(customerId);
} else if ( type == SharePrefsChange.logout ) {
sharedPreferences.setBool(Cache.isLoggedInKey, false);
sharedPreferences.setInt(Cache.customerIdKey, 0);
sharedPreferences.setString(Cache.firebaseUidKey, null);
sharedPreferences.setString(authTokenKey, "");
}
}
+4 -1
View File
@@ -15,6 +15,7 @@ class Customer {
int admin;
int trainer;
int dataPolicyAllowed;
String firebaseUid;
Customer({this.customerId,
@@ -32,7 +33,8 @@ class Customer {
this.weight,
this.admin,
this.trainer,
this.dataPolicyAllowed
this.dataPolicyAllowed,
this.firebaseUid,
});
Customer.fromJson(Map json) {
@@ -50,6 +52,7 @@ class Customer {
this.weight = json['weight'];
this.admin = json['admin'];
this.trainer = json['trainer'];
this.firebaseUid = json['firebaseUid'];
}
Map<String, dynamic> toJson() =>
+2
View File
@@ -2,6 +2,7 @@
String email;
String password;
int customerId;
String firebaseUid;
User({this.customerId, this.email, this.password});
@@ -11,5 +12,6 @@
{
"username": email,
"password": password,
"firebaseUid": firebaseUid,
};
}