v1.0.1 warning fixes
This commit is contained in:
parent
ee205bf4b8
commit
9782a1ca46
File diff suppressed because one or more lines are too long
1
.gitignore
vendored
1
.gitignore
vendored
@ -28,3 +28,4 @@ migrate_working_dir/
|
|||||||
.dart_tool/
|
.dart_tool/
|
||||||
.packages
|
.packages
|
||||||
build/
|
build/
|
||||||
|
.flutter-plugins-dependencies*
|
@ -119,6 +119,7 @@ class Cache with Logging {
|
|||||||
|
|
||||||
static String baseUrlLive = 'https://api.workouttest.org/api/';
|
static String baseUrlLive = 'https://api.workouttest.org/api/';
|
||||||
static String baseUrlTest = 'https://apitest.workouttest.org/api/';
|
static String baseUrlTest = 'https://apitest.workouttest.org/api/';
|
||||||
|
static String baseUrlLocal = 'http://localhost:8443/api/';
|
||||||
late String baseUrl;
|
late String baseUrl;
|
||||||
static const String mediaUrl = 'https://admin.workouttest.org/media/';
|
static const String mediaUrl = 'https://admin.workouttest.org/media/';
|
||||||
static const String username = 'bosi';
|
static const String username = 'bosi';
|
||||||
@ -199,6 +200,9 @@ class Cache with Logging {
|
|||||||
if (testEnv == "1") {
|
if (testEnv == "1") {
|
||||||
baseUrl = baseUrlTest;
|
baseUrl = baseUrlTest;
|
||||||
liveServer = false;
|
liveServer = false;
|
||||||
|
} else if ( testEnv == "2") {
|
||||||
|
baseUrl = baseUrlLocal;
|
||||||
|
liveServer = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var element in ActivityDone.values) {
|
for (var element in ActivityDone.values) {
|
||||||
@ -210,6 +214,10 @@ class Cache with Logging {
|
|||||||
baseUrl = baseUrlTest;
|
baseUrl = baseUrlTest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setLocalBaseUrl() {
|
||||||
|
baseUrl = baseUrlLocal;
|
||||||
|
}
|
||||||
|
|
||||||
String getAuthToken() {
|
String getAuthToken() {
|
||||||
return authToken;
|
return authToken;
|
||||||
}
|
}
|
||||||
@ -362,10 +370,14 @@ class Cache with Logging {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setServerAddress(SharedPreferences prefs) {
|
void setServerAddress(SharedPreferences prefs) {
|
||||||
if (this.testEnvironment == "1") {
|
if (testEnvironment == "1") {
|
||||||
baseUrl = baseUrlTest;
|
baseUrl = baseUrlTest;
|
||||||
print("TestEnv $baseUrl");
|
print("TestEnv $baseUrl");
|
||||||
return;
|
return;
|
||||||
|
} else if ( testEnvironment == "2") {
|
||||||
|
baseUrl = baseUrlLocal;
|
||||||
|
print("TestEnv $baseUrl");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
final bool? live = prefs.getBool(Cache.serverKey);
|
final bool? live = prefs.getBool(Cache.serverKey);
|
||||||
if (live == null) {
|
if (live == null) {
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
// ignore: depend_on_referenced_packages
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
class CustomerActivity {
|
class CustomerActivity {
|
||||||
@ -12,19 +13,19 @@ class CustomerActivity {
|
|||||||
customerId = json['custoemrId'];
|
customerId = json['custoemrId'];
|
||||||
type = json['type'];
|
type = json['type'];
|
||||||
skipped = json['skipped'];
|
skipped = json['skipped'];
|
||||||
this.dateAdd = DateTime.parse(json['dateAdd']);
|
dateAdd = DateTime.parse(json['dateAdd']);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, dynamic> toJson() => {
|
Map<String, dynamic> toJson() => {
|
||||||
'activityId': this.activityId,
|
'activityId': activityId,
|
||||||
'customerId': this.customerId,
|
'customerId': customerId,
|
||||||
'type': this.type,
|
'type': type,
|
||||||
'skipped': this.skipped,
|
'skipped': skipped,
|
||||||
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateAdd!),
|
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(dateAdd!),
|
||||||
};
|
};
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return this.toJson().toString();
|
return toJson().toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
// ignore: depend_on_referenced_packages
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
class CustomerExerciseDevice {
|
class CustomerExerciseDevice {
|
||||||
@ -14,11 +15,11 @@ class CustomerExerciseDevice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CustomerExerciseDevice.fromJson(Map json) {
|
CustomerExerciseDevice.fromJson(Map json) {
|
||||||
this.customerExerciseDeviceId = json['customerExerciseDeviceId'];
|
customerExerciseDeviceId = json['customerExerciseDeviceId'];
|
||||||
this.exerciseDeviceId = json['exerciseDeviceId'];
|
exerciseDeviceId = json['exerciseDeviceId'];
|
||||||
this.customerId = json['customerId'];
|
customerId = json['customerId'];
|
||||||
this.favourite = json['favourite'] == 1 ? true : false;
|
favourite = json['favourite'] == 1 ? true : false;
|
||||||
this.dateAdd = DateTime.parse(json['dateAdd']);
|
dateAdd = DateTime.parse(json['dateAdd']);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
@ -27,7 +28,7 @@ class CustomerExerciseDevice {
|
|||||||
"exerciseDeviceId": exerciseDeviceId,
|
"exerciseDeviceId": exerciseDeviceId,
|
||||||
"customerId": customerId,
|
"customerId": customerId,
|
||||||
"favourite": favourite == true ? 1 : 0,
|
"favourite": favourite == true ? 1 : 0,
|
||||||
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateAdd),
|
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(dateAdd),
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
@ -35,7 +36,7 @@ class CustomerExerciseDevice {
|
|||||||
"exerciseDeviceId": exerciseDeviceId,
|
"exerciseDeviceId": exerciseDeviceId,
|
||||||
"customerId": customerId,
|
"customerId": customerId,
|
||||||
"favourite": favourite == true ? 1 : 0,
|
"favourite": favourite == true ? 1 : 0,
|
||||||
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateAdd),
|
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(dateAdd),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
|
// ignore: depend_on_referenced_packages
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
import '../util/logging.dart';
|
||||||
|
|
||||||
class CustomerProperty {
|
class CustomerProperty with Logging {
|
||||||
int? customerPropertyId;
|
int? customerPropertyId;
|
||||||
late int propertyId;
|
late int propertyId;
|
||||||
late int customerId;
|
late int customerId;
|
||||||
@ -18,20 +20,20 @@ class CustomerProperty {
|
|||||||
required this.propertyValue});
|
required this.propertyValue});
|
||||||
|
|
||||||
CustomerProperty.fromJson(Map json) {
|
CustomerProperty.fromJson(Map json) {
|
||||||
this.customerPropertyId = json['customerPropertyId'];
|
customerPropertyId = json['customerPropertyId'];
|
||||||
this.propertyId = json['propertyId'];
|
propertyId = json['propertyId'];
|
||||||
this.customerId = json['customerId'];
|
customerId = json['customerId'];
|
||||||
this.dateAdd = DateTime.parse(json['dateAdd']);
|
dateAdd = DateTime.parse(json['dateAdd']);
|
||||||
|
|
||||||
if (this.dateAdd != null) {
|
if (dateAdd != null) {
|
||||||
dateYmd = DateFormat('yyyy-MM-dd').format(this.dateAdd!);
|
dateYmd = DateFormat('yyyy-MM-dd').format(dateAdd!);
|
||||||
dateYm = DateFormat('yyyy-MM').format(this.dateAdd!);
|
dateYm = DateFormat('yyyy-MM').format(dateAdd!);
|
||||||
dateY = DateFormat('yyyy').format(this.dateAdd!);
|
dateY = DateFormat('yyyy').format(dateAdd!);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.propertyValue = json['propertyValue'];
|
propertyValue = json['propertyValue'];
|
||||||
|
|
||||||
print("Json $json, ${this.toString()}");
|
print("Json $json, ${toString()}");
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
|
@ -4,7 +4,6 @@ import 'package:sentry_flutter/sentry_flutter.dart';
|
|||||||
import 'package:workouttest_util/util/logging.dart';
|
import 'package:workouttest_util/util/logging.dart';
|
||||||
import 'package:workouttest_util/util/common.dart';
|
import 'package:workouttest_util/util/common.dart';
|
||||||
import 'package:workouttest_util/util/not_found_exception.dart';
|
import 'package:workouttest_util/util/not_found_exception.dart';
|
||||||
import 'package:flutter/services.dart';
|
|
||||||
import 'package:workouttest_util/model/cache.dart';
|
import 'package:workouttest_util/model/cache.dart';
|
||||||
|
|
||||||
class APIClient with Common, Logging {
|
class APIClient with Common, Logging {
|
||||||
@ -20,42 +19,40 @@ class APIClient with Common, Logging {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dynamic authenticateUser(String email, String password) async {
|
dynamic authenticateUser(String email, String password) async {
|
||||||
var url = Cache().getBaseUrl() + "authenticate";
|
var baseUrl = Cache().getBaseUrl();
|
||||||
|
log("Base URL: $baseUrl");
|
||||||
|
var url = "${baseUrl}authenticate";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ByteData data = await rootBundle.load('asset/data/aitrainer_server.crt.pem');
|
|
||||||
SecurityContext context = SecurityContext.defaultContext;
|
|
||||||
if (cert == false) {
|
|
||||||
print("Set CERT $cert");
|
|
||||||
context.setTrustedCertificatesBytes(data.buffer.asUint8List(), password: "[xxxx]");
|
|
||||||
cert = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
HttpClient client = new HttpClient(); //context: context Todo provide the right certificate
|
|
||||||
client.badCertificateCallback = ((X509Certificate cert, String host, int port) {
|
|
||||||
print("Host: $host Port: $port");
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
var uri = Uri.parse(url);
|
var uri = Uri.parse(url);
|
||||||
|
HttpClient client = HttpClient();
|
||||||
final HttpClientRequest request = await client.postUrl(uri);
|
final HttpClientRequest request = await client.postUrl(uri);
|
||||||
request.headers.set('Content-Type', 'application/json');
|
request.headers.contentType = ContentType('application', 'json', charset: 'utf-8');
|
||||||
request.headers.set('Authorization', '1');
|
request.headers.set('Authorization', '1');
|
||||||
|
|
||||||
final body = '{"username":"$email", "password":"$password"}';
|
final body = jsonEncode(<String, String>{
|
||||||
|
'username': email,
|
||||||
|
'password': password
|
||||||
|
});
|
||||||
|
|
||||||
request.write(body);
|
request.write(body);
|
||||||
HttpClientResponse result = await request.close();
|
HttpClientResponse result = await request.close();
|
||||||
client.close();
|
client.close();
|
||||||
if (result.statusCode != 200) {
|
if (result.statusCode != 200) {
|
||||||
trace("authentication response: ${result.statusCode} with URL: $url");
|
log("authentication response: ${result.statusCode} with URL: $url");
|
||||||
throw Exception("Authentication error: ${result.statusCode}");
|
throw Exception("Authentication error: ${result.statusCode}");
|
||||||
}
|
}
|
||||||
return jsonDecode(await result.transform(utf8.decoder).join());
|
|
||||||
|
String response = await result.transform(utf8.decoder).join();
|
||||||
|
log("Authentication status: ${result.statusCode}, response: $response");
|
||||||
|
final data = jsonDecode(response);
|
||||||
|
return data;
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
print(exception.toString());
|
log(exception.toString());
|
||||||
try {
|
try {
|
||||||
await Sentry.captureException(exception);
|
await Sentry.captureException(exception);
|
||||||
} on Exception catch (e) {
|
} on Exception catch (e) {
|
||||||
print(e);
|
log(e.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
throw Exception("Network error, try again later!");
|
throw Exception("Network error, try again later!");
|
||||||
@ -67,35 +64,35 @@ class APIClient with Common, Logging {
|
|||||||
trace(" ------------ http/post body $body - url: $url ");
|
trace(" ------------ http/post body $body - url: $url ");
|
||||||
try {
|
try {
|
||||||
String authToken = Cache().getAuthToken();
|
String authToken = Cache().getAuthToken();
|
||||||
if (authToken.length == 0) {
|
if (authToken.isEmpty) {
|
||||||
var responseJson = await this.authenticateUser(Cache.username, Cache.password);
|
var responseJson = await authenticateUser(Cache.username, Cache.password);
|
||||||
authToken = responseJson['token'];
|
authToken = responseJson['token'];
|
||||||
Cache().authToken = authToken;
|
Cache().authToken = authToken;
|
||||||
}
|
}
|
||||||
var uri = Uri.parse(url);
|
var uri = Uri.parse(url);
|
||||||
HttpClient client = new HttpClient();
|
HttpClient client = HttpClient();
|
||||||
|
|
||||||
client.badCertificateCallback = ((X509Certificate cert, String host, int port) => true);
|
client.badCertificateCallback = ((X509Certificate cert, String host, int port) => true);
|
||||||
|
|
||||||
final HttpClientRequest request = await client.postUrl(uri);
|
final HttpClientRequest request = await client.postUrl(uri);
|
||||||
request.headers.contentType = new ContentType("application", "json", charset: "utf-8");
|
request.headers.contentType = ContentType("application", "json", charset: "utf-8");
|
||||||
request.headers.set('Authorization', 'Bearer $authToken');
|
request.headers.set('Authorization', 'Bearer $authToken');
|
||||||
//request.contentLength = body.length;
|
//request.contentLength = body.length;
|
||||||
request.write(body);
|
request.write(body);
|
||||||
HttpClientResponse result = await request.close();
|
HttpClientResponse result = await request.close();
|
||||||
client.close();
|
client.close();
|
||||||
trace(" ------------post response code: " + result.statusCode.toString());
|
trace(" ------------post response code: ${result.statusCode}");
|
||||||
if (result.statusCode == 200) {
|
if (result.statusCode == 200) {
|
||||||
return await result.transform(utf8.decoder).join();
|
return await result.transform(utf8.decoder).join();
|
||||||
} else if (result.statusCode == 404) {
|
} else if (result.statusCode == 404) {
|
||||||
throw NotFoundException(message: "Not Found");
|
throw const NotFoundException(message: "Not Found");
|
||||||
} else {
|
} else {
|
||||||
throw Exception("Network Error, please try again later");
|
throw Exception("Network Error, please try again later");
|
||||||
}
|
}
|
||||||
} on NotFoundException catch(e) {
|
} on NotFoundException catch(e) {
|
||||||
throw NotFoundException(message: "Not Found");
|
throw NotFoundException(message: "Not Found ${e.message}");
|
||||||
} on Exception catch (e) {
|
} on Exception catch (e) {
|
||||||
print("Post Exception: $e");
|
log("Post Exception: $e");
|
||||||
await Sentry.captureException(e);
|
await Sentry.captureException(e);
|
||||||
throw Exception("Network Error, please try again later");
|
throw Exception("Network Error, please try again later");
|
||||||
}
|
}
|
||||||
@ -104,36 +101,35 @@ class APIClient with Common, Logging {
|
|||||||
Future<String> get(String endPoint, String param) async {
|
Future<String> get(String endPoint, String param) async {
|
||||||
final url = Cache().getBaseUrl() + endPoint + param;
|
final url = Cache().getBaseUrl() + endPoint + param;
|
||||||
try {
|
try {
|
||||||
trace("-------- API get " + url);
|
trace("-------- API get $url");
|
||||||
String authToken = Cache().getAuthToken();
|
String authToken = Cache().getAuthToken();
|
||||||
if (authToken.length == 0) {
|
if (authToken.isEmpty) {
|
||||||
var responseJson = await this.authenticateUser(Cache.username, Cache.password);
|
var responseJson = await authenticateUser(Cache.username, Cache.password);
|
||||||
authToken = responseJson['token'];
|
authToken = responseJson['token'];
|
||||||
Cache().authToken = authToken;
|
Cache().authToken = authToken;
|
||||||
}
|
}
|
||||||
var uri = Uri.parse(url);
|
var uri = Uri.parse(url);
|
||||||
|
|
||||||
HttpClient client = new HttpClient();
|
HttpClient client = HttpClient();
|
||||||
|
|
||||||
client.badCertificateCallback = ((X509Certificate cert, String host, int port) => true);
|
|
||||||
|
|
||||||
final HttpClientRequest request = await client.getUrl(uri);
|
final HttpClientRequest request = await client.getUrl(uri);
|
||||||
request.headers.set('Content-Type', 'application/json');
|
request.headers.contentType = ContentType("application", "json", charset: "utf-8");
|
||||||
request.headers.set('Authorization', 'Bearer $authToken');
|
request.headers.set('Authorization', 'Bearer $authToken');
|
||||||
|
request.write("");
|
||||||
HttpClientResponse result = await request.close();
|
HttpClientResponse result = await request.close();
|
||||||
client.close();
|
client.close();
|
||||||
trace(" ------------get response code: " + result.statusCode.toString());
|
trace(" ------------get response code: ${result.statusCode}");
|
||||||
if (result.statusCode == 200) {
|
if (result.statusCode == 200) {
|
||||||
return await result.transform(utf8.decoder).join();
|
return await result.transform(utf8.decoder).join();
|
||||||
} else if (result.statusCode == 404) {
|
} else if (result.statusCode == 404) {
|
||||||
throw NotFoundException(message: "Not Found");
|
throw const NotFoundException(message: "Not Found");
|
||||||
} else {
|
} else {
|
||||||
throw Exception("Network Error, please try again later");
|
throw Exception("Network Error, please try again later");
|
||||||
}
|
}
|
||||||
} on NotFoundException catch(e) {
|
} on NotFoundException catch(e) {
|
||||||
throw NotFoundException(message: "Not Found");
|
throw NotFoundException(message: "Not Found ${e.message}");
|
||||||
} on Exception catch (e) {
|
} on Exception catch (e) {
|
||||||
print("Post Exception: $e");
|
log("Post Exception: $e");
|
||||||
await Sentry.captureException(e);
|
await Sentry.captureException(e);
|
||||||
throw Exception("Network Error, please try again later");
|
throw Exception("Network Error, please try again later");
|
||||||
}
|
}
|
||||||
|
@ -22,14 +22,14 @@ class CustomerApi with Logging {
|
|||||||
|
|
||||||
Future<void> saveCustomer(Customer customer) async {
|
Future<void> saveCustomer(Customer customer) async {
|
||||||
customer.dateChange = DateTime.now();
|
customer.dateChange = DateTime.now();
|
||||||
String body = JsonEncoder().convert(customer.toJson());
|
String body = const JsonEncoder().convert(customer.toJson());
|
||||||
log(" ===== saving customer id: " + customer.customerId.toString() + ":" + body);
|
log(" ===== saving customer id: ${customer.customerId}:$body");
|
||||||
await _client.post("customers/" + customer.customerId.toString(), body);
|
await _client.post("customers/${customer.customerId}", body);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> updateFirebaseUid(int customerId, String uid) async {
|
Future<void> updateFirebaseUid(int customerId, String uid) async {
|
||||||
log(" ===== update Firebase uid : " + customerId.toString() + ": " + uid);
|
log(" ===== update Firebase uid : $customerId: $uid");
|
||||||
await _client.post("customers/update_firebase_uid/" + customerId.toString(), uid);
|
await _client.post("customers/update_firebase_uid/$customerId", uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> deactivateCustomer(int customerId) async {
|
Future<void> deactivateCustomer(int customerId) async {
|
||||||
@ -40,21 +40,21 @@ class CustomerApi with Logging {
|
|||||||
Future<void> addCustomer(Customer customer) async {
|
Future<void> addCustomer(Customer customer) async {
|
||||||
customer.dateAdd = DateTime.now();
|
customer.dateAdd = DateTime.now();
|
||||||
customer.dateChange = DateTime.now();
|
customer.dateChange = DateTime.now();
|
||||||
String body = JsonEncoder().convert(customer.toJson());
|
String body = const JsonEncoder().convert(customer.toJson());
|
||||||
log(" ===== add new customer: " + body);
|
log(" ===== add new customer: $body");
|
||||||
await _client.post("customers", body);
|
await _client.post("customers", body);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> addUser(User user) async {
|
Future<void> addUser(User user) async {
|
||||||
String body = JsonEncoder().convert(user.toJson());
|
String body = const JsonEncoder().convert(user.toJson());
|
||||||
log(" ===== add new user: " + body);
|
log(" ===== add new user: $body");
|
||||||
final String responseBody = await _client.post("registration", body);
|
final String responseBody = await _client.post("registration", body);
|
||||||
Customer customer;
|
Customer customer;
|
||||||
try {
|
try {
|
||||||
int? status = jsonDecode(responseBody)['status'];
|
int? status = jsonDecode(responseBody)['status'];
|
||||||
if (status != null) {
|
if (status != null) {
|
||||||
String error = jsonDecode(responseBody)['error'];
|
String error = jsonDecode(responseBody)['error'];
|
||||||
throw new Exception(error);
|
throw Exception(error);
|
||||||
} else {
|
} else {
|
||||||
customer = Customer.fromJson(jsonDecode(responseBody));
|
customer = Customer.fromJson(jsonDecode(responseBody));
|
||||||
await Cache().afterRegistration(customer);
|
await Cache().afterRegistration(customer);
|
||||||
@ -63,58 +63,58 @@ class CustomerApi with Logging {
|
|||||||
if (responseBody == "Customer exists") {
|
if (responseBody == "Customer exists") {
|
||||||
throw WorkoutTestException(code: WorkoutTestException.CUSTOMER_EXISTS, message: responseBody);
|
throw WorkoutTestException(code: WorkoutTestException.CUSTOMER_EXISTS, message: responseBody);
|
||||||
}
|
}
|
||||||
throw new Exception(responseBody);
|
throw Exception(responseBody);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> getUser(User user) async {
|
Future<void> getUser(User user) async {
|
||||||
String body = JsonEncoder().convert(user.toJson());
|
String body = const JsonEncoder().convert(user.toJson());
|
||||||
log(" ===== login the user: " + body);
|
log(" ===== login the user: $body");
|
||||||
final String responseBody = await _client.post("login", body);
|
final String responseBody = await _client.post("login", body);
|
||||||
Customer customer;
|
Customer customer;
|
||||||
try {
|
try {
|
||||||
customer = Customer.fromJson(jsonDecode(responseBody));
|
customer = Customer.fromJson(jsonDecode(responseBody));
|
||||||
await Cache().afterLogin(customer);
|
await Cache().afterLogin(customer);
|
||||||
} on FormatException {
|
} on FormatException {
|
||||||
throw new Exception(responseBody);
|
throw Exception(responseBody);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> getUserByEmail(String email) async {
|
Future<void> getUserByEmail(String email) async {
|
||||||
log(" ===== User getByEmail : " + email);
|
log(" ===== User getByEmail : $email");
|
||||||
final String responseBody = await _client.get("customers/find_by_email/" + email, "");
|
final String responseBody = await _client.get("customers/find_by_email/$email", "");
|
||||||
Customer customer;
|
Customer customer;
|
||||||
try {
|
try {
|
||||||
customer = Customer.fromJson(jsonDecode(responseBody));
|
customer = Customer.fromJson(jsonDecode(responseBody));
|
||||||
if (customer.firebaseUid == null) {
|
if (customer.firebaseUid == null) {
|
||||||
await this.updateFirebaseUid(customer.customerId!, Cache().firebaseUid!);
|
await updateFirebaseUid(customer.customerId!, Cache().firebaseUid!);
|
||||||
}
|
}
|
||||||
Cache().userLoggedIn = customer;
|
Cache().userLoggedIn = customer;
|
||||||
final List<CustomerProperty>? properties = await this.getActualProperties(customer.customerId!);
|
final List<CustomerProperty>? properties = await getActualProperties(customer.customerId!);
|
||||||
if (properties != null) {
|
if (properties != null) {
|
||||||
this.initProperties(properties);
|
initProperties(properties);
|
||||||
}
|
}
|
||||||
} on FormatException {
|
} on FormatException {
|
||||||
throw new Exception(responseBody);
|
throw Exception(responseBody);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> getCustomer(int customerId) async {
|
Future<void> getCustomer(int customerId) async {
|
||||||
String body = "";
|
String body = "";
|
||||||
log(" ===== get the customer by id: " + customerId.toString());
|
log(" ===== get the customer by id: $customerId");
|
||||||
try {
|
try {
|
||||||
final String responseBody = await _client.get("customers/" + customerId.toString(), body);
|
final String responseBody = await _client.get("customers/$customerId", body);
|
||||||
Customer customer = Customer.fromJson(jsonDecode(responseBody));
|
Customer customer = Customer.fromJson(jsonDecode(responseBody));
|
||||||
log(" --- Customer: " + customer.toJson().toString());
|
log(" --- Customer: ${customer.toJson()}");
|
||||||
Cache().userLoggedIn = customer;
|
Cache().userLoggedIn = customer;
|
||||||
final List<CustomerProperty>? properties = await this.getActualProperties(customerId);
|
final List<CustomerProperty>? properties = await getActualProperties(customerId);
|
||||||
//log(" ---- Props: " + properties.toJson().toString());
|
//log(" ---- Props: " + properties.toJson().toString());
|
||||||
//await Cache().initCustomer(customerId);
|
//await Cache().initCustomer(customerId);
|
||||||
if (properties != null) {
|
if (properties != null) {
|
||||||
this.initProperties(properties);
|
initProperties(properties);
|
||||||
}
|
}
|
||||||
} on Exception catch (exception) {
|
} on Exception catch (exception) {
|
||||||
log("Exception: " + exception.toString());
|
log("Exception: $exception");
|
||||||
log(" === go to registration ");
|
log(" === go to registration ");
|
||||||
Cache().logout();
|
Cache().logout();
|
||||||
Cache().startPage = "registration";
|
Cache().startPage = "registration";
|
||||||
|
@ -8,7 +8,7 @@ class ExerciseDeviceApi {
|
|||||||
final APIClient _client = APIClient();
|
final APIClient _client = APIClient();
|
||||||
|
|
||||||
Future<List<ExerciseDevice>> getDevices() async {
|
Future<List<ExerciseDevice>> getDevices() async {
|
||||||
final body = await _client.get("exercise_device/", "");
|
final body = await _client.get("exercise_device", "");
|
||||||
final Iterable json = jsonDecode(body);
|
final Iterable json = jsonDecode(body);
|
||||||
final List<ExerciseDevice> devices = json.map((device) => ExerciseDevice.fromJson(device)).toList();
|
final List<ExerciseDevice> devices = json.map((device) => ExerciseDevice.fromJson(device)).toList();
|
||||||
Cache().setDevices(devices);
|
Cache().setDevices(devices);
|
||||||
|
@ -14,7 +14,7 @@ class ExerciseTypeApi with Logging {
|
|||||||
final List<ExerciseType> exerciseTypes = json.map((exerciseType) => ExerciseType.fromJson(exerciseType)).toList();
|
final List<ExerciseType> exerciseTypes = json.map((exerciseType) => ExerciseType.fromJson(exerciseType)).toList();
|
||||||
|
|
||||||
await Future.forEach(exerciseTypes, (element) async {
|
await Future.forEach(exerciseTypes, (element) async {
|
||||||
ExerciseType exerciseType = element as ExerciseType;
|
ExerciseType exerciseType = element;
|
||||||
exerciseType.imageUrl = await buildImage(exerciseType.imageUrl, exerciseType.exerciseTypeId);
|
exerciseType.imageUrl = await buildImage(exerciseType.imageUrl, exerciseType.exerciseTypeId);
|
||||||
});
|
});
|
||||||
log("ExerciseTypes downloaded");
|
log("ExerciseTypes downloaded");
|
||||||
@ -25,12 +25,12 @@ class ExerciseTypeApi with Logging {
|
|||||||
|
|
||||||
Future<String> buildImage(String imageUrl, int exerciseTypeId) async {
|
Future<String> buildImage(String imageUrl, int exerciseTypeId) async {
|
||||||
if (imageUrl.length > 8) {
|
if (imageUrl.length > 8) {
|
||||||
String assetImage = 'asset/menu/' + imageUrl.substring(7);
|
String assetImage = 'asset/menu/${imageUrl.substring(7)}';
|
||||||
return rootBundle.load(assetImage).then((value) {
|
return rootBundle.load(assetImage).then((value) {
|
||||||
return assetImage;
|
return assetImage;
|
||||||
}).catchError((_) {
|
}).catchError((_) {
|
||||||
String imagePath = assetImage.substring(10);
|
String imagePath = assetImage.substring(10);
|
||||||
String url = Cache.mediaUrl + 'images' + imagePath;
|
String url = '${Cache.mediaUrl}images$imagePath';
|
||||||
return url;
|
return url;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
@ -117,7 +117,7 @@ class FirebaseApi with logger.Logging {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String generateNonce([int length = 32]) {
|
String generateNonce([int length = 32]) {
|
||||||
final charset = '0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-._';
|
const charset = '0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-._';
|
||||||
final random = math.Random.secure();
|
final random = math.Random.secure();
|
||||||
return List.generate(length, (_) => charset[random.nextInt(charset.length)]).join();
|
return List.generate(length, (_) => charset[random.nextInt(charset.length)]).join();
|
||||||
}
|
}
|
||||||
@ -130,7 +130,7 @@ class FirebaseApi with logger.Logging {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<Map<String, dynamic>> signInWithApple() async {
|
Future<Map<String, dynamic>> signInWithApple() async {
|
||||||
Map<String, dynamic> userData = Map();
|
Map<String, dynamic> userData = {};
|
||||||
|
|
||||||
// To prevent replay attacks with the credential returned from Apple, we
|
// To prevent replay attacks with the credential returned from Apple, we
|
||||||
// include a nonce in the credential request. When signing in with
|
// include a nonce in the credential request. When signing in with
|
||||||
@ -163,7 +163,7 @@ class FirebaseApi with logger.Logging {
|
|||||||
throw Exception(e);
|
throw Exception(e);
|
||||||
}
|
}
|
||||||
Cache().firebaseUid = userCredential.user!.uid;
|
Cache().firebaseUid = userCredential.user!.uid;
|
||||||
log("userCredential: " + userCredential.toString());
|
log("userCredential: $userCredential");
|
||||||
|
|
||||||
log("Apple Credentials: ${appleCredential.userIdentifier} state ${appleCredential.state} email ${userCredential.user!.email!}");
|
log("Apple Credentials: ${appleCredential.userIdentifier} state ${appleCredential.state} email ${userCredential.user!.email!}");
|
||||||
userData['email'] = userCredential.user!.email;
|
userData['email'] = userCredential.user!.email;
|
||||||
@ -212,16 +212,16 @@ class FirebaseApi with logger.Logging {
|
|||||||
Map<String, dynamic> userData = Map();
|
Map<String, dynamic> userData = Map();
|
||||||
|
|
||||||
// Trigger the authentication flow
|
// Trigger the authentication flow
|
||||||
GoogleSignIn _googleSignIn = GoogleSignIn(
|
GoogleSignIn googleSignIn = GoogleSignIn(
|
||||||
scopes: [
|
scopes: [
|
||||||
'email',
|
'email',
|
||||||
'https://www.googleapis.com/auth/contacts.readonly',
|
'https://www.googleapis.com/auth/contacts.readonly',
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
final GoogleSignInAccount? googleUser = await _googleSignIn.signIn();
|
final GoogleSignInAccount? googleUser = await googleSignIn.signIn();
|
||||||
|
|
||||||
if (googleUser == null) {
|
if (googleUser == null) {
|
||||||
Sentry.captureException(new Exception("Google Sign In failed"));
|
Sentry.captureException(Exception("Google Sign In failed"));
|
||||||
throw Exception("Google Sign In failed");
|
throw Exception("Google Sign In failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -237,7 +237,7 @@ class FirebaseApi with logger.Logging {
|
|||||||
UserCredential userCredential = await FirebaseAuth.instance.signInWithCredential(credential);
|
UserCredential userCredential = await FirebaseAuth.instance.signInWithCredential(credential);
|
||||||
Cache().firebaseUid = userCredential.user!.uid;
|
Cache().firebaseUid = userCredential.user!.uid;
|
||||||
|
|
||||||
log("GoogleUser: " + googleUser.toString());
|
log("GoogleUser: $googleUser");
|
||||||
userData['email'] = googleUser.email;
|
userData['email'] = googleUser.email;
|
||||||
userData['id'] = googleUser.id;
|
userData['id'] = googleUser.id;
|
||||||
userData['name'] = googleUser.displayName;
|
userData['name'] = googleUser.displayName;
|
||||||
@ -249,16 +249,16 @@ class FirebaseApi with logger.Logging {
|
|||||||
Map<String, dynamic> userData = Map();
|
Map<String, dynamic> userData = Map();
|
||||||
|
|
||||||
// Trigger the authentication flow
|
// Trigger the authentication flow
|
||||||
GoogleSignIn _googleSignIn = GoogleSignIn(
|
GoogleSignIn googleSignIn = GoogleSignIn(
|
||||||
scopes: [
|
scopes: [
|
||||||
'email',
|
'email',
|
||||||
'https://www.googleapis.com/auth/contacts.readonly',
|
'https://www.googleapis.com/auth/contacts.readonly',
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
final GoogleSignInAccount? googleUser = await _googleSignIn.signIn();
|
final GoogleSignInAccount? googleUser = await googleSignIn.signIn();
|
||||||
|
|
||||||
if (googleUser == null) {
|
if (googleUser == null) {
|
||||||
Sentry.captureException(new Exception("Google Sign In failed"));
|
Sentry.captureException(Exception("Google Sign In failed"));
|
||||||
throw Exception("Google Sign In failed");
|
throw Exception("Google Sign In failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,7 +273,7 @@ class FirebaseApi with logger.Logging {
|
|||||||
|
|
||||||
final userCredential = await FirebaseAuth.instance.signInWithCredential(credential);
|
final userCredential = await FirebaseAuth.instance.signInWithCredential(credential);
|
||||||
|
|
||||||
log("Google credentials: " + credential.toString() + " GoogleUser: " + googleUser.toString());
|
log("Google credentials: $credential GoogleUser: $googleUser");
|
||||||
Cache().firebaseUid = userCredential.user!.uid;
|
Cache().firebaseUid = userCredential.user!.uid;
|
||||||
|
|
||||||
userData['email'] = googleUser.email;
|
userData['email'] = googleUser.email;
|
||||||
@ -295,7 +295,7 @@ class FirebaseApi with logger.Logging {
|
|||||||
Cache().firebaseUid = userData['id'];
|
Cache().firebaseUid = userData['id'];
|
||||||
log(userData.toString());
|
log(userData.toString());
|
||||||
} else {
|
} else {
|
||||||
Sentry.captureException(new Exception(result.message));
|
Sentry.captureException(Exception(result.message));
|
||||||
throw Exception("Facebook login was not successful");
|
throw Exception("Facebook login was not successful");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,7 +312,7 @@ class FirebaseApi with logger.Logging {
|
|||||||
Cache().accessTokenFacebook = accessToken;
|
Cache().accessTokenFacebook = accessToken;
|
||||||
// get the user data
|
// get the user data
|
||||||
userData = await FacebookAuth.instance.getUserData();
|
userData = await FacebookAuth.instance.getUserData();
|
||||||
log("FB user data: " + userData.toString());
|
log("FB user data: $userData");
|
||||||
|
|
||||||
// Create a credential from the access token
|
// Create a credential from the access token
|
||||||
final OAuthCredential facebookAuthCredential = FacebookAuthProvider.credential(accessToken.token);
|
final OAuthCredential facebookAuthCredential = FacebookAuthProvider.credential(accessToken.token);
|
||||||
@ -323,7 +323,7 @@ class FirebaseApi with logger.Logging {
|
|||||||
|
|
||||||
Cache().firebaseUid = userCredential.user!.uid;
|
Cache().firebaseUid = userCredential.user!.uid;
|
||||||
} else {
|
} else {
|
||||||
Sentry.captureException(new Exception(result.message));
|
Sentry.captureException(Exception(result.message));
|
||||||
throw Exception("Facebook login was not successful");
|
throw Exception("Facebook login was not successful");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -356,7 +356,7 @@ class FirebaseApi with logger.Logging {
|
|||||||
//RemoteConfigValue(null, ValueSource.valueStatic);
|
//RemoteConfigValue(null, ValueSource.valueStatic);
|
||||||
//Cache().setRemoteConfig(remoteConfig);
|
//Cache().setRemoteConfig(remoteConfig);
|
||||||
} on Exception catch (e) {
|
} on Exception catch (e) {
|
||||||
print('Unable to fetch remote config. Cached or default values will be used: $e');
|
log('Unable to fetch remote config. Cached or default values will be used: $e');
|
||||||
if (remoteConfig != null) {
|
if (remoteConfig != null) {
|
||||||
await remoteConfig.setDefaults(<String, dynamic>{
|
await remoteConfig.setDefaults(<String, dynamic>{
|
||||||
'sales_page_text_a': '',
|
'sales_page_text_a': '',
|
||||||
@ -375,29 +375,3 @@ Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
|
|||||||
// make sure you call `initializeApp` before using other Firebase services.
|
// make sure you call `initializeApp` before using other Firebase services.
|
||||||
print('Handling a background message ${message.messageId}');
|
print('Handling a background message ${message.messageId}');
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
|
|
||||||
print('Handling a background message: ${message.messageId}');
|
|
||||||
|
|
||||||
if (!StringUtils.isNullOrEmpty(message.notification?.title, considerWhiteSpaceAsEmpty: true) ||
|
|
||||||
!StringUtils.isNullOrEmpty(message.notification?.body, considerWhiteSpaceAsEmpty: true)) {
|
|
||||||
print('message also contained a notification: ${message.notification}');
|
|
||||||
|
|
||||||
String? imageUrl;
|
|
||||||
imageUrl ??= message.notification!.android?.imageUrl;
|
|
||||||
imageUrl ??= message.notification!.apple?.imageUrl;
|
|
||||||
|
|
||||||
Map<String, dynamic> notificationAdapter = {
|
|
||||||
NOTIFICATION_CHANNEL_KEY: 'basic_channel',
|
|
||||||
NOTIFICATION_ID: message.data[NOTIFICATION_CONTENT]?[NOTIFICATION_ID] ?? message.messageId ?? math.Random().nextInt(2147483647),
|
|
||||||
NOTIFICATION_TITLE: message.data[NOTIFICATION_CONTENT]?[NOTIFICATION_TITLE] ?? message.notification?.title,
|
|
||||||
NOTIFICATION_BODY: message.data[NOTIFICATION_CONTENT]?[NOTIFICATION_BODY] ?? message.notification?.body,
|
|
||||||
NOTIFICATION_LAYOUT: StringUtils.isNullOrEmpty(imageUrl) ? 'Default' : 'BigPicture',
|
|
||||||
NOTIFICATION_BIG_PICTURE: imageUrl
|
|
||||||
};
|
|
||||||
|
|
||||||
AwesomeNotifications().createNotificationFromJsonData(notificationAdapter);
|
|
||||||
} else {
|
|
||||||
AwesomeNotifications().createNotificationFromJsonData(message.data);
|
|
||||||
}
|
|
||||||
} */
|
|
||||||
|
@ -36,11 +36,11 @@ class PackageApi {
|
|||||||
Future<void> getPackage() async {
|
Future<void> getPackage() async {
|
||||||
late List<ExerciseTree> exerciseTree;
|
late List<ExerciseTree> exerciseTree;
|
||||||
late List<ExerciseTreeParents> exerciseTreeParents;
|
late List<ExerciseTreeParents> exerciseTreeParents;
|
||||||
final body = await _client.get("app_package/", "");
|
final body = await _client.get("app_package", "");
|
||||||
|
|
||||||
final List<String> models = body.split("|||");
|
final List<String> models = body.split("|||");
|
||||||
await Future.forEach(models, (elem) async {
|
await Future.forEach(models, (elem) async {
|
||||||
final String element = elem as String;
|
final String element = elem;
|
||||||
final List<String> headRecord = element.split("***");
|
final List<String> headRecord = element.split("***");
|
||||||
final Iterable json = jsonDecode(headRecord[1]);
|
final Iterable json = jsonDecode(headRecord[1]);
|
||||||
if (headRecord[0] == "ExerciseDevice") {
|
if (headRecord[0] == "ExerciseDevice") {
|
||||||
@ -57,7 +57,7 @@ class PackageApi {
|
|||||||
} else if (headRecord[0] == "ExerciseType") {
|
} else if (headRecord[0] == "ExerciseType") {
|
||||||
final List<ExerciseType> exerciseTypes = json.map((exerciseType) => ExerciseType.fromJson(exerciseType)).toList();
|
final List<ExerciseType> exerciseTypes = json.map((exerciseType) => ExerciseType.fromJson(exerciseType)).toList();
|
||||||
await Future.forEach(exerciseTypes, (elem) async {
|
await Future.forEach(exerciseTypes, (elem) async {
|
||||||
final ExerciseType exerciseType = elem as ExerciseType;
|
final ExerciseType exerciseType = elem;
|
||||||
exerciseType.imageUrl = await ExerciseTypeApi().buildImage(exerciseType.imageUrl, exerciseType.exerciseTypeId);
|
exerciseType.imageUrl = await ExerciseTypeApi().buildImage(exerciseType.imageUrl, exerciseType.exerciseTypeId);
|
||||||
});
|
});
|
||||||
Cache().setExerciseTypes(exerciseTypes);
|
Cache().setExerciseTypes(exerciseTypes);
|
||||||
@ -81,48 +81,48 @@ class PackageApi {
|
|||||||
Cache().setTutorials(tutorials);
|
Cache().setTutorials(tutorials);
|
||||||
} else if (headRecord[0] == "Description") {
|
} else if (headRecord[0] == "Description") {
|
||||||
final Iterable json = jsonDecode(headRecord[1]);
|
final Iterable json = jsonDecode(headRecord[1]);
|
||||||
final List<Description>? descriptions = json.map((description) => Description.fromJson(description)).toList();
|
final List<Description> descriptions = json.map((description) => Description.fromJson(description)).toList();
|
||||||
//print("Description: $descriptions");
|
//print("Description: $descriptions");
|
||||||
Cache().setDescriptions(descriptions);
|
Cache().setDescriptions(descriptions);
|
||||||
} else if (headRecord[0] == "Faq") {
|
} else if (headRecord[0] == "Faq") {
|
||||||
final Iterable json = jsonDecode(headRecord[1]);
|
final Iterable json = jsonDecode(headRecord[1]);
|
||||||
final List<Faq>? faqs = json.map((faq) => Faq.fromJson(faq)).toList();
|
final List<Faq> faqs = json.map((faq) => Faq.fromJson(faq)).toList();
|
||||||
//print("Faq: $faqs");
|
//print("Faq: $faqs");
|
||||||
Cache().setFaqs(faqs);
|
Cache().setFaqs(faqs);
|
||||||
} else if (headRecord[0] == "TrainingPlan") {
|
} else if (headRecord[0] == "TrainingPlan") {
|
||||||
final Iterable json = jsonDecode(headRecord[1]);
|
final Iterable json = jsonDecode(headRecord[1]);
|
||||||
final List<TrainingPlan>? plans = json.map((plan) => TrainingPlan.fromJson(plan)).toList();
|
final List<TrainingPlan> plans = json.map((plan) => TrainingPlan.fromJson(plan)).toList();
|
||||||
|
|
||||||
List<TrainingPlan> activePlans = [];
|
List<TrainingPlan> activePlans = [];
|
||||||
if (plans != null) {
|
|
||||||
plans.forEach((element) {
|
for (var element in plans) {
|
||||||
if (element.active) {
|
if (element.active) {
|
||||||
activePlans.add(element);
|
activePlans.add(element);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Cache().setTrainingPlans(activePlans);
|
Cache().setTrainingPlans(activePlans);
|
||||||
} else if (headRecord[0] == "SplitTests") {
|
} else if (headRecord[0] == "SplitTests") {
|
||||||
final Iterable json = jsonDecode(headRecord[1]);
|
final Iterable json = jsonDecode(headRecord[1]);
|
||||||
final List<SplitTest>? tests = json.map((test) => SplitTest.fromJson(test)).toList();
|
final List<SplitTest> tests = json.map((test) => SplitTest.fromJson(test)).toList();
|
||||||
//print("A/B tests: $tests");
|
//print("A/B tests: $tests");
|
||||||
Cache().setSplitTests(tests);
|
Cache().setSplitTests(tests);
|
||||||
} else if (headRecord[0] == "TrainingPlanDay") {
|
} else if (headRecord[0] == "TrainingPlanDay") {
|
||||||
final Iterable json = jsonDecode(headRecord[1]);
|
final Iterable json = jsonDecode(headRecord[1]);
|
||||||
final List<TrainingPlanDay>? days = json.map((day) => TrainingPlanDay.fromJson(day)).toList();
|
final List<TrainingPlanDay> days = json.map((day) => TrainingPlanDay.fromJson(day)).toList();
|
||||||
Cache().setTrainingPlanDays(days);
|
Cache().setTrainingPlanDays(days);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
exerciseTree = this.getExerciseTreeParents(exerciseTree, exerciseTreeParents);
|
exerciseTree = getExerciseTreeParents(exerciseTree, exerciseTreeParents);
|
||||||
|
|
||||||
await Future.forEach(exerciseTree, (element) async {
|
await Future.forEach(exerciseTree, (element) async {
|
||||||
ExerciseTree tree = element as ExerciseTree;
|
ExerciseTree tree = element;
|
||||||
tree.imageUrl = await ExerciseTreeApi().buildImage(tree.imageUrl, tree.treeId);
|
tree.imageUrl = await ExerciseTreeApi().buildImage(tree.imageUrl, tree.treeId);
|
||||||
});
|
});
|
||||||
Cache().setExerciseTree(exerciseTree);
|
Cache().setExerciseTree(exerciseTree);
|
||||||
|
|
||||||
TrainingPlanDayRepository trainingPlanDayRepository = TrainingPlanDayRepository();
|
TrainingPlanDayRepository trainingPlanDayRepository = const TrainingPlanDayRepository();
|
||||||
trainingPlanDayRepository.assignTrainingPlanDays();
|
trainingPlanDayRepository.assignTrainingPlanDays();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -158,11 +158,11 @@ class PackageApi {
|
|||||||
|
|
||||||
Future<void> getCustomerPackage(int customerId) async {
|
Future<void> getCustomerPackage(int customerId) async {
|
||||||
try {
|
try {
|
||||||
final body = await _client.get("app_customer_package/" + customerId.toString(), "");
|
final body = await _client.get("app_customer_package/$customerId", "");
|
||||||
|
|
||||||
final List<String> models = body.split("|||");
|
final List<String> models = body.split("|||");
|
||||||
await Future.forEach(models, (elem) async {
|
await Future.forEach(models, (elem) async {
|
||||||
final String element = elem as String;
|
final String element = elem;
|
||||||
final List<String> headRecord = element.split("***");
|
final List<String> headRecord = element.split("***");
|
||||||
//print("Class " + headRecord[0]);
|
//print("Class " + headRecord[0]);
|
||||||
if (headRecord[0] == "Customer") {
|
if (headRecord[0] == "Customer") {
|
||||||
|
@ -8,7 +8,7 @@ class ProductApi {
|
|||||||
final APIClient _client = APIClient();
|
final APIClient _client = APIClient();
|
||||||
|
|
||||||
Future<List<Product>> getProducts() async {
|
Future<List<Product>> getProducts() async {
|
||||||
final body = await _client.get("product/", "");
|
final body = await _client.get("product", "");
|
||||||
final Iterable json = jsonDecode(body);
|
final Iterable json = jsonDecode(body);
|
||||||
final List<Product> products = json.map((product) => Product.fromJson(product)).toList();
|
final List<Product> products = json.map((product) => Product.fromJson(product)).toList();
|
||||||
Cache().setProducts(products);
|
Cache().setProducts(products);
|
||||||
|
@ -2,14 +2,13 @@ import 'dart:convert';
|
|||||||
|
|
||||||
import 'package:workouttest_util/model/cache.dart';
|
import 'package:workouttest_util/model/cache.dart';
|
||||||
import 'package:workouttest_util/service/api.dart';
|
import 'package:workouttest_util/service/api.dart';
|
||||||
|
|
||||||
import 'package:workouttest_util/model/property.dart';
|
import 'package:workouttest_util/model/property.dart';
|
||||||
|
|
||||||
class PropertyApi {
|
class PropertyApi {
|
||||||
final APIClient _client = APIClient();
|
final APIClient _client = APIClient();
|
||||||
|
|
||||||
Future<List<Property>> getProperties() async {
|
Future<List<Property>> getProperties() async {
|
||||||
final body = await _client.get("property/", "");
|
final body = await _client.get("property", "");
|
||||||
final Iterable json = jsonDecode(body);
|
final Iterable json = jsonDecode(body);
|
||||||
final List<Property> properties = json.map((property) => Property.fromJson(property)).toList();
|
final List<Property> properties = json.map((property) => Property.fromJson(property)).toList();
|
||||||
Cache().setProperties(properties);
|
Cache().setProperties(properties);
|
||||||
|
@ -11,7 +11,7 @@ class PurchaseApi with Logging {
|
|||||||
Future<List<Purchase>> getPurchasesByCustomer(int customerId) async {
|
Future<List<Purchase>> getPurchasesByCustomer(int customerId) async {
|
||||||
List<Purchase> purchases = [];
|
List<Purchase> purchases = [];
|
||||||
try {
|
try {
|
||||||
final body = await _client.get("purchase/customer/" + customerId.toString(), "");
|
final body = await _client.get("purchase/customer/$customerId", "");
|
||||||
final Iterable json = jsonDecode(body);
|
final Iterable json = jsonDecode(body);
|
||||||
final List<Purchase> purchases = json.map((purchase) => Purchase.fromJson(purchase)).toList();
|
final List<Purchase> purchases = json.map((purchase) => Purchase.fromJson(purchase)).toList();
|
||||||
Cache().setPurchases(purchases);
|
Cache().setPurchases(purchases);
|
||||||
@ -23,7 +23,7 @@ class PurchaseApi with Logging {
|
|||||||
|
|
||||||
Future<void> savePurchase(Purchase purchase) async {
|
Future<void> savePurchase(Purchase purchase) async {
|
||||||
String body = JsonEncoder().convert(purchase.toJson());
|
String body = JsonEncoder().convert(purchase.toJson());
|
||||||
log(" ===== saving purchase:" + body);
|
log(" ===== saving purchase:$body");
|
||||||
await _client.post("purchase/", body);
|
await _client.post("purchase", body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ class TrackingApi with Logging {
|
|||||||
try {
|
try {
|
||||||
String body = const JsonEncoder().convert(tracking.toJson());
|
String body = const JsonEncoder().convert(tracking.toJson());
|
||||||
log(" ===== saving tracking: $body");
|
log(" ===== saving tracking: $body");
|
||||||
await _client.post("tracking/", body);
|
await _client.post("tracking", body);
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
log("exception in tracking: ${exception.toString()}");
|
log("exception in tracking: ${exception.toString()}");
|
||||||
}
|
}
|
||||||
|
@ -9,24 +9,24 @@ class TrainingPlanApi with Logging {
|
|||||||
final APIClient _client = APIClient();
|
final APIClient _client = APIClient();
|
||||||
|
|
||||||
Future<CustomerTrainingPlan> saveCustomerTrainingPlan(CustomerTrainingPlan plan) async {
|
Future<CustomerTrainingPlan> saveCustomerTrainingPlan(CustomerTrainingPlan plan) async {
|
||||||
String body = JsonEncoder().convert(plan.toJson());
|
String body = const JsonEncoder().convert(plan.toJson());
|
||||||
log(" ===== saving customer training plan:" + body);
|
log(" ===== saving customer training plan:$body");
|
||||||
final String response = await _client.post("customer_training_plan/", body);
|
final String response = await _client.post("customer_training_plan", body);
|
||||||
final CustomerTrainingPlan saved = CustomerTrainingPlan.fromJson(jsonDecode(response));
|
final CustomerTrainingPlan saved = CustomerTrainingPlan.fromJson(jsonDecode(response));
|
||||||
return saved;
|
return saved;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<CustomerTrainingPlanExercise> saveCustomerTrainingPlanExercise(CustomerTrainingPlanExercise planExercise) async {
|
Future<CustomerTrainingPlanExercise> saveCustomerTrainingPlanExercise(CustomerTrainingPlanExercise planExercise) async {
|
||||||
String body = JsonEncoder().convert(planExercise.toJson());
|
String body = const JsonEncoder().convert(planExercise.toJson());
|
||||||
log(" ===== saving customer training plan exercise:" + body);
|
log(" ===== saving customer training plan exercise:$body");
|
||||||
final String response = await _client.post("customer_training_plan_exercise/", body);
|
final String response = await _client.post("customer_training_plan_exercise", body);
|
||||||
final CustomerTrainingPlanExercise saved = CustomerTrainingPlanExercise.fromJson(jsonDecode(response));
|
final CustomerTrainingPlanExercise saved = CustomerTrainingPlanExercise.fromJson(jsonDecode(response));
|
||||||
return saved;
|
return saved;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<CustomerTrainingPlan> updateCustomerTrainingPlan(CustomerTrainingPlan plan, int customerTrainingPlanId) async {
|
Future<CustomerTrainingPlan> updateCustomerTrainingPlan(CustomerTrainingPlan plan, int customerTrainingPlanId) async {
|
||||||
String body = JsonEncoder().convert(plan.toJson());
|
String body = const JsonEncoder().convert(plan.toJson());
|
||||||
log(" ===== update customer training plan:" + body);
|
log(" ===== update customer training plan:$body");
|
||||||
final String response = await _client.post("customer_training_plan/update/$customerTrainingPlanId", body);
|
final String response = await _client.post("customer_training_plan/update/$customerTrainingPlanId", body);
|
||||||
final CustomerTrainingPlan saved = CustomerTrainingPlan.fromJson(jsonDecode(response));
|
final CustomerTrainingPlan saved = CustomerTrainingPlan.fromJson(jsonDecode(response));
|
||||||
return saved;
|
return saved;
|
||||||
|
@ -2,6 +2,7 @@ import 'dart:convert';
|
|||||||
import 'package:workouttest_util/util/app_language.dart';
|
import 'package:workouttest_util/util/app_language.dart';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
// ignore: depend_on_referenced_packages
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
class DateRate {
|
class DateRate {
|
||||||
@ -11,7 +12,7 @@ class DateRate {
|
|||||||
static String yearly = "yearly";
|
static String yearly = "yearly";
|
||||||
}
|
}
|
||||||
|
|
||||||
mixin Common {
|
mixin Common{
|
||||||
final emailError = "Please type a right email address here.";
|
final emailError = "Please type a right email address here.";
|
||||||
final passwordError = "The password must have at least 8 characters.";
|
final passwordError = "The password must have at least 8 characters.";
|
||||||
|
|
||||||
@ -29,7 +30,7 @@ mixin Common {
|
|||||||
|
|
||||||
String dateName = DateFormat(DateFormat.YEAR_NUM_MONTH_DAY, AppLanguage().appLocal.toString()).format(date.toUtc());
|
String dateName = DateFormat(DateFormat.YEAR_NUM_MONTH_DAY, AppLanguage().appLocal.toString()).format(date.toUtc());
|
||||||
if (timeDisplay) {
|
if (timeDisplay) {
|
||||||
dateName += " " + DateFormat(DateFormat.HOUR_MINUTE, AppLanguage().appLocal.toString()).format(date.toUtc());
|
dateName += " ${DateFormat(DateFormat.HOUR_MINUTE, AppLanguage().appLocal.toString()).format(date.toUtc())}";
|
||||||
}
|
}
|
||||||
|
|
||||||
return dateName;
|
return dateName;
|
||||||
@ -51,7 +52,7 @@ mixin Common {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static String? emailValidation(String? email) {
|
static String? emailValidation(String? email) {
|
||||||
final String error = "Please type an email address";
|
const String error = "Please type an email address";
|
||||||
if (email == null) {
|
if (email == null) {
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
@ -60,8 +61,8 @@ mixin Common {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static String? passwordValidation(String? value) {
|
static String? passwordValidation(String? value) {
|
||||||
final String error = "Password too short";
|
const String error = "Password too short";
|
||||||
if (value == null || value.length == 0) {
|
if (value == null || value.isEmpty) {
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
bool valid = 8 < value.length;
|
bool valid = 8 < value.length;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
name: workouttest_util
|
name: workouttest_util
|
||||||
description: Workout Test app and web functions.
|
description: Workout Test app and web functions.
|
||||||
version: 1.0.0
|
version: 1.0.1
|
||||||
homepage:
|
homepage:
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
|
Loading…
Reference in New Issue
Block a user