WT1.1.11 Null-Safe migration
This commit is contained in:
+10
-7
@@ -15,7 +15,8 @@ class APIClient with Common, Logging {
|
||||
authToken = responseJson['token'];
|
||||
Cache().authToken = authToken;
|
||||
}
|
||||
final response = await http.get(url, headers: {'Content-Type': 'application/json', 'Authorization': "Bearer " + authToken});
|
||||
var uri = Uri.parse(url);
|
||||
final response = await http.get(uri, headers: {'Content-Type': 'application/json', 'Authorization': "Bearer " + authToken});
|
||||
trace(" ------------get response code: " + response.statusCode.toString());
|
||||
if (response.statusCode == 200) {
|
||||
return utf8.decode(response.bodyBytes);
|
||||
@@ -34,9 +35,9 @@ class APIClient with Common, Logging {
|
||||
var responseJson = await this.authenticateUser(Cache.username, Cache.password);
|
||||
authToken = responseJson['token'];
|
||||
}
|
||||
|
||||
var uri = Uri.parse(url);
|
||||
final response = await http.post(
|
||||
url,
|
||||
uri,
|
||||
headers: {'Content-Type': 'application/json; charset=UTF-8', 'Authorization': "Bearer " + authToken},
|
||||
body: body,
|
||||
);
|
||||
@@ -47,11 +48,12 @@ class APIClient with Common, Logging {
|
||||
}
|
||||
|
||||
dynamic authenticateUser(String email, String password) async {
|
||||
var uri = Cache.getBaseUrl() + "authenticate";
|
||||
var url = Cache.getBaseUrl() + "authenticate";
|
||||
|
||||
try {
|
||||
final body = '{"username":"$email", "password":"$password"}';
|
||||
trace("authentication with $email");
|
||||
var uri = Uri.parse(url);
|
||||
final response = await http.post(uri, headers: {'Authorization': '1', 'Content-Type': 'application/json'}, body: body);
|
||||
final responseCode = response.statusCode;
|
||||
if (responseCode != 200) {
|
||||
@@ -67,10 +69,11 @@ class APIClient with Common, Logging {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fetch(var authToken, var endPoint) async {
|
||||
var uri = Cache.getBaseUrl() + endPoint;
|
||||
Future<String?> fetch(var authToken, var endPoint) async {
|
||||
var url = Cache.getBaseUrl() + endPoint;
|
||||
|
||||
try {
|
||||
var uri = Uri.parse(url);
|
||||
final response = await http.get(
|
||||
uri,
|
||||
headers: {'Authorization': authToken},
|
||||
@@ -79,7 +82,7 @@ class APIClient with Common, Logging {
|
||||
final responseJson = json.decode(response.body);
|
||||
return responseJson;
|
||||
} catch (exception) {
|
||||
log(exception);
|
||||
log(exception.toString());
|
||||
if (exception.toString().contains('SocketException')) {
|
||||
return 'NetworkError';
|
||||
} else {
|
||||
|
||||
@@ -9,7 +9,7 @@ class CustomerExerciseDeviceApi with Logging {
|
||||
final APIClient _client = new APIClient();
|
||||
|
||||
Future<List<CustomerExerciseDevice>> getDevices(int customerId) async {
|
||||
List<CustomerExerciseDevice> devices;
|
||||
List<CustomerExerciseDevice> devices = [];
|
||||
try {
|
||||
log(" --- get customer_exercise_devices: ");
|
||||
final body = await _client.get("customer_exercise_device/customer/" + customerId.toString(), "");
|
||||
@@ -17,6 +17,7 @@ class CustomerExerciseDeviceApi with Logging {
|
||||
devices = json.map((device) => CustomerExerciseDevice.fromJson(device)).toList();
|
||||
} on NotFoundException catch (_) {
|
||||
log("No devices found");
|
||||
devices = [];
|
||||
}
|
||||
return devices;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ class CustomerApi with Logging {
|
||||
final String responseBody = await _client.post("registration", body);
|
||||
Customer customer;
|
||||
try {
|
||||
int status = jsonDecode(responseBody)['status'];
|
||||
int? status = jsonDecode(responseBody)['status'];
|
||||
if (status != null) {
|
||||
String error = jsonDecode(responseBody)['error'];
|
||||
throw new Exception(error);
|
||||
@@ -82,10 +82,10 @@ class CustomerApi with Logging {
|
||||
try {
|
||||
customer = Customer.fromJson(jsonDecode(responseBody));
|
||||
if (customer.firebaseUid == null) {
|
||||
await this.updateFirebaseUid(customer.customerId, Cache().firebaseUid);
|
||||
await this.updateFirebaseUid(customer.customerId!, Cache().firebaseUid!);
|
||||
}
|
||||
Cache().userLoggedIn = customer;
|
||||
final List properties = await this.getActualProperties(customer.customerId);
|
||||
final List<CustomerProperty>? properties = await this.getActualProperties(customer.customerId!);
|
||||
if (properties != null) {
|
||||
this.initProperties(properties);
|
||||
}
|
||||
@@ -102,7 +102,7 @@ class CustomerApi with Logging {
|
||||
Customer customer = Customer.fromJson(jsonDecode(responseBody));
|
||||
log(" --- Customer: " + customer.toJson().toString());
|
||||
Cache().userLoggedIn = customer;
|
||||
final List properties = await this.getActualProperties(customerId);
|
||||
final List<CustomerProperty>? properties = await this.getActualProperties(customerId);
|
||||
//log(" ---- Props: " + properties.toJson().toString());
|
||||
//await Cache().initCustomer(customerId);
|
||||
if (properties != null) {
|
||||
@@ -116,25 +116,27 @@ class CustomerApi with Logging {
|
||||
}
|
||||
}
|
||||
|
||||
void initProperties(final List<CustomerProperty> customerProperties) {
|
||||
List<Property> properties = Cache().getProperties();
|
||||
Customer customer = Cache().userLoggedIn;
|
||||
void initProperties(final List<CustomerProperty>? customerProperties) {
|
||||
List<Property>? properties = Cache().getProperties();
|
||||
Customer customer = Cache().userLoggedIn!;
|
||||
customer.properties = LinkedHashMap<String, CustomerProperty>();
|
||||
|
||||
// reset Properties
|
||||
properties.forEach((property) {
|
||||
CustomerProperty customerProperty =
|
||||
CustomerProperty(propertyId: property.propertyId, customerId: customer.customerId, dateAdd: null, propertyValue: 0);
|
||||
customer.properties[property.propertyName] = customerProperty;
|
||||
});
|
||||
|
||||
customerProperties.forEach((customerProperty) {
|
||||
if (properties != null) {
|
||||
// reset Properties
|
||||
properties.forEach((property) {
|
||||
if (customerProperty.propertyId == property.propertyId) {
|
||||
customer.properties[property.propertyName] = customerProperty;
|
||||
}
|
||||
CustomerProperty customerProperty =
|
||||
CustomerProperty(propertyId: property.propertyId, customerId: customer.customerId!, dateAdd: DateTime.now(), propertyValue: 0);
|
||||
customer.properties[property.propertyName] = customerProperty;
|
||||
});
|
||||
});
|
||||
|
||||
customerProperties!.forEach((customerProperty) {
|
||||
properties.forEach((property) {
|
||||
if (customerProperty.propertyId == property.propertyId) {
|
||||
customer.properties[property.propertyName] = customerProperty;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future<Customer> getTrainee(int customerId) async {
|
||||
@@ -153,7 +155,7 @@ class CustomerApi with Logging {
|
||||
}
|
||||
|
||||
Future<List<Customer>> getTrainees(int trainerId) async {
|
||||
List<Customer> trainees = List<Customer>();
|
||||
List<Customer> trainees = [];
|
||||
log("Get trainees list");
|
||||
try {
|
||||
String body = "";
|
||||
@@ -175,18 +177,12 @@ class CustomerApi with Logging {
|
||||
return properties;
|
||||
}
|
||||
|
||||
Future<List<CustomerProperty>> getActualProperties(int customerId) async {
|
||||
List<CustomerProperty> properties;
|
||||
Future<List<CustomerProperty>?> getActualProperties(int customerId) async {
|
||||
List<CustomerProperty>? properties;
|
||||
try {
|
||||
final body = await _client.get("customer_property/last/", customerId.toString());
|
||||
final Iterable json = jsonDecode(body);
|
||||
properties = json.map((property) => CustomerProperty.fromJson(property)).toList();
|
||||
|
||||
if (properties != null) {
|
||||
properties.forEach((element) {
|
||||
//log("Property " + element.toString());
|
||||
});
|
||||
}
|
||||
} on Exception catch (ex) {
|
||||
log(ex.toString());
|
||||
}
|
||||
@@ -197,18 +193,15 @@ class CustomerApi with Logging {
|
||||
String body = JsonEncoder().convert(property.toJson());
|
||||
log(" ===== add new customer property: " + body);
|
||||
CustomerProperty customerProperty;
|
||||
String responseBody;
|
||||
String? responseBody;
|
||||
try {
|
||||
responseBody = await _client.post("customer_property", body);
|
||||
log(" responseBody: " + responseBody);
|
||||
int status = jsonDecode(responseBody)['status'];
|
||||
int? status = jsonDecode(responseBody)['status'];
|
||||
if (status != null) {
|
||||
throw new Exception(jsonDecode(responseBody)['error']);
|
||||
} else {
|
||||
customerProperty = CustomerProperty.fromJson(jsonDecode(responseBody));
|
||||
if (customerProperty == null) {
|
||||
throw new Exception("Property Insert was not successful");
|
||||
}
|
||||
}
|
||||
} on FormatException {
|
||||
throw new Exception(responseBody);
|
||||
@@ -220,20 +213,17 @@ class CustomerApi with Logging {
|
||||
|
||||
Future<CustomerProperty> updateProperty(CustomerProperty property) async {
|
||||
String body = JsonEncoder().convert(property.toJson());
|
||||
CustomerProperty customerProperty;
|
||||
CustomerProperty? customerProperty;
|
||||
log(" ===== update customer property: " + body);
|
||||
String responseBody;
|
||||
String? responseBody;
|
||||
try {
|
||||
responseBody = await _client.post("customer_property/update/" + property.customerPropertyId.toString(), body);
|
||||
log(" responseBody: " + responseBody);
|
||||
int status = jsonDecode(responseBody)['status'];
|
||||
int? status = jsonDecode(responseBody)['status'];
|
||||
if (status != null) {
|
||||
throw new Exception(jsonDecode(responseBody)['error']);
|
||||
} else {
|
||||
customerProperty = CustomerProperty.fromJson(jsonDecode(responseBody));
|
||||
if (customerProperty == null) {
|
||||
throw new Exception("Property Update was not successful");
|
||||
}
|
||||
}
|
||||
} on FormatException {
|
||||
throw new Exception(responseBody);
|
||||
|
||||
@@ -83,10 +83,10 @@ class ExercisePlanApi with Logging {
|
||||
return;
|
||||
}
|
||||
|
||||
Future<ExercisePlan> getLastExercisePlan(int customerId) async {
|
||||
Future<ExercisePlan?> getLastExercisePlan(int customerId) async {
|
||||
String body = "";
|
||||
log(" ===== get last exercisePlan $customerId");
|
||||
ExercisePlan exercisePlan;
|
||||
ExercisePlan? exercisePlan;
|
||||
try {
|
||||
final String responseBody = await _client.get("exercise_plan/last/" + customerId.toString(), body);
|
||||
exercisePlan = ExercisePlan.fromJson(jsonDecode(responseBody));
|
||||
|
||||
@@ -33,7 +33,7 @@ class ExerciseApi with Logging {
|
||||
}
|
||||
|
||||
Future<void> deleteExercise(Exercise exercise) async {
|
||||
int exerciseId = exercise.exerciseId;
|
||||
int exerciseId = exercise.exerciseId!;
|
||||
log(" ===== delete exercise: " + exerciseId.toString());
|
||||
await _client.post("exercises/" + exerciseId.toString(), "");
|
||||
return;
|
||||
|
||||
@@ -13,18 +13,17 @@ class ExerciseTreeApi with Logging {
|
||||
Future<List<ExerciseTree>> getExerciseTree() async {
|
||||
final String body = await _client.get("exercise_tree", "");
|
||||
Iterable json = jsonDecode(body);
|
||||
List<ExerciseTree> exerciseTree = json.map((exerciseTree) => ExerciseTree.fromJson(exerciseTree)).toList();
|
||||
List<ExerciseTree>? exerciseTree = json.map((exerciseTree) => ExerciseTree.fromJson(exerciseTree)).toList();
|
||||
|
||||
exerciseTree = await getExerciseTreeParents(exerciseTree);
|
||||
|
||||
if (exerciseTree != null) {
|
||||
await Future.forEach(exerciseTree, (element) async {
|
||||
element.imageUrl = await buildImage(element.imageUrl, element.treeId);
|
||||
});
|
||||
exerciseTree = await getExerciseTreeParents(exerciseTree);
|
||||
log("ExerciseTree downloaded");
|
||||
Cache().setExerciseTree(exerciseTree);
|
||||
}
|
||||
await Future.forEach(exerciseTree, (element) async {
|
||||
ExerciseTree exerciseTree = element as ExerciseTree;
|
||||
exerciseTree.imageUrl = await buildImage(exerciseTree.imageUrl, exerciseTree.treeId);
|
||||
});
|
||||
exerciseTree = await getExerciseTreeParents(exerciseTree);
|
||||
log("ExerciseTree downloaded");
|
||||
Cache().setExerciseTree(exerciseTree);
|
||||
|
||||
return exerciseTree;
|
||||
}
|
||||
@@ -55,11 +54,11 @@ class ExerciseTreeApi with Logging {
|
||||
if (parent.exerciseTreeChildId == element.treeId) {
|
||||
if (index > 0) {
|
||||
ExerciseTree newElement = element.copy(parent.exerciseTreeParentId);
|
||||
newElement.sort = parent.sort ?? 0;
|
||||
newElement.sort = parent.sort;
|
||||
exerciseTree.add(newElement);
|
||||
} else {
|
||||
element.parentId = parent.exerciseTreeParentId;
|
||||
element.sort = parent.sort ?? 0;
|
||||
element.sort = parent.sort;
|
||||
exerciseTree[treeIndex].parentId = parent.exerciseTreeParentId;
|
||||
}
|
||||
index++;
|
||||
@@ -71,7 +70,7 @@ class ExerciseTreeApi with Logging {
|
||||
}
|
||||
|
||||
List<ExerciseTree> copyList(List<ExerciseTree> tree) {
|
||||
final List<ExerciseTree> copyList = List();
|
||||
final List<ExerciseTree> copyList = [];
|
||||
tree.forEach((element) {
|
||||
final ExerciseTree copy = element.copy(-1);
|
||||
copyList.add(copy);
|
||||
|
||||
@@ -12,13 +12,13 @@ class ExerciseTypeApi with Logging {
|
||||
final body = await _client.get("exercise_type", "");
|
||||
final Iterable json = jsonDecode(body);
|
||||
final List<ExerciseType> exerciseTypes = json.map((exerciseType) => ExerciseType.fromJson(exerciseType)).toList();
|
||||
if (exerciseTypes != null) {
|
||||
await Future.forEach(exerciseTypes, (element) async {
|
||||
element.imageUrl = await buildImage(element.imageUrl, element.exerciseTypeId);
|
||||
});
|
||||
log("ExerciseTypes downloaded");
|
||||
Cache().setExerciseTypes(exerciseTypes);
|
||||
}
|
||||
|
||||
await Future.forEach(exerciseTypes, (element) async {
|
||||
ExerciseType exerciseType = element as ExerciseType;
|
||||
exerciseType.imageUrl = await buildImage(exerciseType.imageUrl, exerciseType.exerciseTypeId);
|
||||
});
|
||||
log("ExerciseTypes downloaded");
|
||||
Cache().setExerciseTypes(exerciseTypes);
|
||||
|
||||
return exerciseTypes;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import 'package:google_sign_in/google_sign_in.dart';
|
||||
|
||||
class FirebaseApi with logging.Logging {
|
||||
bool appleSignInAvailable = false;
|
||||
static FirebaseApi _instance;
|
||||
//late FirebaseApi _instance;
|
||||
|
||||
static final FirebaseAuth auth = FirebaseAuth.instance;
|
||||
|
||||
@@ -18,13 +18,11 @@ class FirebaseApi with logging.Logging {
|
||||
static const String REGISTER_WEAK_PWD = "weak-password";
|
||||
static const String REGISTER_EMAIL_IN_USE = "email-already-in-use";
|
||||
|
||||
UserCredential userCredential;
|
||||
late UserCredential userCredential;
|
||||
|
||||
factory FirebaseApi() => _instance ?? FirebaseApi._internal();
|
||||
factory FirebaseApi() => FirebaseApi._internal();
|
||||
|
||||
FirebaseApi._internal() {
|
||||
_instance = this;
|
||||
}
|
||||
FirebaseApi._internal();
|
||||
|
||||
// Define an async function to initialize FlutterFire
|
||||
Future<void> initializeFlutterFire() async {
|
||||
@@ -38,7 +36,7 @@ class FirebaseApi with logging.Logging {
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> signInEmail(String email, String password) async {
|
||||
Future<String> signInEmail(String? email, String? password) async {
|
||||
if (email == null) {
|
||||
throw Exception("Please type an email address");
|
||||
}
|
||||
@@ -48,7 +46,7 @@ class FirebaseApi with logging.Logging {
|
||||
String rc = SIGN_IN_OK;
|
||||
try {
|
||||
userCredential = await FirebaseAuth.instance.signInWithEmailAndPassword(email: email, password: password);
|
||||
Cache().firebaseUid = userCredential.user.uid;
|
||||
Cache().firebaseUid = userCredential.user!.uid;
|
||||
} on FirebaseAuthException catch (e) {
|
||||
if (e.code == 'user-not-found') {
|
||||
log('No user found for that email.');
|
||||
@@ -67,7 +65,7 @@ class FirebaseApi with logging.Logging {
|
||||
String rc = SIGN_IN_OK;
|
||||
try {
|
||||
userCredential = await FirebaseAuth.instance.createUserWithEmailAndPassword(email: email, password: password);
|
||||
Cache().firebaseUid = userCredential.user.uid;
|
||||
Cache().firebaseUid = userCredential.user!.uid;
|
||||
} on FirebaseAuthException catch (e) {
|
||||
if (e.code == 'weak-password') {
|
||||
log('The password provided is too weak.');
|
||||
@@ -79,7 +77,7 @@ class FirebaseApi with logging.Logging {
|
||||
throw Exception("The email address has been registered already");
|
||||
}
|
||||
} catch (e) {
|
||||
log(e);
|
||||
log(e.toString());
|
||||
throw Exception(e.toString());
|
||||
}
|
||||
return rc;
|
||||
@@ -98,11 +96,9 @@ class FirebaseApi with logging.Logging {
|
||||
case AuthorizationStatus.error:
|
||||
print('User error');
|
||||
throw Exception("Apple Sign-In failed");
|
||||
break;
|
||||
case AuthorizationStatus.cancelled:
|
||||
print('User cancelled');
|
||||
throw Exception("Apple Sign-In cancelled");
|
||||
break;
|
||||
}
|
||||
|
||||
// Create an `OAuthCredential` from the credential returned by Apple.
|
||||
@@ -121,8 +117,8 @@ class FirebaseApi with logging.Logging {
|
||||
" state " +
|
||||
result.credential.state.toString() +
|
||||
" email " +
|
||||
userCredential.user.email);
|
||||
userData['email'] = userCredential.user.email;
|
||||
userCredential.user!.email!);
|
||||
userData['email'] = userCredential.user!.email;
|
||||
|
||||
return userData;
|
||||
}
|
||||
@@ -139,11 +135,9 @@ class FirebaseApi with logging.Logging {
|
||||
case AuthorizationStatus.error:
|
||||
print('Apple User error');
|
||||
throw Exception("Apple Sign-In failed");
|
||||
break;
|
||||
case AuthorizationStatus.cancelled:
|
||||
print('User cancelled');
|
||||
throw Exception("Apple Sign-In cancelled");
|
||||
break;
|
||||
}
|
||||
|
||||
// Create an `OAuthCredential` from the credential returned by Apple.
|
||||
@@ -155,9 +149,9 @@ class FirebaseApi with logging.Logging {
|
||||
// not match the nonce in `appleCredential.identityToken`, sign in will fail.
|
||||
UserCredential userCredential = await FirebaseAuth.instance.signInWithCredential(oauthCredential);
|
||||
|
||||
Cache().firebaseUid = userCredential.user.uid;
|
||||
Cache().firebaseUid = userCredential.user!.uid;
|
||||
|
||||
userData['email'] = userCredential.user.email;
|
||||
userData['email'] = userCredential.user!.email;
|
||||
|
||||
return userData;
|
||||
}
|
||||
@@ -172,7 +166,7 @@ class FirebaseApi with logging.Logging {
|
||||
'https://www.googleapis.com/auth/contacts.readonly',
|
||||
],
|
||||
);
|
||||
final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
|
||||
final GoogleSignInAccount? googleUser = await _googleSignIn.signIn();
|
||||
|
||||
if (googleUser == null) {
|
||||
throw Exception("Google Sign In failed");
|
||||
@@ -182,19 +176,17 @@ class FirebaseApi with logging.Logging {
|
||||
final GoogleSignInAuthentication googleAuth = await googleUser.authentication;
|
||||
|
||||
// Create a new credential
|
||||
final GoogleAuthCredential credential = GoogleAuthProvider.credential(
|
||||
final OAuthCredential credential = GoogleAuthProvider.credential(
|
||||
accessToken: googleAuth.accessToken,
|
||||
idToken: googleAuth.idToken,
|
||||
);
|
||||
|
||||
await FirebaseAuth.instance.signInWithCredential(credential);
|
||||
|
||||
if (googleUser != null) {
|
||||
log("GoogleUser: " + googleUser.toString());
|
||||
userData['email'] = googleUser.email;
|
||||
userData['id'] = googleUser.id;
|
||||
userData['name'] = googleUser.displayName;
|
||||
}
|
||||
log("GoogleUser: " + googleUser.toString());
|
||||
userData['email'] = googleUser.email;
|
||||
userData['id'] = googleUser.id;
|
||||
userData['name'] = googleUser.displayName;
|
||||
|
||||
return userData;
|
||||
}
|
||||
@@ -209,7 +201,7 @@ class FirebaseApi with logging.Logging {
|
||||
'https://www.googleapis.com/auth/contacts.readonly',
|
||||
],
|
||||
);
|
||||
final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
|
||||
final GoogleSignInAccount? googleUser = await _googleSignIn.signIn();
|
||||
|
||||
if (googleUser == null) {
|
||||
throw Exception("Google Sign In failed");
|
||||
@@ -219,7 +211,7 @@ class FirebaseApi with logging.Logging {
|
||||
final GoogleSignInAuthentication googleAuth = await googleUser.authentication;
|
||||
|
||||
// Create a new credential
|
||||
final GoogleAuthCredential credential = GoogleAuthProvider.credential(
|
||||
final OAuthCredential credential = GoogleAuthProvider.credential(
|
||||
accessToken: googleAuth.accessToken,
|
||||
idToken: googleAuth.idToken,
|
||||
);
|
||||
@@ -227,7 +219,7 @@ class FirebaseApi with logging.Logging {
|
||||
final userCredential = await FirebaseAuth.instance.signInWithCredential(credential);
|
||||
|
||||
log("Google credentials: " + credential.toString() + " GoogleUser: " + googleUser.toString());
|
||||
Cache().firebaseUid = userCredential.user.uid;
|
||||
Cache().firebaseUid = userCredential.user!.uid;
|
||||
|
||||
userData['email'] = googleUser.email;
|
||||
|
||||
@@ -238,7 +230,7 @@ class FirebaseApi with logging.Logging {
|
||||
Map<String, dynamic> userData;
|
||||
|
||||
// by default the login method has the next permissions ['email','public_profile']
|
||||
AccessToken accessToken = await FacebookAuth.instance.login();
|
||||
AccessToken? accessToken = await FacebookAuth.instance.accessToken;
|
||||
if (accessToken != null) {
|
||||
log(accessToken.toJson().toString());
|
||||
Cache().accessTokenFacebook = accessToken;
|
||||
@@ -257,7 +249,7 @@ class FirebaseApi with logging.Logging {
|
||||
Map<String, dynamic> userData;
|
||||
|
||||
// by default the login method has the next permissions ['email','public_profile']
|
||||
AccessToken accessToken = await FacebookAuth.instance.login();
|
||||
AccessToken? accessToken = await FacebookAuth.instance.accessToken;
|
||||
if (accessToken != null) {
|
||||
Cache().accessTokenFacebook = accessToken;
|
||||
// get the user data
|
||||
@@ -265,13 +257,13 @@ class FirebaseApi with logging.Logging {
|
||||
log("FB user data: " + userData.toString());
|
||||
|
||||
// Create a credential from the access token
|
||||
final FacebookAuthCredential facebookAuthCredential = FacebookAuthProvider.credential(accessToken.token);
|
||||
final OAuthCredential facebookAuthCredential = FacebookAuthProvider.credential(accessToken.token);
|
||||
|
||||
// Once signed in, return the UserCredential
|
||||
final userCredential = await FirebaseAuth.instance.signInWithCredential(facebookAuthCredential);
|
||||
log("Email by FB: " + userData['email'] + " FB credential: " + userCredential.toString());
|
||||
|
||||
Cache().firebaseUid = userCredential.user.uid;
|
||||
Cache().firebaseUid = userCredential.user!.uid;
|
||||
} else {
|
||||
throw Exception("Facebook login was not successful");
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import 'package:aitrainer_app/model/customer_property.dart';
|
||||
import 'package:aitrainer_app/model/exercise.dart';
|
||||
import 'package:aitrainer_app/model/exercise_device.dart';
|
||||
import 'package:aitrainer_app/model/exercise_plan_template.dart';
|
||||
import 'package:aitrainer_app/model/exercise_result.dart';
|
||||
import 'package:aitrainer_app/model/exercise_tree.dart';
|
||||
import 'package:aitrainer_app/model/exercise_tree_parents.dart';
|
||||
import 'package:aitrainer_app/model/exercise_type.dart';
|
||||
@@ -26,12 +25,13 @@ class PackageApi {
|
||||
final APIClient _client = new APIClient();
|
||||
|
||||
Future<void> getPackage() async {
|
||||
List<ExerciseTree> exerciseTree;
|
||||
List<ExerciseTreeParents> exerciseTreeParents;
|
||||
late List<ExerciseTree> exerciseTree;
|
||||
late List<ExerciseTreeParents> exerciseTreeParents;
|
||||
final body = await _client.get("app_package/", "");
|
||||
|
||||
final List<String> models = body.split("|||");
|
||||
await Future.forEach(models, (element) async {
|
||||
await Future.forEach(models, (elem) async {
|
||||
final String element = elem as String;
|
||||
final List<String> headRecord = element.split("***");
|
||||
final Iterable json = jsonDecode(headRecord[1]);
|
||||
if (headRecord[0] == "ExerciseDevice") {
|
||||
@@ -47,12 +47,11 @@ class PackageApi {
|
||||
exerciseTree = json.map((exerciseTree) => ExerciseTree.fromJson(exerciseTree)).toList();
|
||||
} else if (headRecord[0] == "ExerciseType") {
|
||||
final List<ExerciseType> exerciseTypes = json.map((exerciseType) => ExerciseType.fromJson(exerciseType)).toList();
|
||||
if (exerciseTypes != null) {
|
||||
await Future.forEach(exerciseTypes, (element) async {
|
||||
element.imageUrl = await ExerciseTypeApi().buildImage(element.imageUrl, element.exerciseTypeId);
|
||||
});
|
||||
Cache().setExerciseTypes(exerciseTypes);
|
||||
}
|
||||
await Future.forEach(exerciseTypes, (elem) async {
|
||||
final ExerciseType exerciseType = elem as ExerciseType;
|
||||
exerciseType.imageUrl = await ExerciseTypeApi().buildImage(exerciseType.imageUrl, exerciseType.exerciseTypeId);
|
||||
});
|
||||
Cache().setExerciseTypes(exerciseTypes);
|
||||
} else if (headRecord[0] == "ExerciseAbility") {
|
||||
} else if (headRecord[0] == "ExercisePlanTemplate") {
|
||||
final List<ExercisePlanTemplate> exercisePlanTemplates =
|
||||
@@ -64,12 +63,12 @@ class PackageApi {
|
||||
});
|
||||
|
||||
exerciseTree = this.getExerciseTreeParents(exerciseTree, exerciseTreeParents);
|
||||
if (exerciseTree != null) {
|
||||
await Future.forEach(exerciseTree, (element) async {
|
||||
element.imageUrl = await ExerciseTreeApi().buildImage(element.imageUrl, element.treeId);
|
||||
});
|
||||
Cache().setExerciseTree(exerciseTree);
|
||||
}
|
||||
|
||||
await Future.forEach(exerciseTree, (element) async {
|
||||
ExerciseTree tree = element as ExerciseTree;
|
||||
tree.imageUrl = await ExerciseTreeApi().buildImage(tree.imageUrl, tree.treeId);
|
||||
});
|
||||
Cache().setExerciseTree(exerciseTree);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -107,7 +106,8 @@ class PackageApi {
|
||||
final body = await _client.get("app_customer_package/" + customerId.toString(), "");
|
||||
|
||||
final List<String> models = body.split("|||");
|
||||
await Future.forEach(models, (element) async {
|
||||
await Future.forEach(models, (elem) async {
|
||||
final String element = elem as String;
|
||||
final List<String> headRecord = element.split("***");
|
||||
//print("Class " + headRecord[0]);
|
||||
if (headRecord[0] == "Customer") {
|
||||
@@ -135,12 +135,12 @@ class PackageApi {
|
||||
final List<CustomerProperty> customerProperties = json.map((property) => CustomerProperty.fromJson(property)).toList();
|
||||
CustomerApi().initProperties(customerProperties);
|
||||
} else if (headRecord[0] == "ExerciseResult") {
|
||||
final Iterable json = jsonDecode(headRecord[1]);
|
||||
final List<ExerciseResult> exerciseResults = json.map((exerciseResult) {
|
||||
/*final Iterable json = jsonDecode(headRecord[1]);
|
||||
final List<ExerciseResult> exerciseResults = json.map((exerciseResult) {
|
||||
ExerciseResult item = ExerciseResult.fromJson(exerciseResult);
|
||||
return item;
|
||||
}).toList();
|
||||
// ToDo
|
||||
// ToDo */
|
||||
}
|
||||
});
|
||||
} on NotFoundException catch (_) {
|
||||
|
||||
@@ -9,7 +9,7 @@ class PurchaseApi with Logging {
|
||||
final APIClient _client = new APIClient();
|
||||
|
||||
Future<List<Purchase>> getPurchasesByCustomer(int customerId) async {
|
||||
List<Purchase> purchases = List();
|
||||
List<Purchase> purchases = [];
|
||||
try {
|
||||
final body = await _client.get("purchase/customer/" + customerId.toString(), "");
|
||||
final Iterable json = jsonDecode(body);
|
||||
|
||||
Reference in New Issue
Block a user