wt1.1a flutter_bloc
This commit is contained in:
+30
-11
@@ -1,4 +1,6 @@
|
||||
import 'package:aitrainer_app/model/customer.dart';
|
||||
import 'package:aitrainer_app/model/exercise_tree.dart';
|
||||
import 'package:aitrainer_app/service/exercise_tree_service.dart';
|
||||
import 'package:aitrainer_app/service/exercisetype_service.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:aitrainer_app/model/exercise_type.dart';
|
||||
@@ -35,7 +37,8 @@ class Auth {
|
||||
static final String isRegisteredKey = 'is_registered';
|
||||
static final String isLoggedInKey = 'is_logged_in';
|
||||
|
||||
static final String _baseUrl = 'http://andio.eu:8888/api/';
|
||||
static final String baseUrl = 'http://aitrainer.info:8888/api/';
|
||||
static final String mediaUrl = 'https://aitrainer.info:4343/media/';
|
||||
static final String username = 'bosi';
|
||||
static final String password = 'andio2009';
|
||||
|
||||
@@ -43,7 +46,9 @@ class Auth {
|
||||
Customer userLoggedIn;
|
||||
bool firstLoad = true;
|
||||
List<ExerciseType> _exerciseTypes;
|
||||
List<ExerciseTree> _exerciseTree;
|
||||
List deviceLanguages;
|
||||
String startPage;
|
||||
|
||||
factory Auth() {
|
||||
return _singleton;
|
||||
@@ -60,7 +65,11 @@ class Auth {
|
||||
}
|
||||
|
||||
static String getBaseUrl() {
|
||||
return _baseUrl;
|
||||
return baseUrl;
|
||||
}
|
||||
|
||||
static String getMediaUrl() {
|
||||
return mediaUrl;
|
||||
}
|
||||
|
||||
afterRegistration(Customer customer) {
|
||||
@@ -70,20 +79,19 @@ class Auth {
|
||||
setPreferences(prefs, SharePrefsChange.registration, customer.customerId);
|
||||
}
|
||||
|
||||
afterLogin(Customer customer) {
|
||||
afterLogin(Customer customer) async {
|
||||
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
|
||||
|
||||
userLoggedIn = customer;
|
||||
setPreferences(prefs, SharePrefsChange.login, customer.customerId);
|
||||
await setPreferences(prefs, SharePrefsChange.login, customer.customerId);
|
||||
}
|
||||
|
||||
logout(){
|
||||
logout() async {
|
||||
userLoggedIn = null;
|
||||
authToken = "";
|
||||
//firstLoad = true;
|
||||
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
|
||||
setPreferences(prefs, SharePrefsChange.logout, 0);
|
||||
|
||||
await setPreferences(prefs, SharePrefsChange.logout, 0);
|
||||
}
|
||||
|
||||
setPreferences(Future<SharedPreferences> prefs,
|
||||
@@ -95,18 +103,21 @@ class Auth {
|
||||
DateTime now = DateTime.now();
|
||||
sharedPreferences.setString(Auth.lastStoreDateKey, now.toString());
|
||||
if ( type == SharePrefsChange.registration ) {
|
||||
Auth().startPage = "home";
|
||||
sharedPreferences.setInt(Auth.customerIdKey, customerId);
|
||||
sharedPreferences.setBool(Auth.isRegisteredKey, true);
|
||||
sharedPreferences.setBool(Auth.isLoggedInKey, true);
|
||||
await ExerciseTypeApi().getExerciseTypes("");
|
||||
await ExerciseTypeApi().getExerciseTypes();
|
||||
await ExerciseTreeApi().getExerciseTree();
|
||||
} else if ( type == SharePrefsChange.login ) {
|
||||
|
||||
Auth().startPage = "home";
|
||||
sharedPreferences.setInt(Auth.customerIdKey, customerId);
|
||||
sharedPreferences.setBool(Auth.isLoggedInKey, true);
|
||||
await ExerciseTypeApi().getExerciseTypes("");
|
||||
await ExerciseTypeApi().getExerciseTypes();
|
||||
await ExerciseTreeApi().getExerciseTree();
|
||||
} else if ( type == SharePrefsChange.logout ) {
|
||||
sharedPreferences.setBool(Auth.isLoggedInKey, false);
|
||||
//sharedPreferences.setInt(Auth.customerIdKey, 0);
|
||||
sharedPreferences.setInt(Auth.customerIdKey, 0);
|
||||
sharedPreferences.setString(authTokenKey, "");
|
||||
}
|
||||
}
|
||||
@@ -115,7 +126,15 @@ class Auth {
|
||||
this._exerciseTypes = exerciseTypes;
|
||||
}
|
||||
|
||||
void setExerciseTree( List<ExerciseTree> exerciseTree) {
|
||||
this._exerciseTree = exerciseTree;
|
||||
}
|
||||
|
||||
List<ExerciseType> getExerciseTypes() {
|
||||
return this._exerciseTypes;
|
||||
}
|
||||
|
||||
List<ExerciseTree> getExerciseTree() {
|
||||
return this._exerciseTree;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
class ExerciseTree {
|
||||
int treeId;
|
||||
int parentId;
|
||||
String name;
|
||||
String imageUrl;
|
||||
bool active;
|
||||
String nameTranslation;
|
||||
|
||||
ExerciseTree.fromJson(Map json) {
|
||||
this.treeId = json['treeId'];
|
||||
this.name = json['name'];
|
||||
this.parentId = json['parentId'];
|
||||
this.imageUrl = json['imageUrl'];
|
||||
this.active = json['active'];
|
||||
this.nameTranslation =
|
||||
json['translations'] != null && (json['translations']).length > 0
|
||||
? json['translations'][0]['name']
|
||||
: this.name;
|
||||
}
|
||||
}
|
||||
@@ -2,22 +2,32 @@ import 'package:flutter/services.dart';
|
||||
|
||||
class ExerciseType {
|
||||
int exerciseTypeId;
|
||||
int treeId;
|
||||
String name;
|
||||
String description;
|
||||
BinaryCodec video;
|
||||
String unit;
|
||||
String unitQuantity;
|
||||
String unitQuantityUnit;
|
||||
bool active;
|
||||
String imageUrl;
|
||||
String nameTranslation;
|
||||
String descriptionTranslation;
|
||||
|
||||
ExerciseType({this.name, this.description});
|
||||
|
||||
ExerciseType.fromJson(Map json) {
|
||||
this.exerciseTypeId = json['exerciseTypeId'];
|
||||
this.treeId = json['treeId'];
|
||||
this.name = json['name'];
|
||||
this.description = json['description'];
|
||||
this.unit = json['unit'];
|
||||
this.unitQuantity = json['unitQuantity'];
|
||||
this.unitQuantityUnit = json['unitQuantityUnit'];
|
||||
this.active = json['active'];
|
||||
this.imageUrl = json['images'][0]['url'];
|
||||
this.nameTranslation = json['translations'][0]['name'];
|
||||
this.descriptionTranslation = json['translations'][0]['description'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() =>
|
||||
@@ -26,6 +36,7 @@ class ExerciseType {
|
||||
"description": description,
|
||||
"unit": unit,
|
||||
"unitQuantity": unitQuantity,
|
||||
"unitQuantityUnit": unitQuantityUnit
|
||||
"unitQuantityUnit": unitQuantityUnit,
|
||||
"active": active
|
||||
};
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'exercise_type.dart';
|
||||
|
||||
class WorkoutTree {
|
||||
int id;
|
||||
int parent;
|
||||
@@ -9,7 +11,8 @@ class WorkoutTree {
|
||||
double fontSize;
|
||||
bool child;
|
||||
int exerciseTypeId;
|
||||
ExerciseType exerciseType;
|
||||
|
||||
WorkoutTree(this.id, this.parent, this.name, this.imageName, this.color, this.fontSize, this.child, this.exerciseTypeId);
|
||||
WorkoutTree(this.id, this.parent, this.name, this.imageName, this.color, this.fontSize, this.child, this.exerciseTypeId, this.exerciseType);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user