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/
|
||||
.packages
|
||||
build/
|
||||
.flutter-plugins-dependencies*
|
@ -119,6 +119,7 @@ class Cache with Logging {
|
||||
|
||||
static String baseUrlLive = 'https://api.workouttest.org/api/';
|
||||
static String baseUrlTest = 'https://apitest.workouttest.org/api/';
|
||||
static String baseUrlLocal = 'http://localhost:8443/api/';
|
||||
late String baseUrl;
|
||||
static const String mediaUrl = 'https://admin.workouttest.org/media/';
|
||||
static const String username = 'bosi';
|
||||
@ -199,6 +200,9 @@ class Cache with Logging {
|
||||
if (testEnv == "1") {
|
||||
baseUrl = baseUrlTest;
|
||||
liveServer = false;
|
||||
} else if ( testEnv == "2") {
|
||||
baseUrl = baseUrlLocal;
|
||||
liveServer = false;
|
||||
}
|
||||
|
||||
for (var element in ActivityDone.values) {
|
||||
@ -210,6 +214,10 @@ class Cache with Logging {
|
||||
baseUrl = baseUrlTest;
|
||||
}
|
||||
|
||||
void setLocalBaseUrl() {
|
||||
baseUrl = baseUrlLocal;
|
||||
}
|
||||
|
||||
String getAuthToken() {
|
||||
return authToken;
|
||||
}
|
||||
@ -362,10 +370,14 @@ class Cache with Logging {
|
||||
}
|
||||
|
||||
void setServerAddress(SharedPreferences prefs) {
|
||||
if (this.testEnvironment == "1") {
|
||||
if (testEnvironment == "1") {
|
||||
baseUrl = baseUrlTest;
|
||||
print("TestEnv $baseUrl");
|
||||
return;
|
||||
} else if ( testEnvironment == "2") {
|
||||
baseUrl = baseUrlLocal;
|
||||
print("TestEnv $baseUrl");
|
||||
return;
|
||||
}
|
||||
final bool? live = prefs.getBool(Cache.serverKey);
|
||||
if (live == null) {
|
||||
|
@ -1,3 +1,4 @@
|
||||
// ignore: depend_on_referenced_packages
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class CustomerActivity {
|
||||
@ -12,19 +13,19 @@ class CustomerActivity {
|
||||
customerId = json['custoemrId'];
|
||||
type = json['type'];
|
||||
skipped = json['skipped'];
|
||||
this.dateAdd = DateTime.parse(json['dateAdd']);
|
||||
dateAdd = DateTime.parse(json['dateAdd']);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'activityId': this.activityId,
|
||||
'customerId': this.customerId,
|
||||
'type': this.type,
|
||||
'skipped': this.skipped,
|
||||
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateAdd!),
|
||||
'activityId': activityId,
|
||||
'customerId': customerId,
|
||||
'type': type,
|
||||
'skipped': skipped,
|
||||
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(dateAdd!),
|
||||
};
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return this.toJson().toString();
|
||||
return toJson().toString();
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
// ignore: depend_on_referenced_packages
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class CustomerExerciseDevice {
|
||||
@ -14,11 +15,11 @@ class CustomerExerciseDevice {
|
||||
}
|
||||
|
||||
CustomerExerciseDevice.fromJson(Map json) {
|
||||
this.customerExerciseDeviceId = json['customerExerciseDeviceId'];
|
||||
this.exerciseDeviceId = json['exerciseDeviceId'];
|
||||
this.customerId = json['customerId'];
|
||||
this.favourite = json['favourite'] == 1 ? true : false;
|
||||
this.dateAdd = DateTime.parse(json['dateAdd']);
|
||||
customerExerciseDeviceId = json['customerExerciseDeviceId'];
|
||||
exerciseDeviceId = json['exerciseDeviceId'];
|
||||
customerId = json['customerId'];
|
||||
favourite = json['favourite'] == 1 ? true : false;
|
||||
dateAdd = DateTime.parse(json['dateAdd']);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
@ -27,7 +28,7 @@ class CustomerExerciseDevice {
|
||||
"exerciseDeviceId": exerciseDeviceId,
|
||||
"customerId": customerId,
|
||||
"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 {
|
||||
return {
|
||||
@ -35,7 +36,7 @@ class CustomerExerciseDevice {
|
||||
"exerciseDeviceId": exerciseDeviceId,
|
||||
"customerId": customerId,
|
||||
"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 '../util/logging.dart';
|
||||
|
||||
class CustomerProperty {
|
||||
class CustomerProperty with Logging {
|
||||
int? customerPropertyId;
|
||||
late int propertyId;
|
||||
late int customerId;
|
||||
@ -18,20 +20,20 @@ class CustomerProperty {
|
||||
required this.propertyValue});
|
||||
|
||||
CustomerProperty.fromJson(Map json) {
|
||||
this.customerPropertyId = json['customerPropertyId'];
|
||||
this.propertyId = json['propertyId'];
|
||||
this.customerId = json['customerId'];
|
||||
this.dateAdd = DateTime.parse(json['dateAdd']);
|
||||
customerPropertyId = json['customerPropertyId'];
|
||||
propertyId = json['propertyId'];
|
||||
customerId = json['customerId'];
|
||||
dateAdd = DateTime.parse(json['dateAdd']);
|
||||
|
||||
if (this.dateAdd != null) {
|
||||
dateYmd = DateFormat('yyyy-MM-dd').format(this.dateAdd!);
|
||||
dateYm = DateFormat('yyyy-MM').format(this.dateAdd!);
|
||||
dateY = DateFormat('yyyy').format(this.dateAdd!);
|
||||
if (dateAdd != null) {
|
||||
dateYmd = DateFormat('yyyy-MM-dd').format(dateAdd!);
|
||||
dateYm = DateFormat('yyyy-MM').format(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() {
|
||||
|
@ -4,7 +4,6 @@ import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
import 'package:workouttest_util/util/logging.dart';
|
||||
import 'package:workouttest_util/util/common.dart';
|
||||
import 'package:workouttest_util/util/not_found_exception.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:workouttest_util/model/cache.dart';
|
||||
|
||||
class APIClient with Common, Logging {
|
||||
@ -20,42 +19,40 @@ class APIClient with Common, Logging {
|
||||
}
|
||||
|
||||
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 {
|
||||
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);
|
||||
HttpClient client = HttpClient();
|
||||
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');
|
||||
|
||||
final body = '{"username":"$email", "password":"$password"}';
|
||||
final body = jsonEncode(<String, String>{
|
||||
'username': email,
|
||||
'password': password
|
||||
});
|
||||
|
||||
request.write(body);
|
||||
HttpClientResponse result = await request.close();
|
||||
client.close();
|
||||
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}");
|
||||
}
|
||||
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) {
|
||||
print(exception.toString());
|
||||
log(exception.toString());
|
||||
try {
|
||||
await Sentry.captureException(exception);
|
||||
} on Exception catch (e) {
|
||||
print(e);
|
||||
log(e.toString());
|
||||
}
|
||||
|
||||
throw Exception("Network error, try again later!");
|
||||
@ -67,35 +64,35 @@ class APIClient with Common, Logging {
|
||||
trace(" ------------ http/post body $body - url: $url ");
|
||||
try {
|
||||
String authToken = Cache().getAuthToken();
|
||||
if (authToken.length == 0) {
|
||||
var responseJson = await this.authenticateUser(Cache.username, Cache.password);
|
||||
if (authToken.isEmpty) {
|
||||
var responseJson = await authenticateUser(Cache.username, Cache.password);
|
||||
authToken = responseJson['token'];
|
||||
Cache().authToken = authToken;
|
||||
}
|
||||
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.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.contentLength = body.length;
|
||||
request.write(body);
|
||||
HttpClientResponse result = await request.close();
|
||||
client.close();
|
||||
trace(" ------------post response code: " + result.statusCode.toString());
|
||||
trace(" ------------post response code: ${result.statusCode}");
|
||||
if (result.statusCode == 200) {
|
||||
return await result.transform(utf8.decoder).join();
|
||||
} else if (result.statusCode == 404) {
|
||||
throw NotFoundException(message: "Not Found");
|
||||
throw const NotFoundException(message: "Not Found");
|
||||
} else {
|
||||
throw Exception("Network Error, please try again later");
|
||||
}
|
||||
} on NotFoundException catch(e) {
|
||||
throw NotFoundException(message: "Not Found");
|
||||
throw NotFoundException(message: "Not Found ${e.message}");
|
||||
} on Exception catch (e) {
|
||||
print("Post Exception: $e");
|
||||
log("Post Exception: $e");
|
||||
await Sentry.captureException(e);
|
||||
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 {
|
||||
final url = Cache().getBaseUrl() + endPoint + param;
|
||||
try {
|
||||
trace("-------- API get " + url);
|
||||
trace("-------- API get $url");
|
||||
String authToken = Cache().getAuthToken();
|
||||
if (authToken.length == 0) {
|
||||
var responseJson = await this.authenticateUser(Cache.username, Cache.password);
|
||||
if (authToken.isEmpty) {
|
||||
var responseJson = await authenticateUser(Cache.username, Cache.password);
|
||||
authToken = responseJson['token'];
|
||||
Cache().authToken = authToken;
|
||||
}
|
||||
var uri = Uri.parse(url);
|
||||
|
||||
HttpClient client = new HttpClient();
|
||||
|
||||
client.badCertificateCallback = ((X509Certificate cert, String host, int port) => true);
|
||||
HttpClient client = HttpClient();
|
||||
|
||||
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.write("");
|
||||
HttpClientResponse result = await request.close();
|
||||
client.close();
|
||||
trace(" ------------get response code: " + result.statusCode.toString());
|
||||
trace(" ------------get response code: ${result.statusCode}");
|
||||
if (result.statusCode == 200) {
|
||||
return await result.transform(utf8.decoder).join();
|
||||
} else if (result.statusCode == 404) {
|
||||
throw NotFoundException(message: "Not Found");
|
||||
throw const NotFoundException(message: "Not Found");
|
||||
} else {
|
||||
throw Exception("Network Error, please try again later");
|
||||
}
|
||||
} on NotFoundException catch(e) {
|
||||
throw NotFoundException(message: "Not Found");
|
||||
throw NotFoundException(message: "Not Found ${e.message}");
|
||||
} on Exception catch (e) {
|
||||
print("Post Exception: $e");
|
||||
log("Post Exception: $e");
|
||||
await Sentry.captureException(e);
|
||||
throw Exception("Network Error, please try again later");
|
||||
}
|
||||
|
@ -22,14 +22,14 @@ class CustomerApi with Logging {
|
||||
|
||||
Future<void> saveCustomer(Customer customer) async {
|
||||
customer.dateChange = DateTime.now();
|
||||
String body = JsonEncoder().convert(customer.toJson());
|
||||
log(" ===== saving customer id: " + customer.customerId.toString() + ":" + body);
|
||||
await _client.post("customers/" + customer.customerId.toString(), body);
|
||||
String body = const JsonEncoder().convert(customer.toJson());
|
||||
log(" ===== saving customer id: ${customer.customerId}:$body");
|
||||
await _client.post("customers/${customer.customerId}", body);
|
||||
}
|
||||
|
||||
Future<void> updateFirebaseUid(int customerId, String uid) async {
|
||||
log(" ===== update Firebase uid : " + customerId.toString() + ": " + uid);
|
||||
await _client.post("customers/update_firebase_uid/" + customerId.toString(), uid);
|
||||
log(" ===== update Firebase uid : $customerId: $uid");
|
||||
await _client.post("customers/update_firebase_uid/$customerId", uid);
|
||||
}
|
||||
|
||||
Future<void> deactivateCustomer(int customerId) async {
|
||||
@ -40,21 +40,21 @@ class CustomerApi with Logging {
|
||||
Future<void> addCustomer(Customer customer) async {
|
||||
customer.dateAdd = DateTime.now();
|
||||
customer.dateChange = DateTime.now();
|
||||
String body = JsonEncoder().convert(customer.toJson());
|
||||
log(" ===== add new customer: " + body);
|
||||
String body = const JsonEncoder().convert(customer.toJson());
|
||||
log(" ===== add new customer: $body");
|
||||
await _client.post("customers", body);
|
||||
}
|
||||
|
||||
Future<void> addUser(User user) async {
|
||||
String body = JsonEncoder().convert(user.toJson());
|
||||
log(" ===== add new user: " + body);
|
||||
String body = const JsonEncoder().convert(user.toJson());
|
||||
log(" ===== add new user: $body");
|
||||
final String responseBody = await _client.post("registration", body);
|
||||
Customer customer;
|
||||
try {
|
||||
int? status = jsonDecode(responseBody)['status'];
|
||||
if (status != null) {
|
||||
String error = jsonDecode(responseBody)['error'];
|
||||
throw new Exception(error);
|
||||
throw Exception(error);
|
||||
} else {
|
||||
customer = Customer.fromJson(jsonDecode(responseBody));
|
||||
await Cache().afterRegistration(customer);
|
||||
@ -63,58 +63,58 @@ class CustomerApi with Logging {
|
||||
if (responseBody == "Customer exists") {
|
||||
throw WorkoutTestException(code: WorkoutTestException.CUSTOMER_EXISTS, message: responseBody);
|
||||
}
|
||||
throw new Exception(responseBody);
|
||||
throw Exception(responseBody);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> getUser(User user) async {
|
||||
String body = JsonEncoder().convert(user.toJson());
|
||||
log(" ===== login the user: " + body);
|
||||
String body = const JsonEncoder().convert(user.toJson());
|
||||
log(" ===== login the user: $body");
|
||||
final String responseBody = await _client.post("login", body);
|
||||
Customer customer;
|
||||
try {
|
||||
customer = Customer.fromJson(jsonDecode(responseBody));
|
||||
await Cache().afterLogin(customer);
|
||||
} on FormatException {
|
||||
throw new Exception(responseBody);
|
||||
throw Exception(responseBody);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> getUserByEmail(String email) async {
|
||||
log(" ===== User getByEmail : " + email);
|
||||
final String responseBody = await _client.get("customers/find_by_email/" + email, "");
|
||||
log(" ===== User getByEmail : $email");
|
||||
final String responseBody = await _client.get("customers/find_by_email/$email", "");
|
||||
Customer customer;
|
||||
try {
|
||||
customer = Customer.fromJson(jsonDecode(responseBody));
|
||||
if (customer.firebaseUid == null) {
|
||||
await this.updateFirebaseUid(customer.customerId!, Cache().firebaseUid!);
|
||||
await updateFirebaseUid(customer.customerId!, Cache().firebaseUid!);
|
||||
}
|
||||
Cache().userLoggedIn = customer;
|
||||
final List<CustomerProperty>? properties = await this.getActualProperties(customer.customerId!);
|
||||
final List<CustomerProperty>? properties = await getActualProperties(customer.customerId!);
|
||||
if (properties != null) {
|
||||
this.initProperties(properties);
|
||||
initProperties(properties);
|
||||
}
|
||||
} on FormatException {
|
||||
throw new Exception(responseBody);
|
||||
throw Exception(responseBody);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> getCustomer(int customerId) async {
|
||||
String body = "";
|
||||
log(" ===== get the customer by id: " + customerId.toString());
|
||||
log(" ===== get the customer by id: $customerId");
|
||||
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));
|
||||
log(" --- Customer: " + customer.toJson().toString());
|
||||
log(" --- Customer: ${customer.toJson()}");
|
||||
Cache().userLoggedIn = customer;
|
||||
final List<CustomerProperty>? properties = await this.getActualProperties(customerId);
|
||||
final List<CustomerProperty>? properties = await getActualProperties(customerId);
|
||||
//log(" ---- Props: " + properties.toJson().toString());
|
||||
//await Cache().initCustomer(customerId);
|
||||
if (properties != null) {
|
||||
this.initProperties(properties);
|
||||
initProperties(properties);
|
||||
}
|
||||
} on Exception catch (exception) {
|
||||
log("Exception: " + exception.toString());
|
||||
log("Exception: $exception");
|
||||
log(" === go to registration ");
|
||||
Cache().logout();
|
||||
Cache().startPage = "registration";
|
||||
|
@ -8,7 +8,7 @@ class ExerciseDeviceApi {
|
||||
final APIClient _client = APIClient();
|
||||
|
||||
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 List<ExerciseDevice> devices = json.map((device) => ExerciseDevice.fromJson(device)).toList();
|
||||
Cache().setDevices(devices);
|
||||
|
@ -14,7 +14,7 @@ class ExerciseTypeApi with Logging {
|
||||
final List<ExerciseType> exerciseTypes = json.map((exerciseType) => ExerciseType.fromJson(exerciseType)).toList();
|
||||
|
||||
await Future.forEach(exerciseTypes, (element) async {
|
||||
ExerciseType exerciseType = element as ExerciseType;
|
||||
ExerciseType exerciseType = element;
|
||||
exerciseType.imageUrl = await buildImage(exerciseType.imageUrl, exerciseType.exerciseTypeId);
|
||||
});
|
||||
log("ExerciseTypes downloaded");
|
||||
@ -25,12 +25,12 @@ class ExerciseTypeApi with Logging {
|
||||
|
||||
Future<String> buildImage(String imageUrl, int exerciseTypeId) async {
|
||||
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 assetImage;
|
||||
}).catchError((_) {
|
||||
String imagePath = assetImage.substring(10);
|
||||
String url = Cache.mediaUrl + 'images' + imagePath;
|
||||
String url = '${Cache.mediaUrl}images$imagePath';
|
||||
return url;
|
||||
});
|
||||
} else {
|
||||
|
@ -117,7 +117,7 @@ class FirebaseApi with logger.Logging {
|
||||
}
|
||||
|
||||
String generateNonce([int length = 32]) {
|
||||
final charset = '0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-._';
|
||||
const charset = '0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-._';
|
||||
final random = math.Random.secure();
|
||||
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 {
|
||||
Map<String, dynamic> userData = Map();
|
||||
Map<String, dynamic> userData = {};
|
||||
|
||||
// To prevent replay attacks with the credential returned from Apple, we
|
||||
// include a nonce in the credential request. When signing in with
|
||||
@ -163,7 +163,7 @@ class FirebaseApi with logger.Logging {
|
||||
throw Exception(e);
|
||||
}
|
||||
Cache().firebaseUid = userCredential.user!.uid;
|
||||
log("userCredential: " + userCredential.toString());
|
||||
log("userCredential: $userCredential");
|
||||
|
||||
log("Apple Credentials: ${appleCredential.userIdentifier} state ${appleCredential.state} email ${userCredential.user!.email!}");
|
||||
userData['email'] = userCredential.user!.email;
|
||||
@ -212,16 +212,16 @@ class FirebaseApi with logger.Logging {
|
||||
Map<String, dynamic> userData = Map();
|
||||
|
||||
// Trigger the authentication flow
|
||||
GoogleSignIn _googleSignIn = GoogleSignIn(
|
||||
GoogleSignIn googleSignIn = GoogleSignIn(
|
||||
scopes: [
|
||||
'email',
|
||||
'https://www.googleapis.com/auth/contacts.readonly',
|
||||
],
|
||||
);
|
||||
final GoogleSignInAccount? googleUser = await _googleSignIn.signIn();
|
||||
final GoogleSignInAccount? googleUser = await googleSignIn.signIn();
|
||||
|
||||
if (googleUser == null) {
|
||||
Sentry.captureException(new Exception("Google Sign In failed"));
|
||||
Sentry.captureException(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);
|
||||
Cache().firebaseUid = userCredential.user!.uid;
|
||||
|
||||
log("GoogleUser: " + googleUser.toString());
|
||||
log("GoogleUser: $googleUser");
|
||||
userData['email'] = googleUser.email;
|
||||
userData['id'] = googleUser.id;
|
||||
userData['name'] = googleUser.displayName;
|
||||
@ -249,16 +249,16 @@ class FirebaseApi with logger.Logging {
|
||||
Map<String, dynamic> userData = Map();
|
||||
|
||||
// Trigger the authentication flow
|
||||
GoogleSignIn _googleSignIn = GoogleSignIn(
|
||||
GoogleSignIn googleSignIn = GoogleSignIn(
|
||||
scopes: [
|
||||
'email',
|
||||
'https://www.googleapis.com/auth/contacts.readonly',
|
||||
],
|
||||
);
|
||||
final GoogleSignInAccount? googleUser = await _googleSignIn.signIn();
|
||||
final GoogleSignInAccount? googleUser = await googleSignIn.signIn();
|
||||
|
||||
if (googleUser == null) {
|
||||
Sentry.captureException(new Exception("Google Sign In failed"));
|
||||
Sentry.captureException(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);
|
||||
|
||||
log("Google credentials: " + credential.toString() + " GoogleUser: " + googleUser.toString());
|
||||
log("Google credentials: $credential GoogleUser: $googleUser");
|
||||
Cache().firebaseUid = userCredential.user!.uid;
|
||||
|
||||
userData['email'] = googleUser.email;
|
||||
@ -295,7 +295,7 @@ class FirebaseApi with logger.Logging {
|
||||
Cache().firebaseUid = userData['id'];
|
||||
log(userData.toString());
|
||||
} else {
|
||||
Sentry.captureException(new Exception(result.message));
|
||||
Sentry.captureException(Exception(result.message));
|
||||
throw Exception("Facebook login was not successful");
|
||||
}
|
||||
|
||||
@ -312,7 +312,7 @@ class FirebaseApi with logger.Logging {
|
||||
Cache().accessTokenFacebook = accessToken;
|
||||
// get the user data
|
||||
userData = await FacebookAuth.instance.getUserData();
|
||||
log("FB user data: " + userData.toString());
|
||||
log("FB user data: $userData");
|
||||
|
||||
// Create a credential from the access token
|
||||
final OAuthCredential facebookAuthCredential = FacebookAuthProvider.credential(accessToken.token);
|
||||
@ -323,7 +323,7 @@ class FirebaseApi with logger.Logging {
|
||||
|
||||
Cache().firebaseUid = userCredential.user!.uid;
|
||||
} else {
|
||||
Sentry.captureException(new Exception(result.message));
|
||||
Sentry.captureException(Exception(result.message));
|
||||
throw Exception("Facebook login was not successful");
|
||||
}
|
||||
|
||||
@ -356,7 +356,7 @@ class FirebaseApi with logger.Logging {
|
||||
//RemoteConfigValue(null, ValueSource.valueStatic);
|
||||
//Cache().setRemoteConfig(remoteConfig);
|
||||
} 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) {
|
||||
await remoteConfig.setDefaults(<String, dynamic>{
|
||||
'sales_page_text_a': '',
|
||||
@ -375,29 +375,3 @@ Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
|
||||
// make sure you call `initializeApp` before using other Firebase services.
|
||||
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 {
|
||||
late List<ExerciseTree> exerciseTree;
|
||||
late List<ExerciseTreeParents> exerciseTreeParents;
|
||||
final body = await _client.get("app_package/", "");
|
||||
final body = await _client.get("app_package", "");
|
||||
|
||||
final List<String> models = body.split("|||");
|
||||
await Future.forEach(models, (elem) async {
|
||||
final String element = elem as String;
|
||||
final String element = elem;
|
||||
final List<String> headRecord = element.split("***");
|
||||
final Iterable json = jsonDecode(headRecord[1]);
|
||||
if (headRecord[0] == "ExerciseDevice") {
|
||||
@ -57,7 +57,7 @@ class PackageApi {
|
||||
} else if (headRecord[0] == "ExerciseType") {
|
||||
final List<ExerciseType> exerciseTypes = json.map((exerciseType) => ExerciseType.fromJson(exerciseType)).toList();
|
||||
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);
|
||||
});
|
||||
Cache().setExerciseTypes(exerciseTypes);
|
||||
@ -81,48 +81,48 @@ class PackageApi {
|
||||
Cache().setTutorials(tutorials);
|
||||
} else if (headRecord[0] == "Description") {
|
||||
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");
|
||||
Cache().setDescriptions(descriptions);
|
||||
} else if (headRecord[0] == "Faq") {
|
||||
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");
|
||||
Cache().setFaqs(faqs);
|
||||
} else if (headRecord[0] == "TrainingPlan") {
|
||||
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 = [];
|
||||
if (plans != null) {
|
||||
plans.forEach((element) {
|
||||
|
||||
for (var element in plans) {
|
||||
if (element.active) {
|
||||
activePlans.add(element);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Cache().setTrainingPlans(activePlans);
|
||||
} else if (headRecord[0] == "SplitTests") {
|
||||
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");
|
||||
Cache().setSplitTests(tests);
|
||||
} else if (headRecord[0] == "TrainingPlanDay") {
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
||||
exerciseTree = this.getExerciseTreeParents(exerciseTree, exerciseTreeParents);
|
||||
exerciseTree = getExerciseTreeParents(exerciseTree, exerciseTreeParents);
|
||||
|
||||
await Future.forEach(exerciseTree, (element) async {
|
||||
ExerciseTree tree = element as ExerciseTree;
|
||||
ExerciseTree tree = element;
|
||||
tree.imageUrl = await ExerciseTreeApi().buildImage(tree.imageUrl, tree.treeId);
|
||||
});
|
||||
Cache().setExerciseTree(exerciseTree);
|
||||
|
||||
TrainingPlanDayRepository trainingPlanDayRepository = TrainingPlanDayRepository();
|
||||
TrainingPlanDayRepository trainingPlanDayRepository = const TrainingPlanDayRepository();
|
||||
trainingPlanDayRepository.assignTrainingPlanDays();
|
||||
|
||||
return;
|
||||
@ -158,11 +158,11 @@ class PackageApi {
|
||||
|
||||
Future<void> getCustomerPackage(int customerId) async {
|
||||
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("|||");
|
||||
await Future.forEach(models, (elem) async {
|
||||
final String element = elem as String;
|
||||
final String element = elem;
|
||||
final List<String> headRecord = element.split("***");
|
||||
//print("Class " + headRecord[0]);
|
||||
if (headRecord[0] == "Customer") {
|
||||
|
@ -8,7 +8,7 @@ class ProductApi {
|
||||
final APIClient _client = APIClient();
|
||||
|
||||
Future<List<Product>> getProducts() async {
|
||||
final body = await _client.get("product/", "");
|
||||
final body = await _client.get("product", "");
|
||||
final Iterable json = jsonDecode(body);
|
||||
final List<Product> products = json.map((product) => Product.fromJson(product)).toList();
|
||||
Cache().setProducts(products);
|
||||
|
@ -2,14 +2,13 @@ import 'dart:convert';
|
||||
|
||||
import 'package:workouttest_util/model/cache.dart';
|
||||
import 'package:workouttest_util/service/api.dart';
|
||||
|
||||
import 'package:workouttest_util/model/property.dart';
|
||||
|
||||
class PropertyApi {
|
||||
final APIClient _client = APIClient();
|
||||
|
||||
Future<List<Property>> getProperties() async {
|
||||
final body = await _client.get("property/", "");
|
||||
final body = await _client.get("property", "");
|
||||
final Iterable json = jsonDecode(body);
|
||||
final List<Property> properties = json.map((property) => Property.fromJson(property)).toList();
|
||||
Cache().setProperties(properties);
|
||||
|
@ -11,7 +11,7 @@ class PurchaseApi with Logging {
|
||||
Future<List<Purchase>> getPurchasesByCustomer(int customerId) async {
|
||||
List<Purchase> purchases = [];
|
||||
try {
|
||||
final body = await _client.get("purchase/customer/" + customerId.toString(), "");
|
||||
final body = await _client.get("purchase/customer/$customerId", "");
|
||||
final Iterable json = jsonDecode(body);
|
||||
final List<Purchase> purchases = json.map((purchase) => Purchase.fromJson(purchase)).toList();
|
||||
Cache().setPurchases(purchases);
|
||||
@ -23,7 +23,7 @@ class PurchaseApi with Logging {
|
||||
|
||||
Future<void> savePurchase(Purchase purchase) async {
|
||||
String body = JsonEncoder().convert(purchase.toJson());
|
||||
log(" ===== saving purchase:" + body);
|
||||
await _client.post("purchase/", body);
|
||||
log(" ===== saving purchase:$body");
|
||||
await _client.post("purchase", body);
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ class TrackingApi with Logging {
|
||||
try {
|
||||
String body = const JsonEncoder().convert(tracking.toJson());
|
||||
log(" ===== saving tracking: $body");
|
||||
await _client.post("tracking/", body);
|
||||
await _client.post("tracking", body);
|
||||
} catch (exception) {
|
||||
log("exception in tracking: ${exception.toString()}");
|
||||
}
|
||||
|
@ -9,24 +9,24 @@ class TrainingPlanApi with Logging {
|
||||
final APIClient _client = APIClient();
|
||||
|
||||
Future<CustomerTrainingPlan> saveCustomerTrainingPlan(CustomerTrainingPlan plan) async {
|
||||
String body = JsonEncoder().convert(plan.toJson());
|
||||
log(" ===== saving customer training plan:" + body);
|
||||
final String response = await _client.post("customer_training_plan/", body);
|
||||
String body = const JsonEncoder().convert(plan.toJson());
|
||||
log(" ===== saving customer training plan:$body");
|
||||
final String response = await _client.post("customer_training_plan", body);
|
||||
final CustomerTrainingPlan saved = CustomerTrainingPlan.fromJson(jsonDecode(response));
|
||||
return saved;
|
||||
}
|
||||
|
||||
Future<CustomerTrainingPlanExercise> saveCustomerTrainingPlanExercise(CustomerTrainingPlanExercise planExercise) async {
|
||||
String body = JsonEncoder().convert(planExercise.toJson());
|
||||
log(" ===== saving customer training plan exercise:" + body);
|
||||
final String response = await _client.post("customer_training_plan_exercise/", body);
|
||||
String body = const JsonEncoder().convert(planExercise.toJson());
|
||||
log(" ===== saving customer training plan exercise:$body");
|
||||
final String response = await _client.post("customer_training_plan_exercise", body);
|
||||
final CustomerTrainingPlanExercise saved = CustomerTrainingPlanExercise.fromJson(jsonDecode(response));
|
||||
return saved;
|
||||
}
|
||||
|
||||
Future<CustomerTrainingPlan> updateCustomerTrainingPlan(CustomerTrainingPlan plan, int customerTrainingPlanId) async {
|
||||
String body = JsonEncoder().convert(plan.toJson());
|
||||
log(" ===== update customer training plan:" + body);
|
||||
String body = const JsonEncoder().convert(plan.toJson());
|
||||
log(" ===== update customer training plan:$body");
|
||||
final String response = await _client.post("customer_training_plan/update/$customerTrainingPlanId", body);
|
||||
final CustomerTrainingPlan saved = CustomerTrainingPlan.fromJson(jsonDecode(response));
|
||||
return saved;
|
||||
|
@ -2,6 +2,7 @@ import 'dart:convert';
|
||||
import 'package:workouttest_util/util/app_language.dart';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
// ignore: depend_on_referenced_packages
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class DateRate {
|
||||
@ -11,7 +12,7 @@ class DateRate {
|
||||
static String yearly = "yearly";
|
||||
}
|
||||
|
||||
mixin Common {
|
||||
mixin Common{
|
||||
final emailError = "Please type a right email address here.";
|
||||
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());
|
||||
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;
|
||||
@ -51,7 +52,7 @@ mixin Common {
|
||||
}
|
||||
|
||||
static String? emailValidation(String? email) {
|
||||
final String error = "Please type an email address";
|
||||
const String error = "Please type an email address";
|
||||
if (email == null) {
|
||||
return error;
|
||||
}
|
||||
@ -60,8 +61,8 @@ mixin Common {
|
||||
}
|
||||
|
||||
static String? passwordValidation(String? value) {
|
||||
final String error = "Password too short";
|
||||
if (value == null || value.length == 0) {
|
||||
const String error = "Password too short";
|
||||
if (value == null || value.isEmpty) {
|
||||
return error;
|
||||
}
|
||||
bool valid = 8 < value.length;
|
||||
|
@ -1,6 +1,6 @@
|
||||
name: workouttest_util
|
||||
description: Workout Test app and web functions.
|
||||
version: 1.0.0
|
||||
version: 1.0.1
|
||||
homepage:
|
||||
|
||||
environment:
|
||||
|
Loading…
Reference in New Issue
Block a user