WT 1.1.11+3 Evaluation, null-safe fixes

This commit is contained in:
bossanyit
2021-04-12 00:51:09 +02:00
parent 01148c6e39
commit 10c8a0a2d8
73 changed files with 3256 additions and 676 deletions
+3
View File
@@ -8,6 +8,7 @@ import 'package:aitrainer_app/model/cache.dart';
class APIClient with Common, Logging {
Future<String> get(String endPoint, String param) async {
final url = Cache.getBaseUrl() + endPoint + param;
trace("-------- API get " + url);
String authToken = Cache().getAuthToken();
if (authToken.length == 0) {
@@ -57,6 +58,7 @@ class APIClient with Common, Logging {
final response = await http.post(uri, headers: {'Authorization': '1', 'Content-Type': 'application/json'}, body: body);
final responseCode = response.statusCode;
if (responseCode != 200) {
trace("authentication response: $responseCode");
return {
"error": "Authentication error, total failure",
};
@@ -65,6 +67,7 @@ class APIClient with Common, Logging {
final responseJson = json.decode(response.body);
return responseJson;
} catch (exception) {
print(exception.toString());
return {"error": "Network error, try again later " + exception.toString()};
}
}
+3 -2
View File
@@ -91,9 +91,10 @@ class ExercisePlanApi with Logging {
final String responseBody = await _client.get("exercise_plan/last/" + customerId.toString(), body);
exercisePlan = ExercisePlan.fromJson(jsonDecode(responseBody));
} on Exception catch (e) {
print(e.toString());
if (e is NotFoundException) {
log("ExercisePlan not found for " + customerId.toString());
return exercisePlan;
return null;
} else {
throw new Exception(e.toString());
}
@@ -104,7 +105,7 @@ class ExercisePlanApi with Logging {
Future<List<ExercisePlanDetail>> getExercisePlanDetail(int exercisePlanId) async {
String body = "";
log(" ===== get exercisePlanDetail $exercisePlanId");
List<ExercisePlanDetail> listExercisePlanDetail;
List<ExercisePlanDetail> listExercisePlanDetail = [];
try {
final String responseBody = await _client.get("exercise_plan_detail/" + exercisePlanId.toString(), body);
log("response body:" + responseBody);
+9 -6
View File
@@ -109,7 +109,7 @@ class FirebaseApi with logging.Logging {
// Sign in the user with Firebase. If the nonce we generated earlier does
// not match the nonce in `appleCredential.identityToken`, sign in will fail.
UserCredential userCredential = await FirebaseAuth.instance.signInWithCredential(oauthCredential);
Cache().firebaseUid = userCredential.user!.uid;
log("userCredential: " + userCredential.toString());
log("Apple Credentials: " +
@@ -181,7 +181,8 @@ class FirebaseApi with logging.Logging {
idToken: googleAuth.idToken,
);
await FirebaseAuth.instance.signInWithCredential(credential);
UserCredential userCredential = await FirebaseAuth.instance.signInWithCredential(credential);
Cache().firebaseUid = userCredential.user!.uid;
log("GoogleUser: " + googleUser.toString());
userData['email'] = googleUser.email;
@@ -230,8 +231,9 @@ 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.accessToken;
if (accessToken != null) {
final LoginResult result = await FacebookAuth.instance.login();
if (result.status == LoginStatus.success) {
final AccessToken accessToken = result.accessToken!;
log(accessToken.toJson().toString());
Cache().accessTokenFacebook = accessToken;
// get the user data
@@ -249,8 +251,9 @@ 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.accessToken;
if (accessToken != null) {
final LoginResult result = await FacebookAuth.instance.login();
if (result.status == LoginStatus.success) {
final AccessToken accessToken = result.accessToken!;
Cache().accessTokenFacebook = accessToken;
// get the user data
userData = await FacebookAuth.instance.getUserData();
+4
View File
@@ -4,6 +4,7 @@ import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/model/customer.dart';
import 'package:aitrainer_app/model/customer_exercise_device.dart';
import 'package:aitrainer_app/model/customer_property.dart';
import 'package:aitrainer_app/model/evaluation.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';
@@ -59,6 +60,9 @@ class PackageApi {
Cache().setExercisePlanTemplates(exercisePlanTemplates);
} else if (headRecord[0] == "ExerciseTreeParents") {
exerciseTreeParents = json.map((exerciseTreeParent) => ExerciseTreeParents.fromJson(exerciseTreeParent)).toList();
} else if (headRecord[0] == "Evaluation") {
final List<Evaluation> evaluations = json.map((evaluation) => Evaluation.fromJson(evaluation)).toList();
Cache().evaluations = evaluations;
}
});