WT1.1.2f Purchase, Product, Property, BMR, BMI, Sizes
This commit is contained in:
+16
-27
@@ -6,6 +6,7 @@ import 'package:aitrainer_app/service/customer_service.dart';
|
||||
import 'package:aitrainer_app/service/exercise_tree_service.dart';
|
||||
import 'package:aitrainer_app/service/exercisetype_service.dart';
|
||||
import 'package:aitrainer_app/service/firebase_api.dart';
|
||||
import 'package:aitrainer_app/service/property_service.dart';
|
||||
import 'package:devicelocale/devicelocale.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
@@ -14,34 +15,29 @@ import 'package:firebase_core/firebase_core.dart';
|
||||
|
||||
//import '../push_notifications.dart';
|
||||
|
||||
class Session {
|
||||
|
||||
class Session {
|
||||
Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
|
||||
|
||||
SharedPreferences _sharedPreferences;
|
||||
|
||||
fetchSessionAndNavigate( ) async {
|
||||
print (" -- Session: await prefs..");
|
||||
fetchSessionAndNavigate() async {
|
||||
print(" -- Session: await prefs..");
|
||||
_sharedPreferences = await _prefs;
|
||||
|
||||
|
||||
if ( Cache().firstLoad ) {
|
||||
|
||||
print (" -- Session: fetch locale..");
|
||||
if (Cache().firstLoad) {
|
||||
print(" -- Session: fetch locale..");
|
||||
await AppLanguage().getLocale(_sharedPreferences);
|
||||
await AppLocalizations.delegate.load(AppLanguage().appLocal);
|
||||
print (" -- Session: fetch token..");
|
||||
print(" -- Session: fetch token..");
|
||||
await _fetchToken(_sharedPreferences);
|
||||
print (" -- FireBase init..");
|
||||
print(" -- FireBase init..");
|
||||
await FirebaseApi().initializeFlutterFire();
|
||||
//initDeviceLocale();
|
||||
|
||||
// Create the initialization Future outside of `build`:
|
||||
|
||||
|
||||
// PushNotificationsManager().init();
|
||||
// PushNotificationsManager().init();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Future<void> initDeviceLocale() async {
|
||||
@@ -53,7 +49,6 @@ class Session {
|
||||
languages = await Devicelocale.preferredLanguages;
|
||||
Cache().deviceLanguages = languages;
|
||||
print("device langs " + languages.toString());
|
||||
|
||||
} on PlatformException {
|
||||
print("Error obtaining preferred languages");
|
||||
}
|
||||
@@ -69,14 +64,10 @@ class Session {
|
||||
Auth flow of the user, see auth.dart
|
||||
*/
|
||||
_fetchToken(SharedPreferences prefs) async {
|
||||
|
||||
var responseJson = await APIClient.authenticateUser(
|
||||
Cache.username,
|
||||
Cache.password
|
||||
);
|
||||
var responseJson = await APIClient.authenticateUser(Cache.username, Cache.password);
|
||||
int customerId = 0;
|
||||
print("--- Lang: " + AppLanguage().appLocal.toString());
|
||||
if(responseJson['error'] != null) {
|
||||
if (responseJson['error'] != null) {
|
||||
print("************** Here big error - no authentication");
|
||||
} else if (responseJson['token'] != null) {
|
||||
prefs.setString(Cache.authTokenKey, responseJson['token']);
|
||||
@@ -89,8 +80,7 @@ class Session {
|
||||
Cache().startPage = "registration";
|
||||
} else {
|
||||
DateTime now = DateTime.now();
|
||||
DateTime lastStoreDate = DateTime.parse(
|
||||
prefs.get(Cache.lastStoreDateKey));
|
||||
DateTime lastStoreDate = DateTime.parse(prefs.get(Cache.lastStoreDateKey));
|
||||
DateTime minStoreDate = now.add(Duration(days: -10));
|
||||
|
||||
if (lastStoreDate == null ||
|
||||
@@ -100,14 +90,14 @@ class Session {
|
||||
print("************* Login");
|
||||
Cache().startPage = "login";
|
||||
} else {
|
||||
|
||||
// only
|
||||
if ( Cache().firebaseUid == null) {
|
||||
if (Cache().firebaseUid == null) {
|
||||
print("************* firebaseUid is null, Login");
|
||||
Cache().startPage = "login";
|
||||
} else {
|
||||
// get API customer
|
||||
customerId = prefs.getInt(Cache.customerIdKey);
|
||||
await PropertyApi().getProperties();
|
||||
await CustomerApi().getCustomer(customerId);
|
||||
Cache().startPage = "home";
|
||||
}
|
||||
@@ -115,13 +105,12 @@ class Session {
|
||||
|
||||
await ExerciseTypeApi().getExerciseTypes();
|
||||
await ExerciseTreeApi().getExerciseTree();
|
||||
if ( customerId > 0) {
|
||||
if (customerId > 0) {
|
||||
ExerciseRepository exerciseRepository = ExerciseRepository();
|
||||
await exerciseRepository.getExercisesByCustomer(customerId);
|
||||
}
|
||||
print("--- Session finished");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,4 +10,6 @@ mixin Trans {
|
||||
String t(String text) {
|
||||
return AppLocalizations.of(context).translate(text);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user