wt1.1a flutter_bloc

This commit is contained in:
Bossanyi Tibor
2020-08-17 12:38:47 +02:00
parent 8363d7772f
commit ac1c6be8f3
90 changed files with 4281 additions and 2854 deletions
+20 -8
View File
@@ -39,8 +39,13 @@ class CustomerApi {
body);
Customer customer;
try {
customer = Customer.fromJson(jsonDecode(responseBody));
Auth().afterRegistration(customer);
int status = jsonDecode(responseBody)['status'];
if ( status != null ) {
throw new Exception(jsonDecode(responseBody)['error']);
} else {
customer = Customer.fromJson(jsonDecode(responseBody));
Auth().afterRegistration(customer);
}
} on FormatException catch(exception) {
throw new Exception(responseBody);
}
@@ -56,7 +61,7 @@ class CustomerApi {
Customer customer;
try {
customer = Customer.fromJson(jsonDecode(responseBody));
Auth().afterRegistration(customer);
await Auth().afterLogin(customer);
} on FormatException catch(exception) {
throw new Exception(responseBody);
}
@@ -66,10 +71,17 @@ class CustomerApi {
Future<void> getCustomer(int customerId) async {
String body = "";
print(" ===== get the customer by id: " + customerId.toString() );
final String responseBody = await _client.get(
"customers/"+customerId.toString(),
body);
Customer customer = Customer.fromJson(jsonDecode(responseBody));
Auth().afterRegistration(customer);
try {
final String responseBody = await _client.get(
"customers/"+customerId.toString(),
body);
Customer customer = Customer.fromJson(jsonDecode(responseBody));
Auth().afterRegistration(customer);
} catch (exception) {
print ("Exception: " + exception.toString());
print (" === go to registration ");
Auth().logout();
Auth().startPage = "registration";
}
}
}
+19
View File
@@ -0,0 +1,19 @@
import 'dart:convert';
import 'package:aitrainer_app/model/auth.dart';
import 'package:aitrainer_app/model/exercise_tree.dart';
import 'api.dart';
class ExerciseTreeApi {
final APIClient _client = new APIClient();
Future<List<ExerciseTree>> getExerciseTree() async {
final body = await _client.get("exercise_tree", "");
final Iterable json = jsonDecode(body);
final List<ExerciseTree> exerciseTree = json.map((exerciseTree) =>
ExerciseTree.fromJson(exerciseTree)).toList();
Auth().setExerciseTree(exerciseTree);
return exerciseTree;
}
}
+2 -2
View File
@@ -7,8 +7,8 @@ import 'package:aitrainer_app/service/api.dart';
class ExerciseTypeApi {
final APIClient _client=new APIClient();
Future<List<ExerciseType>> getExerciseTypes(String param) async {
final body = await _client.get("exercise_type", param);
Future<List<ExerciseType>> getExerciseTypes() async {
final body = await _client.get("exercise_type/active", "");
final Iterable json = jsonDecode(body);
final List<ExerciseType> exerciseTypes = json.map( (exerciseType) => ExerciseType.fromJson(exerciseType) ).toList();
Auth().setExerciseTypes(exerciseTypes);