Merge ssh://git.aitrainer.app:6622/bossanyit/aitrainer_app

This commit is contained in:
bossanyit 2020-11-29 10:41:13 +01:00
commit ba50018a2b
71 changed files with 1458 additions and 845 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 348 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

BIN
asset/image/haken.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

View File

@ -223,5 +223,10 @@
"Your Sizes":"Your Sizes", "Your Sizes":"Your Sizes",
"Size Of Your":"Size Of Your", "Size Of Your":"Size Of Your",
"Please type the following data:":"Please type the following data:", "Please type the following data:":"Please type the following data:",
"Cancel": "Cancel" "Cancel": "Cancel",
"Available Devices":"Available Devices",
"select your equipments by tapping":"select your equipments by tapping",
"Available Equipments":"Available Equipments",
"select your places by tapping":"select your places by tapping",
"Available Training Places":"Available Training Places"
} }

View File

@ -224,5 +224,10 @@
"Your Sizes":"Méreteid", "Your Sizes":"Méreteid",
"Size Of Your":"Testméret:", "Size Of Your":"Testméret:",
"Please type the following data:":"Kérlek írd be a következő adatot:", "Please type the following data:":"Kérlek írd be a következő adatot:",
"Cancel": "Mégsem" "Cancel": "Mégsem",
"Available Devices":"Edzés eszközök",
"select your equipments by tapping":"válaszd ki az eszközeidet, kattints a képre",
"Available Equipments":"Elérhető eszközök",
"select your places by tapping":"kattints az edzéshelyszínre",
"Available Training Places":"Elérhető edzéshelyszínek"
} }

View File

@ -1,109 +1,91 @@
PODS: PODS:
- devicelocale (0.0.1): - devicelocale (0.0.1):
- Flutter - Flutter
- FBSDKCoreKit (7.1.1): - Firebase/Auth (6.33.0):
- FBSDKCoreKit/Basics (= 7.1.1)
- FBSDKCoreKit/Core (= 7.1.1)
- FBSDKCoreKit/Basics (7.1.1)
- FBSDKCoreKit/Core (7.1.1):
- FBSDKCoreKit/Basics
- FBSDKLoginKit (7.1.1):
- FBSDKLoginKit/Login (= 7.1.1)
- FBSDKLoginKit/Login (7.1.1):
- FBSDKCoreKit (~> 7.1.1)
- Firebase/Auth (6.26.0):
- Firebase/CoreOnly - Firebase/CoreOnly
- FirebaseAuth (~> 6.5.3) - FirebaseAuth (~> 6.9.2)
- Firebase/CoreOnly (6.26.0): - Firebase/CoreOnly (6.33.0):
- FirebaseCore (= 6.7.2) - FirebaseCore (= 6.10.3)
- Firebase/Messaging (6.26.0): - Firebase/Messaging (6.33.0):
- Firebase/CoreOnly - Firebase/CoreOnly
- FirebaseMessaging (~> 4.4.1) - FirebaseMessaging (~> 4.7.0)
- firebase_auth (0.18.1-2): - firebase_auth (0.18.3):
- Firebase/Auth (~> 6.26.0) - Firebase/Auth (~> 6.33.0)
- Firebase/CoreOnly (~> 6.26.0) - Firebase/CoreOnly (~> 6.33.0)
- firebase_core - firebase_core
- Flutter - Flutter
- firebase_core (0.5.0-1): - firebase_core (0.5.2):
- Firebase/CoreOnly (~> 6.26.0) - Firebase/CoreOnly (~> 6.33.0)
- Flutter - Flutter
- firebase_messaging (7.0.3): - firebase_messaging (7.0.3):
- Firebase/CoreOnly (~> 6.26.0) - Firebase/CoreOnly (~> 6.33.0)
- Firebase/Messaging (~> 6.26.0) - Firebase/Messaging (~> 6.33.0)
- firebase_core - firebase_core
- Flutter - Flutter
- FirebaseAnalyticsInterop (1.5.0) - FirebaseAuth (6.9.2):
- FirebaseAuth (6.5.3): - FirebaseCore (~> 6.10)
- FirebaseAuthInterop (~> 1.0) - GoogleUtilities/AppDelegateSwizzler (~> 6.7)
- FirebaseCore (~> 6.6) - GoogleUtilities/Environment (~> 6.7)
- GoogleUtilities/AppDelegateSwizzler (~> 6.5)
- GoogleUtilities/Environment (~> 6.5)
- GTMSessionFetcher/Core (~> 1.1) - GTMSessionFetcher/Core (~> 1.1)
- FirebaseAuthInterop (1.1.0) - FirebaseCore (6.10.3):
- FirebaseCore (6.7.2): - FirebaseCoreDiagnostics (~> 1.6)
- FirebaseCoreDiagnostics (~> 1.3) - GoogleUtilities/Environment (~> 6.7)
- FirebaseCoreDiagnosticsInterop (~> 1.2) - GoogleUtilities/Logger (~> 6.7)
- GoogleUtilities/Environment (~> 6.5) - FirebaseCoreDiagnostics (1.7.0):
- GoogleUtilities/Logger (~> 6.5) - GoogleDataTransport (~> 7.4)
- FirebaseCoreDiagnostics (1.4.0): - GoogleUtilities/Environment (~> 6.7)
- GoogleDataTransportCCTSupport (~> 3.1) - GoogleUtilities/Logger (~> 6.7)
- GoogleUtilities/Environment (~> 6.5) - nanopb (~> 1.30906.0)
- GoogleUtilities/Logger (~> 6.5) - FirebaseInstallations (1.7.0):
- nanopb (~> 1.30905.0) - FirebaseCore (~> 6.10)
- FirebaseCoreDiagnosticsInterop (1.2.0) - GoogleUtilities/Environment (~> 6.7)
- FirebaseInstallations (1.3.0): - GoogleUtilities/UserDefaults (~> 6.7)
- FirebaseCore (~> 6.6)
- GoogleUtilities/Environment (~> 6.6)
- GoogleUtilities/UserDefaults (~> 6.6)
- PromisesObjC (~> 1.2) - PromisesObjC (~> 1.2)
- FirebaseInstanceID (4.3.4): - FirebaseInstanceID (4.8.0):
- FirebaseCore (~> 6.6) - FirebaseCore (~> 6.10)
- FirebaseInstallations (~> 1.0) - FirebaseInstallations (~> 1.6)
- GoogleUtilities/Environment (~> 6.5) - GoogleUtilities/Environment (~> 6.7)
- GoogleUtilities/UserDefaults (~> 6.5) - GoogleUtilities/UserDefaults (~> 6.7)
- FirebaseMessaging (4.4.1): - FirebaseMessaging (4.7.1):
- FirebaseAnalyticsInterop (~> 1.5) - FirebaseCore (~> 6.10)
- FirebaseCore (~> 6.6) - FirebaseInstanceID (~> 4.7)
- FirebaseInstanceID (~> 4.3) - GoogleUtilities/AppDelegateSwizzler (~> 6.7)
- GoogleUtilities/AppDelegateSwizzler (~> 6.5) - GoogleUtilities/Environment (~> 6.7)
- GoogleUtilities/Environment (~> 6.5) - GoogleUtilities/Reachability (~> 6.7)
- GoogleUtilities/Reachability (~> 6.5) - GoogleUtilities/UserDefaults (~> 6.7)
- GoogleUtilities/UserDefaults (~> 6.5)
- Protobuf (>= 3.9.2, ~> 3.9) - Protobuf (>= 3.9.2, ~> 3.9)
- Flutter (1.0.0) - flurry (0.0.4):
- flutter_facebook_auth (0.3.1): - Flurry-iOS-SDK/FlurrySDK
- FBSDKCoreKit (~> 7.1.0)
- FBSDKLoginKit (~> 7.1.0)
- Flutter - Flutter
- Flurry-iOS-SDK/FlurrySDK (11.1.1)
- Flutter (1.0.0)
- flutter_keyboard_visibility (0.0.1): - flutter_keyboard_visibility (0.0.1):
- Flutter - Flutter
- GoogleDataTransport (6.2.1) - GoogleDataTransport (7.5.1):
- GoogleDataTransportCCTSupport (3.2.0): - nanopb (~> 1.30906.0)
- GoogleDataTransport (~> 6.1) - GoogleUtilities/AppDelegateSwizzler (6.7.2):
- nanopb (~> 1.30905.0)
- GoogleUtilities/AppDelegateSwizzler (6.6.0):
- GoogleUtilities/Environment - GoogleUtilities/Environment
- GoogleUtilities/Logger - GoogleUtilities/Logger
- GoogleUtilities/Network - GoogleUtilities/Network
- GoogleUtilities/Environment (6.6.0): - GoogleUtilities/Environment (6.7.2):
- PromisesObjC (~> 1.2) - PromisesObjC (~> 1.2)
- GoogleUtilities/Logger (6.6.0): - GoogleUtilities/Logger (6.7.2):
- GoogleUtilities/Environment - GoogleUtilities/Environment
- GoogleUtilities/Network (6.6.0): - GoogleUtilities/Network (6.7.2):
- GoogleUtilities/Logger - GoogleUtilities/Logger
- "GoogleUtilities/NSData+zlib" - "GoogleUtilities/NSData+zlib"
- GoogleUtilities/Reachability - GoogleUtilities/Reachability
- "GoogleUtilities/NSData+zlib (6.6.0)" - "GoogleUtilities/NSData+zlib (6.7.2)"
- GoogleUtilities/Reachability (6.6.0): - GoogleUtilities/Reachability (6.7.2):
- GoogleUtilities/Logger - GoogleUtilities/Logger
- GoogleUtilities/UserDefaults (6.6.0): - GoogleUtilities/UserDefaults (6.7.2):
- GoogleUtilities/Logger - GoogleUtilities/Logger
- GTMSessionFetcher/Core (1.4.0) - GTMSessionFetcher/Core (1.5.0)
- nanopb (1.30905.0): - nanopb (1.30906.0):
- nanopb/decode (= 1.30905.0) - nanopb/decode (= 1.30906.0)
- nanopb/encode (= 1.30905.0) - nanopb/encode (= 1.30906.0)
- nanopb/decode (1.30905.0) - nanopb/decode (1.30906.0)
- nanopb/encode (1.30905.0) - nanopb/encode (1.30906.0)
- path_provider (0.0.1): - path_provider (0.0.1):
- Flutter - Flutter
- PromisesObjC (1.2.11) - PromisesObjC (1.2.11)
@ -116,28 +98,23 @@ DEPENDENCIES:
- firebase_auth (from `.symlinks/plugins/firebase_auth/ios`) - firebase_auth (from `.symlinks/plugins/firebase_auth/ios`)
- firebase_core (from `.symlinks/plugins/firebase_core/ios`) - firebase_core (from `.symlinks/plugins/firebase_core/ios`)
- firebase_messaging (from `.symlinks/plugins/firebase_messaging/ios`) - firebase_messaging (from `.symlinks/plugins/firebase_messaging/ios`)
- flurry (from `.symlinks/plugins/flurry/ios`)
- Flutter (from `Flutter`) - Flutter (from `Flutter`)
- flutter_facebook_auth (from `.symlinks/plugins/flutter_facebook_auth/ios`)
- flutter_keyboard_visibility (from `.symlinks/plugins/flutter_keyboard_visibility/ios`) - flutter_keyboard_visibility (from `.symlinks/plugins/flutter_keyboard_visibility/ios`)
- path_provider (from `.symlinks/plugins/path_provider/ios`) - path_provider (from `.symlinks/plugins/path_provider/ios`)
- shared_preferences (from `.symlinks/plugins/shared_preferences/ios`) - shared_preferences (from `.symlinks/plugins/shared_preferences/ios`)
SPEC REPOS: SPEC REPOS:
trunk: trunk:
- FBSDKCoreKit
- FBSDKLoginKit
- Firebase - Firebase
- FirebaseAnalyticsInterop
- FirebaseAuth - FirebaseAuth
- FirebaseAuthInterop
- FirebaseCore - FirebaseCore
- FirebaseCoreDiagnostics - FirebaseCoreDiagnostics
- FirebaseCoreDiagnosticsInterop
- FirebaseInstallations - FirebaseInstallations
- FirebaseInstanceID - FirebaseInstanceID
- FirebaseMessaging - FirebaseMessaging
- Flurry-iOS-SDK
- GoogleDataTransport - GoogleDataTransport
- GoogleDataTransportCCTSupport
- GoogleUtilities - GoogleUtilities
- GTMSessionFetcher - GTMSessionFetcher
- nanopb - nanopb
@ -153,10 +130,10 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/firebase_core/ios" :path: ".symlinks/plugins/firebase_core/ios"
firebase_messaging: firebase_messaging:
:path: ".symlinks/plugins/firebase_messaging/ios" :path: ".symlinks/plugins/firebase_messaging/ios"
flurry:
:path: ".symlinks/plugins/flurry/ios"
Flutter: Flutter:
:path: Flutter :path: Flutter
flutter_facebook_auth:
:path: ".symlinks/plugins/flutter_facebook_auth/ios"
flutter_keyboard_visibility: flutter_keyboard_visibility:
:path: ".symlinks/plugins/flutter_keyboard_visibility/ios" :path: ".symlinks/plugins/flutter_keyboard_visibility/ios"
path_provider: path_provider:
@ -166,29 +143,24 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS: SPEC CHECKSUMS:
devicelocale: feebbe5e7a30adb8c4f83185de1b50ff19b44f00 devicelocale: feebbe5e7a30adb8c4f83185de1b50ff19b44f00
FBSDKCoreKit: b46507dc8b8cefed31d644e74d7cc30e2a715ef8 Firebase: 8db6f2d1b2c5e2984efba4949a145875a8f65fe5
FBSDKLoginKit: 1a61d79e2b25e2fc0d03dccab1e34b38bbdf2546 firebase_auth: 240419f6b00dea39c60a2a9c4379c16c4a4b02fb
Firebase: 7cf5f9c67f03cb3b606d1d6535286e1080e57eb6 firebase_core: 350ba329d1641211bc6183a3236893cafdacfea7
firebase_auth: 8ae6798925da84bf8745668a73c936b148c1b04d firebase_messaging: 0aea2cd5885b65e19ede58ee3507f485c992cc75
firebase_core: 00e54a4744164a6b5a250b96dd1ad5afaba7a342 FirebaseAuth: c92d49ada7948d1a23466e3db17bc4c2039dddc3
firebase_messaging: 666d9994651b1ecf8c582b52dd913f3fa58c17ef FirebaseCore: d889d9e12535b7f36ac8bfbf1713a0836a3012cd
FirebaseAnalyticsInterop: 3f86269c38ae41f47afeb43ebf32a001f58fcdae FirebaseCoreDiagnostics: 770ac5958e1372ce67959ae4b4f31d8e127c3ac1
FirebaseAuth: 7047aec89c0b17ecd924a550c853f0c27ac6015e FirebaseInstallations: 466c7b4d1f58fe16707693091da253726a731ed2
FirebaseAuthInterop: a0f37ae05833af156e72028f648d313f7e7592e9 FirebaseInstanceID: bd3ffc24367f901a43c063b36c640b345a4a5dd1
FirebaseCore: f42e5e5f382cdcf6b617ed737bf6c871a6947b17 FirebaseMessaging: 5eca4ef173de76253352511aafef774caa1cba2a
FirebaseCoreDiagnostics: 4505e4d4009b1d93f605088ee7d7764d5f0d1c84 flurry: 15b01f664ab1367c62b50291541ea7f78ca85aad
FirebaseCoreDiagnosticsInterop: 296e2c5f5314500a850ad0b83e9e7c10b011a850 Flurry-iOS-SDK: 8f3f7fce27177002f15f145eede88dc1b9ac0cd0
FirebaseInstallations: 6f5f680e65dc374397a483c32d1799ba822a395b
FirebaseInstanceID: cef67c4967c7cecb56ea65d8acbb4834825c587b
FirebaseMessaging: 29543feb343b09546ab3aa04d008ee8595b43c44
Flutter: 0e3d915762c693b495b44d77113d4970485de6ec Flutter: 0e3d915762c693b495b44d77113d4970485de6ec
flutter_facebook_auth: 85c86b1f574faa5eaacd6de0db6b416fa94b326c
flutter_keyboard_visibility: 0339d06371254c3eb25eeb90ba8d17dca8f9c069 flutter_keyboard_visibility: 0339d06371254c3eb25eeb90ba8d17dca8f9c069
GoogleDataTransport: 9a8a16f79feffc7f42096743de2a7c4815e84020 GoogleDataTransport: f56af7caa4ed338dc8e138a5d7c5973e66440833
GoogleDataTransportCCTSupport: 489c1265d2c85b68187a83a911913d190012158d GoogleUtilities: 7f2f5a07f888cdb145101d6042bc4422f57e70b3
GoogleUtilities: 39530bc0ad980530298e9c4af8549e991fd033b1 GTMSessionFetcher: b3503b20a988c4e20cc189aa798fd18220133f52
GTMSessionFetcher: 6f5c8abbab8a9bce4bb3f057e317728ec6182b10 nanopb: 59317e09cf1f1a0af72f12af412d54edf52603fc
nanopb: c43f40fadfe79e8b8db116583945847910cbabc9
path_provider: abfe2b5c733d04e238b0d8691db0cfd63a27a93c path_provider: abfe2b5c733d04e238b0d8691db0cfd63a27a93c
PromisesObjC: 8c196f5a328c2cba3e74624585467a557dcb482f PromisesObjC: 8c196f5a328c2cba3e74624585467a557dcb482f
Protobuf: 3dac39b34a08151c6d949560efe3f86134a3f748 Protobuf: 3dac39b34a08151c6d949560efe3f86134a3f748

View File

@ -362,7 +362,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 32; CURRENT_PROJECT_VERSION = 33;
DEVELOPMENT_TEAM = SFJJBDCU6Z; DEVELOPMENT_TEAM = SFJJBDCU6Z;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = ( FRAMEWORK_SEARCH_PATHS = (
@ -505,7 +505,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 32; CURRENT_PROJECT_VERSION = 33;
DEVELOPMENT_TEAM = SFJJBDCU6Z; DEVELOPMENT_TEAM = SFJJBDCU6Z;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = ( FRAMEWORK_SEARCH_PATHS = (
@ -540,7 +540,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 32; CURRENT_PROJECT_VERSION = 33;
DEVELOPMENT_TEAM = SFJJBDCU6Z; DEVELOPMENT_TEAM = SFJJBDCU6Z;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = ( FRAMEWORK_SEARCH_PATHS = (

View File

@ -1,9 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<Workspace <Workspace
version = "1.0"> version = "1.0">
<FileRef
location = "group:/Users/tiborbossanyi/Development/projects/workouttest/aitrainer_app/ios/ .xcodeproj">
</FileRef>
<FileRef <FileRef
location = "group:Pods/Pods.xcodeproj"> location = "group:Pods/Pods.xcodeproj">
</FileRef> </FileRef>

View File

@ -1,5 +1,6 @@
import 'dart:async'; import 'dart:async';
import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/repository/customer_repository.dart'; import 'package:aitrainer_app/repository/customer_repository.dart';
import 'package:bloc/bloc.dart'; import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart'; import 'package:equatable/equatable.dart';
@ -77,6 +78,7 @@ class CustomerChangeBloc extends Bloc<CustomerChangeEvent, CustomerChangeState>
yield CustomerSaving(); yield CustomerSaving();
if (validation()) { if (validation()) {
await customerRepository.saveCustomer(); await customerRepository.saveCustomer();
Cache().initBadges();
yield CustomerSaveSuccess(); yield CustomerSaveSuccess();
} else { } else {
yield CustomerSaveError(message: "Please provide the necessary information"); yield CustomerSaveError(message: "Please provide the necessary information");

View File

@ -0,0 +1,51 @@
import 'dart:async';
import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/model/exercise_device.dart';
import 'package:aitrainer_app/repository/customer_exercise_device_repository.dart';
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
part 'customer_exercise_device_event.dart';
part 'customer_exercise_device_state.dart';
class CustomerExerciseDeviceBloc extends Bloc<CustomerExerciseDeviceEvent, CustomerExerciseDeviceState> {
final CustomerExerciseDeviceRepository repository;
final List<ExerciseDevice> devices;
CustomerExerciseDeviceBloc({this.repository, this.devices}) : super(CustomerExerciseDeviceInitial()) {
if (repository.getDevices().isEmpty) {
repository.setDevices(Cache().getCustomerDevices());
}
}
@override
Stream<CustomerExerciseDeviceState> mapEventToState(
CustomerExerciseDeviceEvent event,
) async* {
try {
if (event is CustomerExerciseDeviceLoad) {
yield CustomerExerciseDeviceLoading();
yield CustomerExerciseDeviceReady();
} else if (event is CustomerExerciseDeviceAdd) {
yield CustomerExerciseDeviceLoading();
print("Add device " + event.device.exerciseDeviceId.toString());
await repository.addDevice(event.device);
Cache().initBadges();
yield CustomerExerciseDeviceReady();
} else if (event is CustomerExerciseDeviceRemove) {
print("Remove device " + event.device.exerciseDeviceId.toString());
yield CustomerExerciseDeviceLoading();
await repository.removeDevice(event.device);
Cache().initBadges();
yield CustomerExerciseDeviceReady();
}
} on Exception catch (ex) {
yield CustomerExerciseDeviceError(message: ex.toString());
}
}
bool hasCustomerDevice(int exerciseDeviceId) {
return repository.hasDevice(exerciseDeviceId);
}
}

View File

@ -0,0 +1,32 @@
part of 'customer_exercise_device_bloc.dart';
abstract class CustomerExerciseDeviceEvent extends Equatable {
const CustomerExerciseDeviceEvent();
@override
List<Object> get props => [];
}
class CustomerExerciseDeviceLoad extends CustomerExerciseDeviceEvent {
const CustomerExerciseDeviceLoad();
}
class CustomerExerciseDeviceAdd extends CustomerExerciseDeviceEvent {
final ExerciseDevice device;
const CustomerExerciseDeviceAdd({this.device});
@override
List<Object> get props => [device];
}
class CustomerExerciseDeviceRemove extends CustomerExerciseDeviceEvent {
final ExerciseDevice device;
const CustomerExerciseDeviceRemove({this.device});
@override
List<Object> get props => [device];
}
class CustomerExerciseDeviceSave extends CustomerExerciseDeviceEvent {
const CustomerExerciseDeviceSave();
}

View File

@ -0,0 +1,28 @@
part of 'customer_exercise_device_bloc.dart';
abstract class CustomerExerciseDeviceState extends Equatable {
const CustomerExerciseDeviceState();
@override
List<Object> get props => [];
}
class CustomerExerciseDeviceInitial extends CustomerExerciseDeviceState {
const CustomerExerciseDeviceInitial();
}
class CustomerExerciseDeviceLoading extends CustomerExerciseDeviceState {
const CustomerExerciseDeviceLoading();
}
class CustomerExerciseDeviceReady extends CustomerExerciseDeviceState {
const CustomerExerciseDeviceReady();
}
class CustomerExerciseDeviceError extends CustomerExerciseDeviceState {
final String message;
const CustomerExerciseDeviceError({this.message});
@override
List<Object> get props => [message];
}

View File

@ -7,6 +7,7 @@ import 'package:aitrainer_app/repository/exercise_plan_repository.dart';
import 'package:aitrainer_app/repository/exercise_repository.dart'; import 'package:aitrainer_app/repository/exercise_repository.dart';
import 'package:bloc/bloc.dart'; import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart'; import 'package:equatable/equatable.dart';
import 'package:flurry/flurry.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
part 'exercise_execute_plan_add_event.dart'; part 'exercise_execute_plan_add_event.dart';
@ -30,16 +31,12 @@ class ExerciseExecutePlanAddBloc extends Bloc<ExerciseExecutePlanAddEvent, Exerc
double scrollOffset = 0; double scrollOffset = 0;
@override @override
ExerciseExecutePlanAddBloc({ ExerciseExecutePlanAddBloc({this.exerciseRepository, this.exercisePlanRepository, this.customerId, this.workoutTree, this.planBloc})
this.exerciseRepository, : super(ExerciseExecutePlanAddInitial()) {
this.exercisePlanRepository,
this.customerId,
this.workoutTree,
this.planBloc}): super(ExerciseExecutePlanAddInitial()) {
exerciseRepository.exerciseType = workoutTree.exerciseType; exerciseRepository.exerciseType = workoutTree.exerciseType;
if ( Cache().userLoggedIn.customerId == customerId) { if (Cache().userLoggedIn.customerId == customerId) {
customer = Cache().userLoggedIn; customer = Cache().userLoggedIn;
} else if ( Cache().getTrainee().customerId == customerId) { } else if (Cache().getTrainee().customerId == customerId) {
customer = Cache().getTrainee(); customer = Cache().getTrainee();
} }
exercisePlanRepository.setActualPlanDetailByExerciseType(workoutTree.exerciseType); exercisePlanRepository.setActualPlanDetailByExerciseType(workoutTree.exerciseType);
@ -71,12 +68,12 @@ class ExerciseExecutePlanAddBloc extends Bloc<ExerciseExecutePlanAddEvent, Exerc
yield ExerciseExecutePlanAddReady(); yield ExerciseExecutePlanAddReady();
} else if (event is ExerciseExecutePlanAddSubmit) { } else if (event is ExerciseExecutePlanAddSubmit) {
yield ExerciseExecutePlanAddLoading(); yield ExerciseExecutePlanAddLoading();
exerciseRepository.exercise.exercisePlanDetailId = exerciseRepository.exercise.exercisePlanDetailId = exercisePlanRepository.getActualPlanDetail().exercisePlanDetailId;
exercisePlanRepository.getActualPlanDetail().exercisePlanDetailId;
exerciseRepository.exercise.unit = workoutTree.exerciseType.unit; exerciseRepository.exercise.unit = workoutTree.exerciseType.unit;
workoutTree.executed = true; workoutTree.executed = true;
print("On Submitting Exercise Execute Plan Add " + exerciseRepository.exercise.toJson().toString()); print("On Submitting Exercise Execute Plan Add " + exerciseRepository.exercise.toJson().toString());
await exerciseRepository.addExercise(); await exerciseRepository.addExercise();
Flurry.logEvent("ExecuteExercisePlan");
step++; step++;
scrollOffset = step * 200.0; scrollOffset = step * 200.0;
planBloc.add(ExerciseByPlanLoad()); planBloc.add(ExerciseByPlanLoad());

View File

@ -8,6 +8,7 @@ import 'package:aitrainer_app/repository/customer_repository.dart';
import 'package:aitrainer_app/repository/exercise_repository.dart'; import 'package:aitrainer_app/repository/exercise_repository.dart';
import 'package:bloc/bloc.dart'; import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart'; import 'package:equatable/equatable.dart';
import 'package:flurry/flurry.dart';
import 'package:flutter/animation.dart'; import 'package:flutter/animation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_form_bloc/flutter_form_bloc.dart'; import 'package:flutter_form_bloc/flutter_form_bloc.dart';
@ -266,6 +267,8 @@ class ExerciseNewBloc extends Bloc<ExerciseNewEvent, ExerciseNewState> {
customerRepository.saveCustomer(); customerRepository.saveCustomer();
changedWeight = false; changedWeight = false;
this.changedSizes = false; this.changedSizes = false;
Cache().initBadges();
Flurry.logEvent("Sizes");
yield ExerciseNewReady(); yield ExerciseNewReady();
} else if (event is ExerciseNewSizeChange) { } else if (event is ExerciseNewSizeChange) {
yield ExerciseNewLoading(); yield ExerciseNewLoading();
@ -277,6 +280,8 @@ class ExerciseNewBloc extends Bloc<ExerciseNewEvent, ExerciseNewState> {
yield ExerciseNewLoading(); yield ExerciseNewLoading();
await exerciseRepository.addExercise(); await exerciseRepository.addExercise();
menuBloc.add(MenuTreeDown(parent: 0)); menuBloc.add(MenuTreeDown(parent: 0));
Cache().initBadges();
Flurry.logEvent("newExercise");
yield ExerciseNewReady(); yield ExerciseNewReady();
} else if (event is ExerciseNewBMIAnimate) { } else if (event is ExerciseNewBMIAnimate) {
yield ExerciseNewLoading(); yield ExerciseNewLoading();
@ -288,7 +293,7 @@ class ExerciseNewBloc extends Bloc<ExerciseNewEvent, ExerciseNewState> {
} }
double getBMI() { double getBMI() {
if (height == 0) { if (height == 0 || weight == 0) {
this.bmi = 0; this.bmi = 0;
return 0; return 0;
} }
@ -299,6 +304,10 @@ class ExerciseNewBloc extends Bloc<ExerciseNewEvent, ExerciseNewState> {
double getBMR() { double getBMR() {
var date = DateTime.now(); var date = DateTime.now();
if (height == 0 || weight == 0) {
this.bmi = 0;
return 0;
}
int year = int.parse(DateFormat(DateFormat.YEAR).format(date)); int year = int.parse(DateFormat(DateFormat.YEAR).format(date));
@ -334,14 +343,15 @@ class ExerciseNewBloc extends Bloc<ExerciseNewEvent, ExerciseNewState> {
this.bmiLeft = 72; this.bmiLeft = 72;
bmiAngle = -62; bmiAngle = -62;
} else if (bmi < 25 && 18.5 < bmi) { } else if (bmi < 25 && 18.5 < bmi) {
goalBMI = bmi; goalBMI = 27;
this.bmiTop = 46; this.bmiTop = 46;
this.bmiLeft = 130; this.bmiLeft = 130;
bmiAngle = -21; bmiAngle = -23;
} else if (bmi < 30 && 24.9 < bmi) { } else if (bmi < 30 && 24.9 < bmi) {
goalBMI = 24; goalBMI = 24;
this.bmiTop = 38.0; this.bmiTop = 38.0;
this.bmiLeft = 186.0; this.bmiLeft = 186.0;
bmiAngle = 7.2;
} else if (bmi < 34.9 && 29.9 < bmi) { } else if (bmi < 34.9 && 29.9 < bmi) {
goalBMI = 29; goalBMI = 29;
bmiTop = 48; bmiTop = 48;

View File

@ -1,10 +1,12 @@
import 'dart:async'; import 'dart:async';
import 'package:aitrainer_app/model/exercise_plan_detail.dart'; import 'package:aitrainer_app/model/exercise_plan_detail.dart';
import 'package:aitrainer_app/model/model_change.dart';
import 'package:aitrainer_app/model/workout_menu_tree.dart'; import 'package:aitrainer_app/model/workout_menu_tree.dart';
import 'package:aitrainer_app/repository/exercise_plan_repository.dart'; import 'package:aitrainer_app/repository/exercise_plan_repository.dart';
import 'package:aitrainer_app/repository/workout_tree_repository.dart'; import 'package:aitrainer_app/repository/workout_tree_repository.dart';
import 'package:bloc/bloc.dart'; import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart'; import 'package:equatable/equatable.dart';
import 'package:flurry/flurry.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
part 'exercise_plan_event.dart'; part 'exercise_plan_event.dart';
@ -31,7 +33,7 @@ class ExercisePlanBloc extends Bloc<ExercisePlanEvent, ExercisePlanState> {
workoutTree.selected = false; workoutTree.selected = false;
if (exercisePlanRepository.getExercisePlanDetailSize() > 0) { if (exercisePlanRepository.getExercisePlanDetailSize() > 0) {
ExercisePlanDetail planDetail = exercisePlanRepository.getExercisePlanDetailByExerciseId(workoutTree.exerciseTypeId); ExercisePlanDetail planDetail = exercisePlanRepository.getExercisePlanDetailByExerciseId(workoutTree.exerciseTypeId);
if (planDetail != null && planDetail.change != ExercisePlanDetailChange.deleted) { if (planDetail != null && planDetail.change != ModelChange.deleted) {
workoutTree.selected = true; workoutTree.selected = true;
} }
} }
@ -39,7 +41,7 @@ class ExercisePlanBloc extends Bloc<ExercisePlanEvent, ExercisePlanState> {
}); });
} }
void setExercisePlanRepository(ExercisePlanRepository repo ) => exercisePlanRepository = repo; void setExercisePlanRepository(ExercisePlanRepository repo) => exercisePlanRepository = repo;
@override @override
Stream<ExercisePlanState> mapEventToState(ExercisePlanEvent event) async* { Stream<ExercisePlanState> mapEventToState(ExercisePlanEvent event) async* {
@ -60,9 +62,7 @@ class ExercisePlanBloc extends Bloc<ExercisePlanEvent, ExercisePlanState> {
} }
yield ExercisePlanReady(); yield ExercisePlanReady();
} } else if (event is ExercisePlanAddExercise) {
else if (event is ExercisePlanAddExercise) {
yield ExercisePlanLoading(); yield ExercisePlanLoading();
ExercisePlanDetail planDetail = event.exercisePlanDetail; ExercisePlanDetail planDetail = event.exercisePlanDetail;
exercisePlanRepository.actualPlanDetail = planDetail; exercisePlanRepository.actualPlanDetail = planDetail;
@ -74,16 +74,14 @@ class ExercisePlanBloc extends Bloc<ExercisePlanEvent, ExercisePlanState> {
this.menuTreeRepository.sortedTree.forEach((key, value) { this.menuTreeRepository.sortedTree.forEach((key, value) {
List<WorkoutMenuTree> listTreeItem = value; List<WorkoutMenuTree> listTreeItem = value;
listTreeItem.forEach((element) { listTreeItem.forEach((element) {
if ( element.exerciseType.exerciseTypeId == planDetail.exerciseTypeId) { if (element.exerciseType.exerciseTypeId == planDetail.exerciseTypeId) {
element.selected = true; element.selected = true;
} }
}); });
}); });
yield ExercisePlanReady(); yield ExercisePlanReady();
} } else if (event is ExercisePlanRemoveExercise) {
else if (event is ExercisePlanRemoveExercise) {
yield ExercisePlanLoading(); yield ExercisePlanLoading();
ExercisePlanDetail planDetail = event.exercisePlanDetail; ExercisePlanDetail planDetail = event.exercisePlanDetail;
exercisePlanRepository.removeExerciseTypeFromPlanByExerciseTypeId(planDetail.exerciseTypeId); exercisePlanRepository.removeExerciseTypeFromPlanByExerciseTypeId(planDetail.exerciseTypeId);
@ -91,7 +89,7 @@ class ExercisePlanBloc extends Bloc<ExercisePlanEvent, ExercisePlanState> {
this.menuTreeRepository.sortedTree.forEach((key, value) { this.menuTreeRepository.sortedTree.forEach((key, value) {
List<WorkoutMenuTree> listTreeItem = value; List<WorkoutMenuTree> listTreeItem = value;
listTreeItem.forEach((element) { listTreeItem.forEach((element) {
if ( element.exerciseType.exerciseTypeId == planDetail.exerciseTypeId) { if (element.exerciseType.exerciseTypeId == planDetail.exerciseTypeId) {
element.selected = false; element.selected = false;
} }
}); });
@ -99,12 +97,11 @@ class ExercisePlanBloc extends Bloc<ExercisePlanEvent, ExercisePlanState> {
if (exercisePlanRepository.getExercisePlanDetailSize() != 0) { if (exercisePlanRepository.getExercisePlanDetailSize() != 0) {
exercisePlanRepository.saveExercisePlan(); exercisePlanRepository.saveExercisePlan();
Flurry.logEvent("SaveExercisePlan");
} }
yield ExercisePlanReady(); yield ExercisePlanReady();
} }
} on Exception catch (e) { } on Exception catch (e) {
yield ExercisePlanError(message: e.toString()); yield ExercisePlanError(message: e.toString());
} }

View File

@ -59,6 +59,7 @@ class LoginFormBloc extends FormBloc<String, String> with Common {
} }
emitSuccess(canSubmitAgain: false); emitSuccess(canSubmitAgain: false);
accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn)); accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn));
Cache().initBadges();
} }
} on Exception catch (ex) { } on Exception catch (ex) {
emitFailure(failureResponse: ex.toString()); emitFailure(failureResponse: ex.toString());

View File

@ -11,18 +11,13 @@ class RegistrationFormBloc extends FormBloc<String, String> with Common {
FieldBlocValidators.required, FieldBlocValidators.required,
], ],
); );
final passwordField = TextFieldBloc( final passwordField = TextFieldBloc(validators: [
validators: [
FieldBlocValidators.required, FieldBlocValidators.required,
] ]);
);
final UserRepository userRepository; final UserRepository userRepository;
RegistrationFormBloc({this.userRepository, this.accountBloc}) { RegistrationFormBloc({this.userRepository, this.accountBloc}) {
addFieldBlocs(fieldBlocs: [ addFieldBlocs(fieldBlocs: [emailField, passwordField]);
emailField,
passwordField
]);
emailField.onValueChanges(onData: (previous, current) async* { emailField.onValueChanges(onData: (previous, current) async* {
userRepository.setEmail(current.value); userRepository.setEmail(current.value);
@ -31,18 +26,17 @@ class RegistrationFormBloc extends FormBloc<String, String> with Common {
passwordField.onValueChanges(onData: (previous, current) async* { passwordField.onValueChanges(onData: (previous, current) async* {
userRepository.setPassword(current.value); userRepository.setPassword(current.value);
}); });
} }
@override @override
void onSubmitting() async { void onSubmitting() async {
try { try {
emitLoading(progress: 30); emitLoading(progress: 30);
if ( ! validateEmail(userRepository)) { if (!validateEmail(userRepository)) {
emailField.addFieldError(EMAIL_ERROR, isPermanent: true); emailField.addFieldError(EMAIL_ERROR, isPermanent: true);
emitFailure(failureResponse: EMAIL_ERROR); emitFailure(failureResponse: EMAIL_ERROR);
} else if ( ! validatePassword(userRepository)) { } else if (!validatePassword(userRepository)) {
passwordField.addFieldError(PASSWORD_ERROR, isPermanent: true); passwordField.addFieldError(PASSWORD_ERROR, isPermanent: true);
emitFailure(failureResponse: PASSWORD_ERROR); emitFailure(failureResponse: PASSWORD_ERROR);
} else { } else {
@ -50,12 +44,10 @@ class RegistrationFormBloc extends FormBloc<String, String> with Common {
await userRepository.addUser(); await userRepository.addUser();
emitSuccess(canSubmitAgain: false); emitSuccess(canSubmitAgain: false);
accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn)); accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn));
Cache().initBadges();
} }
} on Exception catch (ex) { } on Exception catch (ex) {
emitFailure(failureResponse: ex.toString()); emitFailure(failureResponse: ex.toString());
} }
} }
} }

View File

@ -1,5 +1,4 @@
import 'dart:async'; import 'dart:async';
import 'package:aitrainer_app/bloc/customer_exercise_device/customer_exercise_device_bloc.dart';
import 'package:aitrainer_app/push_notifications.dart'; import 'package:aitrainer_app/push_notifications.dart';
import 'package:aitrainer_app/repository/customer_repository.dart'; import 'package:aitrainer_app/repository/customer_repository.dart';
import 'package:aitrainer_app/repository/workout_tree_repository.dart'; import 'package:aitrainer_app/repository/workout_tree_repository.dart';
@ -31,8 +30,7 @@ import 'package:aitrainer_app/view/registration.dart';
import 'package:aitrainer_app/view/reset_password.dart'; import 'package:aitrainer_app/view/reset_password.dart';
import 'package:aitrainer_app/view/settings.dart'; import 'package:aitrainer_app/view/settings.dart';
import 'package:aitrainer_app/widgets/home.dart'; import 'package:aitrainer_app/widgets/home.dart';
//import 'package:firebase_analytics/firebase_analytics.dart'; import 'package:flurry/flurry.dart';
//import 'package:firebase_analytics/observer.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
@ -143,18 +141,25 @@ Future<Null> main() async {
create: (BuildContext context) => BodyDevelopmentBloc(workoutTreeRepository: menuTreeRepository), create: (BuildContext context) => BodyDevelopmentBloc(workoutTreeRepository: menuTreeRepository),
), ),
], ],
child: AitrainerApp(), child: WorkoutTestApp(),
)); ));
}, (error, stackTrace) async { }, (error, stackTrace) async {
await _reportError(error, stackTrace); await _reportError(error, stackTrace);
}); });
} }
class AitrainerApp extends StatelessWidget { Future<void> initFlurry() async {
await Flurry.initialize(androidKey: "JNYCTCWBT34FM3J8TV36", iosKey: "3QBG7BSMGPDH24S8TRQP", enableLog: true);
//await Flurry.setUserId("userId");
//await Flurry.logEvent("eventName");
}
class WorkoutTestApp extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
//final FirebaseAnalytics analytics = FirebaseAnalytics(); //final FirebaseAnalytics analytics = FirebaseAnalytics();
initFlurry();
PushNotificationsManager().init(); PushNotificationsManager().init();
return MaterialApp( return MaterialApp(
localizationsDelegates: [ localizationsDelegates: [

View File

@ -4,15 +4,22 @@ import 'package:aitrainer_app/model/exercise_plan.dart';
import 'package:aitrainer_app/model/exercise_plan_detail.dart'; import 'package:aitrainer_app/model/exercise_plan_detail.dart';
import 'package:aitrainer_app/model/exercise_tree.dart'; import 'package:aitrainer_app/model/exercise_tree.dart';
import 'package:aitrainer_app/model/exercise.dart'; import 'package:aitrainer_app/model/exercise.dart';
import 'package:aitrainer_app/model/model_change.dart';
import 'package:aitrainer_app/model/property.dart'; import 'package:aitrainer_app/model/property.dart';
import 'package:aitrainer_app/model/workout_menu_tree.dart'; import 'package:aitrainer_app/model/workout_menu_tree.dart';
import 'package:aitrainer_app/repository/customer_repository.dart';
import 'package:aitrainer_app/repository/exercise_repository.dart'; import 'package:aitrainer_app/repository/exercise_repository.dart';
import 'package:aitrainer_app/service/customer_exercise_device_service.dart';
import 'package:aitrainer_app/service/exercise_tree_service.dart'; import 'package:aitrainer_app/service/exercise_tree_service.dart';
import 'package:aitrainer_app/service/exercisetype_service.dart'; import 'package:aitrainer_app/service/exercisetype_service.dart';
import 'package:aitrainer_app/util/env.dart'; import 'package:aitrainer_app/util/env.dart';
import 'package:flurry/flurry.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:aitrainer_app/model/exercise_type.dart'; import 'package:aitrainer_app/model/exercise_type.dart';
import 'customer_exercise_device.dart';
import 'exercise_device.dart';
enum SharePrefsChange { enum SharePrefsChange {
login, login,
registration, registration,
@ -64,6 +71,8 @@ class Cache {
List<Exercise> _exercises; List<Exercise> _exercises;
ExercisePlan _myExercisePlan; ExercisePlan _myExercisePlan;
List<Property> _properties; List<Property> _properties;
List<ExerciseDevice> _devices;
List<CustomerExerciseDevice> _customerDevices;
LinkedHashMap<int, ExercisePlanDetail> _myExercisesPlanDetails = LinkedHashMap<int, ExercisePlanDetail>(); LinkedHashMap<int, ExercisePlanDetail> _myExercisesPlanDetails = LinkedHashMap<int, ExercisePlanDetail>();
@ -75,6 +84,8 @@ class Cache {
ExercisePlan _traineeExercisePlan; ExercisePlan _traineeExercisePlan;
List<ExercisePlanDetail> _traineeExercisesPlanDetail; List<ExercisePlanDetail> _traineeExercisesPlanDetail;
LinkedHashMap<String, int> _badges = LinkedHashMap();
List deviceLanguages; List deviceLanguages;
String startPage; String startPage;
@ -158,7 +169,10 @@ class Cache {
sharedPreferences.setString(Cache.firebaseUidKey, firebaseUid); sharedPreferences.setString(Cache.firebaseUidKey, firebaseUid);
await ExerciseTypeApi().getExerciseTypes(); await ExerciseTypeApi().getExerciseTypes();
await ExerciseTreeApi().getExerciseTree(); await ExerciseTreeApi().getExerciseTree();
final customerDevices = await CustomerExerciseDeviceApi().getDevices(customerId);
Cache().setCustomerDevices(customerDevices);
await exerciseRepository.getExercisesByCustomer(customerId); await exerciseRepository.getExercisesByCustomer(customerId);
Flurry.setUserId(customerId.toString());
} else if (type == SharePrefsChange.login) { } else if (type == SharePrefsChange.login) {
Cache().startPage = "home"; Cache().startPage = "home";
sharedPreferences.setInt(Cache.customerIdKey, customerId); sharedPreferences.setInt(Cache.customerIdKey, customerId);
@ -166,13 +180,17 @@ class Cache {
sharedPreferences.setBool(Cache.isLoggedInKey, true); sharedPreferences.setBool(Cache.isLoggedInKey, true);
await ExerciseTypeApi().getExerciseTypes(); await ExerciseTypeApi().getExerciseTypes();
await ExerciseTreeApi().getExerciseTree(); await ExerciseTreeApi().getExerciseTree();
final customerDevices = await CustomerExerciseDeviceApi().getDevices(customerId);
Cache().setCustomerDevices(customerDevices);
await exerciseRepository.getExercisesByCustomer(customerId); await exerciseRepository.getExercisesByCustomer(customerId);
Flurry.setUserId(customerId.toString());
} else if (type == SharePrefsChange.logout) { } else if (type == SharePrefsChange.logout) {
sharedPreferences.setBool(Cache.isLoggedInKey, false); sharedPreferences.setBool(Cache.isLoggedInKey, false);
sharedPreferences.setInt(Cache.customerIdKey, 0); sharedPreferences.setInt(Cache.customerIdKey, 0);
sharedPreferences.setString(Cache.firebaseUidKey, null); sharedPreferences.setString(Cache.firebaseUidKey, null);
sharedPreferences.setString(authTokenKey, ""); sharedPreferences.setString(authTokenKey, "");
} }
initBadges();
} }
void setExerciseTypes(List<ExerciseType> exerciseTypes) { void setExerciseTypes(List<ExerciseType> exerciseTypes) {
@ -241,13 +259,85 @@ class Cache {
void deleteMyExercisePlanDetail(ExercisePlanDetail detail) => this.deleteMyExercisePlanDetailByExerciseTypeId(detail.exerciseTypeId); void deleteMyExercisePlanDetail(ExercisePlanDetail detail) => this.deleteMyExercisePlanDetailByExerciseTypeId(detail.exerciseTypeId);
void deletedMyExercisePlanDetail(ExercisePlanDetail detail) => void deletedMyExercisePlanDetail(ExercisePlanDetail detail) =>
this._myExercisesPlanDetails[detail.exerciseTypeId].change = ExercisePlanDetailChange.deleted; this._myExercisesPlanDetails[detail.exerciseTypeId].change = ModelChange.deleted;
void deleteMyExercisePlanDetailByExerciseTypeId(int exerciseTypeId) { void deleteMyExercisePlanDetailByExerciseTypeId(int exerciseTypeId) {
this._myExercisesPlanDetails[exerciseTypeId].change = ExercisePlanDetailChange.delete; this._myExercisesPlanDetails[exerciseTypeId].change = ModelChange.delete;
} }
void setProperties(List<Property> properties) => this._properties = properties; void setProperties(List<Property> properties) => this._properties = properties;
List<Property> getProperties() => _properties; List<Property> getProperties() => _properties;
void setDevices(List<ExerciseDevice> devices) => this._devices = devices;
List<ExerciseDevice> getDevices() => this._devices;
void setCustomerDevices(List<CustomerExerciseDevice> devices) => this._customerDevices = devices;
List<CustomerExerciseDevice> getCustomerDevices() => this._customerDevices;
LinkedHashMap getBadges() => _badges;
void setBadge(String key, bool inc) {
if (inc) {
if (_badges[key] != null) {
_badges[key]++;
} else {
_badges[key] = 1;
}
} else {
if (_badges[key] != null) {
if (_badges[key] == 1) {
_badges.remove(key);
} else {
_badges[key]--;
}
}
}
}
void setBadgeNr(String key, int counter) {
if (_badges[key] != null) {
_badges[key] += counter;
} else {
_badges[key] = counter;
}
}
void initBadges() {
CustomerRepository customerRepository = CustomerRepository();
_badges = LinkedHashMap();
customerRepository.setCustomer(userLoggedIn);
if (this.userLoggedIn != null) {
if (this.userLoggedIn.firstname == null || userLoggedIn.firstname.length == 0) {
setBadge("personalData", true);
setBadge("account", true);
}
if (this._customerDevices == null || this._customerDevices.isEmpty) {
setBadge("customerDevice", true);
setBadge("account", true);
}
if (userLoggedIn.properties == null || userLoggedIn.properties.isEmpty) {
setBadge("personalData", true);
setBadge("Sizes", true);
setBadge("BMI", true);
setBadge("BMR", true);
setBadgeNr("Body Compositions", 3);
setBadgeNr("home", 3);
} else if (customerRepository.getWeight() == 0) {
setBadge("BMI", true);
setBadge("BMR", true);
setBadge("Body Compositions", true);
setBadgeNr("home", 1);
}
if (customerRepository.getHeight() == 0) {
setBadge("BMI", true);
setBadge("BMR", true);
setBadge("Body Compositions", true);
setBadgeNr("home", 1);
}
}
print("Badges: " + _badges.toString());
}
} }

View File

@ -0,0 +1,42 @@
import 'package:flutter_form_bloc/flutter_form_bloc.dart';
class CustomerExerciseDevice {
int customerExerciseDeviceId;
int exerciseDeviceId;
int customerId;
bool favourite;
DateTime dateAdd;
String change;
CustomerExerciseDevice({this.exerciseDeviceId, this.customerId, this.favourite}) {
dateAdd = DateTime.now();
}
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']);
}
Map<String, dynamic> toJson() {
if (customerExerciseDeviceId == null) {
return {
"exerciseDeviceId": exerciseDeviceId,
"customerId": customerId,
"favourite": favourite == true ? 1 : 0,
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateAdd),
};
} else {
return {
"customerExerciseDeviceId": customerExerciseDeviceId,
"exerciseDeviceId": exerciseDeviceId,
"customerId": customerId,
"favourite": favourite == true ? 1 : 0,
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateAdd),
};
}
}
}

View File

@ -0,0 +1,19 @@
class ExerciseDevice {
int exerciseDeviceId;
String name;
String description;
String imageUrl;
String nameTranslation;
int sort;
bool place;
ExerciseDevice.fromJson(Map json) {
this.exerciseDeviceId = json['exerciseDeviceId'];
this.name = json['name'];
this.description = json['description'];
this.imageUrl = json['imageUrl'];
this.nameTranslation = json['translations'][0]['name'];
this.sort = json['sort'];
this.place = json['place'] == 1 ? true : false;
}
}

View File

@ -21,19 +21,18 @@ class ExercisePlan {
this.name = json['name']; this.name = json['name'];
this.private = json['private']; this.private = json['private'];
this.description = json['description']; this.description = json['description'];
this.dateAdd = json['dateAdd'] == null ? null : DateTime.parse( json['dateAdd'] ); this.dateAdd = json['dateAdd'] == null ? null : DateTime.parse(json['dateAdd']);
this.dateUpd = json['dateUpd'] == null ? null : DateTime.parse( json['dateUpd'] ); this.dateUpd = json['dateUpd'] == null ? null : DateTime.parse(json['dateUpd']);
} }
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
String formattedDateAdd; String formattedDateAdd;
if ( dateAdd != null) { if (dateAdd != null) {
formattedDateAdd = DateFormat('yyyy-MM-dd HH:mm').format(dateAdd); formattedDateAdd = DateFormat('yyyy-MM-dd HH:mm').format(dateAdd);
} }
String formattedDateUpd = DateFormat('yyyy-MM-dd HH:mm').format(dateUpd); String formattedDateUpd = DateFormat('yyyy-MM-dd HH:mm').format(dateUpd);
print("DateAdd $formattedDateAdd"); if (exercisePlanId == null) {
if ( exercisePlanId == null ) {
return { return {
"customerId": customerId, "customerId": customerId,
"name": name, "name": name,
@ -54,5 +53,4 @@ class ExercisePlan {
}; };
} }
} }
} }

View File

@ -1,13 +1,5 @@
import 'exercise_type.dart'; import 'exercise_type.dart';
class ExercisePlanDetailChange {
static const String add = "add";
static const String delete = "delete";
static const String update = "update";
static const String deleted = "deleted";
static const String saved = "saved";
}
class ExercisePlanDetail { class ExercisePlanDetail {
int exercisePlanDetailId; int exercisePlanDetailId;
int exercisePlanId; int exercisePlanId;
@ -32,8 +24,7 @@ class ExercisePlanDetail {
this.weightEquation = json['weightEquation']; this.weightEquation = json['weightEquation'];
} }
Map<String, dynamic> toJson() => Map<String, dynamic> toJson() => {
{
"exercisePlanId": exercisePlanId, "exercisePlanId": exercisePlanId,
"exerciseTypeId": exerciseTypeId, "exerciseTypeId": exerciseTypeId,
"serie": serie, "serie": serie,

View File

@ -1,5 +1,3 @@
import 'package:flutter/semantics.dart';
class FitnessState { class FitnessState {
final String value; final String value;
final String stateText; final String stateText;

View File

@ -0,0 +1,7 @@
class ModelChange {
static const String add = "add";
static const String delete = "delete";
static const String update = "update";
static const String deleted = "deleted";
static const String saved = "saved";
}

View File

@ -0,0 +1,76 @@
import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/model/customer_exercise_device.dart';
import 'package:aitrainer_app/model/exercise_device.dart';
import 'package:aitrainer_app/model/model_change.dart';
import 'package:aitrainer_app/service/customer_exercise_device_service.dart';
class CustomerExerciseDeviceRepository {
List<CustomerExerciseDevice> _devices = List();
List<CustomerExerciseDevice> getDevices() => this._devices;
void setDevices(List<CustomerExerciseDevice> devices) => this._devices = devices;
Future<List<CustomerExerciseDevice>> getDBDevices() async {
if (Cache().userLoggedIn != null) {
final int customerId = Cache().userLoggedIn.customerId;
this._devices = await CustomerExerciseDeviceApi().getDevices(customerId);
}
return this._devices;
}
Future<void> addDevice(ExerciseDevice device) async {
CustomerExerciseDevice found;
if (_devices != null) {
this._devices.forEach((element) {
if (element.exerciseDeviceId == device.exerciseDeviceId) {
found = element;
}
});
}
if (found == null) {
int customerId;
if (Cache().userLoggedIn != null) {
customerId = Cache().userLoggedIn.customerId;
}
CustomerExerciseDevice newDevice =
CustomerExerciseDevice(customerId: customerId, exerciseDeviceId: device.exerciseDeviceId, favourite: false);
newDevice.change = ModelChange.add;
await CustomerExerciseDeviceApi().addDevice(newDevice);
this._devices.add(newDevice);
Cache().setCustomerDevices(_devices);
}
}
Future<void> removeDevice(ExerciseDevice device) async {
print("Remove " + device.name);
CustomerExerciseDevice found;
if (_devices != null) {
this._devices.forEach((element) {
if (element.exerciseDeviceId == device.exerciseDeviceId) {
found = element;
}
});
}
if (found != null) {
this._devices.remove(found);
if (found.change != ModelChange.add) {
await CustomerExerciseDeviceApi().removeDevice(found.customerExerciseDeviceId);
}
Cache().setCustomerDevices(_devices);
}
}
bool hasDevice(int exerciseDeviceId) {
bool found = false;
if (_devices != null) {
this._devices.forEach((element) {
if (element.exerciseDeviceId == exerciseDeviceId) {
found = true;
}
});
}
return found;
}
}

View File

@ -0,0 +1,15 @@
import 'package:aitrainer_app/model/exercise_device.dart';
import 'package:aitrainer_app/service/exercise_device_service.dart';
class ExerciseDeviceRepository {
List<ExerciseDevice> _devices = List();
List<ExerciseDevice> getDevices() {
return this._devices;
}
Future<List<ExerciseDevice>> getDBDevices() async {
this._devices = await ExerciseDeviceApi().getDevices();
return this._devices;
}
}

View File

@ -4,17 +4,17 @@ import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/model/exercise_plan.dart'; import 'package:aitrainer_app/model/exercise_plan.dart';
import 'package:aitrainer_app/model/exercise_plan_detail.dart'; import 'package:aitrainer_app/model/exercise_plan_detail.dart';
import 'package:aitrainer_app/model/exercise_type.dart'; import 'package:aitrainer_app/model/exercise_type.dart';
import 'package:aitrainer_app/model/model_change.dart';
import 'package:aitrainer_app/service/exercise_plan_service.dart'; import 'package:aitrainer_app/service/exercise_plan_service.dart';
class ExercisePlanRepository { class ExercisePlanRepository {
bool newPlan = true; bool newPlan = true;
ExercisePlan exercisePlan; ExercisePlan exercisePlan;
LinkedHashMap<int, ExercisePlanDetail> exercisePlanDetails = LinkedHashMap<int, ExercisePlanDetail> exercisePlanDetails = LinkedHashMap<int, ExercisePlanDetail>();
LinkedHashMap<int, ExercisePlanDetail>();
int customerId = 0; int customerId = 0;
ExercisePlanDetail actualPlanDetail; ExercisePlanDetail actualPlanDetail;
void setCustomerId( int customerId ) { void setCustomerId(int customerId) {
this.customerId = customerId; this.customerId = customerId;
} }
@ -24,11 +24,10 @@ class ExercisePlanRepository {
this.exercisePlan = plan; this.exercisePlan = plan;
} }
ExercisePlan getExercisePlan() => exercisePlan; ExercisePlan getExercisePlan() => exercisePlan;
void addDetailToPlan() { void addDetailToPlan() {
if ( exercisePlan != null ) { if (exercisePlan != null) {
actualPlanDetail.exercisePlanId = exercisePlan.exercisePlanId; actualPlanDetail.exercisePlanId = exercisePlan.exercisePlanId;
} }
exercisePlanDetails[actualPlanDetail.exerciseTypeId] = actualPlanDetail; exercisePlanDetails[actualPlanDetail.exerciseTypeId] = actualPlanDetail;
@ -39,7 +38,7 @@ class ExercisePlanRepository {
void setActualPlanDetailByExerciseType(ExerciseType exerciseType) { void setActualPlanDetailByExerciseType(ExerciseType exerciseType) {
ExercisePlanDetail detail = exercisePlanDetails[exerciseType.exerciseTypeId]; ExercisePlanDetail detail = exercisePlanDetails[exerciseType.exerciseTypeId];
if ( detail != null ) { if (detail != null) {
actualPlanDetail = detail; actualPlanDetail = detail;
} else { } else {
actualPlanDetail = ExercisePlanDetail(exerciseType.exerciseTypeId); actualPlanDetail = ExercisePlanDetail(exerciseType.exerciseTypeId);
@ -49,7 +48,7 @@ class ExercisePlanRepository {
ExercisePlanDetail getActualPlanDetail() => actualPlanDetail; ExercisePlanDetail getActualPlanDetail() => actualPlanDetail;
void setActualPlanDetail( ExercisePlanDetail detail ) { void setActualPlanDetail(ExercisePlanDetail detail) {
this.actualPlanDetail = detail; this.actualPlanDetail = detail;
} }
@ -58,10 +57,8 @@ class ExercisePlanRepository {
String getPlanDetail(int exerciseTypeId) { String getPlanDetail(int exerciseTypeId) {
ExercisePlanDetail detail = exercisePlanDetails[exerciseTypeId]; ExercisePlanDetail detail = exercisePlanDetails[exerciseTypeId];
String detailString = ""; String detailString = "";
if ( detail != null) { if (detail != null) {
detailString = detailString = detail.serie.toString() + "x" + detail.repeats.toString() + " " + detail.weightEquation + "kg";
detail.serie.toString() + "x" + detail.repeats.toString() + " " +
detail.weightEquation + "kg";
} }
return detailString; return detailString;
} }
@ -71,14 +68,14 @@ class ExercisePlanRepository {
} }
void updateExercisePlanDetail(ExerciseType exerciseType, int serie, int repeat, String weight) { void updateExercisePlanDetail(ExerciseType exerciseType, int serie, int repeat, String weight) {
if ( exercisePlanDetails[exerciseType.exerciseTypeId] == null) { if (exercisePlanDetails[exerciseType.exerciseTypeId] == null) {
return; return;
} }
ExercisePlanDetail exercisePlanDetail = exercisePlanDetails[exerciseType.exerciseTypeId]; ExercisePlanDetail exercisePlanDetail = exercisePlanDetails[exerciseType.exerciseTypeId];
exercisePlanDetail.serie = serie; exercisePlanDetail.serie = serie;
exercisePlanDetail.repeats = repeat; exercisePlanDetail.repeats = repeat;
exercisePlanDetail.weightEquation = weight; exercisePlanDetail.weightEquation = weight;
exercisePlanDetail.change = ExercisePlanDetailChange.update; exercisePlanDetail.change = ModelChange.update;
exercisePlanDetails[exerciseType.exerciseTypeId] = exercisePlanDetail; exercisePlanDetails[exerciseType.exerciseTypeId] = exercisePlanDetail;
} }
@ -88,19 +85,18 @@ class ExercisePlanRepository {
} }
void removeExerciseTypeFromPlanByExerciseTypeId(int exerciseTypeId) { void removeExerciseTypeFromPlanByExerciseTypeId(int exerciseTypeId) {
exercisePlanDetails[exerciseTypeId].change = ExercisePlanDetailChange.delete; exercisePlanDetails[exerciseTypeId].change = ModelChange.delete;
Cache().deleteMyExercisePlanDetailByExerciseTypeId(exerciseTypeId); Cache().deleteMyExercisePlanDetailByExerciseTypeId(exerciseTypeId);
} }
Future<void> saveExercisePlan() async { Future<void> saveExercisePlan() async {
if (exercisePlan == null) {
if ( exercisePlan == null ) { if (Cache().userLoggedIn == null) {
if ( Cache().userLoggedIn == null ) {
throw Exception("please log in"); throw Exception("please log in");
} }
String exercisePlanName; String exercisePlanName;
if ( this.customerId == Cache().userLoggedIn.customerId) { if (this.customerId == Cache().userLoggedIn.customerId) {
exercisePlanName = Cache().userLoggedIn.name + " private"; exercisePlanName = Cache().userLoggedIn.name + " private";
} else { } else {
exercisePlanName = Cache().getTrainee().name + " " + Cache().getTrainee().firstname + " private"; exercisePlanName = Cache().getTrainee().name + " " + Cache().getTrainee().firstname + " private";
@ -108,11 +104,10 @@ class ExercisePlanRepository {
exercisePlan = ExercisePlan(exercisePlanName, this.customerId); exercisePlan = ExercisePlan(exercisePlanName, this.customerId);
} }
if ( newPlan ) { if (newPlan) {
exercisePlan.dateAdd = DateTime.now(); exercisePlan.dateAdd = DateTime.now();
exercisePlan.private = true; exercisePlan.private = true;
ExercisePlan savedExercisePlan = ExercisePlan savedExercisePlan = await ExercisePlanApi().saveExercisePlan(exercisePlan);
await ExercisePlanApi().saveExercisePlan(exercisePlan);
LinkedHashMap<int, ExercisePlanDetail> savedExercisePlanDetails = LinkedHashMap(); LinkedHashMap<int, ExercisePlanDetail> savedExercisePlanDetails = LinkedHashMap();
exercisePlanDetails.forEach((exerciseTypeId, exercisePlanDetail) async { exercisePlanDetails.forEach((exerciseTypeId, exercisePlanDetail) async {
@ -123,40 +118,33 @@ class ExercisePlanRepository {
exercisePlan = savedExercisePlan; exercisePlan = savedExercisePlan;
exercisePlanDetails = savedExercisePlanDetails; exercisePlanDetails = savedExercisePlanDetails;
} else { } else {
//await ExercisePlanApi().updateExercisePlan(exercisePlan, exercisePlan.exercisePlanId); //await ExercisePlanApi().updateExercisePlan(exercisePlan, exercisePlan.exercisePlanId);
exercisePlanDetails.forEach((exerciseTypeId, exercisePlanDetail) async { exercisePlanDetails.forEach((exerciseTypeId, exercisePlanDetail) async {
if ( exercisePlanDetail.change == ExercisePlanDetailChange.delete ) { if (exercisePlanDetail.change == ModelChange.delete) {
await ExercisePlanApi() await ExercisePlanApi().deleteExercisePlanDetail(exercisePlanDetail.exercisePlanDetailId);
.deleteExercisePlanDetail(exercisePlanDetail.exercisePlanDetailId); exercisePlanDetail.change = ModelChange.deleted;
exercisePlanDetail.change = ExercisePlanDetailChange.deleted;
Cache().deletedMyExercisePlanDetail(exercisePlanDetail); Cache().deletedMyExercisePlanDetail(exercisePlanDetail);
} else if ( exercisePlanDetail.change == ExercisePlanDetailChange.update ) { } else if (exercisePlanDetail.change == ModelChange.update) {
await ExercisePlanApi() await ExercisePlanApi().updateExercisePlanDetail(exercisePlanDetail, exercisePlanDetail.exercisePlanDetailId);
.updateExercisePlanDetail(exercisePlanDetail, exercisePlanDetail.exercisePlanDetailId);
Cache().updateMyExercisePlanDetail(exercisePlanDetail); Cache().updateMyExercisePlanDetail(exercisePlanDetail);
exercisePlanDetail.change = ExercisePlanDetailChange.saved; exercisePlanDetail.change = ModelChange.saved;
} else if ( exercisePlanDetail.change == ExercisePlanDetailChange.add ) { } else if (exercisePlanDetail.change == ModelChange.add) {
await ExercisePlanApi() await ExercisePlanApi().saveExercisePlanDetail(exercisePlanDetail);
.saveExercisePlanDetail(exercisePlanDetail);
Cache().addToMyExercisePlanDetails(exercisePlanDetail); Cache().addToMyExercisePlanDetails(exercisePlanDetail);
exercisePlanDetail.change = ExercisePlanDetailChange.saved; exercisePlanDetail.change = ModelChange.saved;
} }
}); });
} }
} }
Future<ExercisePlan> getLastExercisePlan() async { Future<ExercisePlan> getLastExercisePlan() async {
if ( customerId == 0) { if (customerId == 0) {
return null; return null;
} }
ExercisePlan myExercisePlan = Cache().getMyExercisePlan(); ExercisePlan myExercisePlan = Cache().getMyExercisePlan();
if ( myExercisePlan != null ) { if (myExercisePlan != null) {
exercisePlan = myExercisePlan; exercisePlan = myExercisePlan;
return myExercisePlan; return myExercisePlan;
} }
@ -171,7 +159,7 @@ class ExercisePlanRepository {
Future<void> getExercisePlanDetails() async { Future<void> getExercisePlanDetails() async {
if (exercisePlan == null) { if (exercisePlan == null) {
ExercisePlan exercisePlan = await this.getLastExercisePlan(); ExercisePlan exercisePlan = await this.getLastExercisePlan();
if ( exercisePlan == null ) { if (exercisePlan == null) {
exercisePlanDetails = LinkedHashMap<int, ExercisePlanDetail>(); exercisePlanDetails = LinkedHashMap<int, ExercisePlanDetail>();
return; return;
} }
@ -179,7 +167,7 @@ class ExercisePlanRepository {
List<ExercisePlanDetail> list = List(); List<ExercisePlanDetail> list = List();
LinkedHashMap<int, ExercisePlanDetail> listCache = Cache().getMyExercisePlanDetails(); LinkedHashMap<int, ExercisePlanDetail> listCache = Cache().getMyExercisePlanDetails();
if ( listCache.length > 0) { if (listCache.length > 0) {
exercisePlanDetails = listCache; exercisePlanDetails = listCache;
return; return;
} else { } else {
@ -197,5 +185,4 @@ class ExercisePlanRepository {
return; return;
} }
} }

View File

@ -1,5 +1,3 @@
import 'dart:collection';
import 'package:aitrainer_app/model/cache.dart'; import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/model/property.dart'; import 'package:aitrainer_app/model/property.dart';
import 'package:aitrainer_app/service/property_service.dart'; import 'package:aitrainer_app/service/property_service.dart';

View File

@ -41,9 +41,7 @@ class UserRepository {
String rc = await FirebaseApi().signInEmail(modelUser.email, modelUser.password); String rc = await FirebaseApi().signInEmail(modelUser.email, modelUser.password);
if (rc == FirebaseApi.SIGN_IN_OK) { if (rc == FirebaseApi.SIGN_IN_OK) {
print("Firebase login ok");
await CustomerApi().getUserByEmail(modelUser.email); await CustomerApi().getUserByEmail(modelUser.email);
print("GetUserBy Email OK");
Cache().afterFirebaseLogin(); Cache().afterFirebaseLogin();
} else { } else {
print("Exception: user not found or password is wrong"); print("Exception: user not found or password is wrong");

View File

@ -0,0 +1,44 @@
import 'package:aitrainer_app/model/customer_exercise_device.dart';
import 'package:aitrainer_app/util/not_found_exception.dart';
import 'dart:convert';
import 'api.dart';
class CustomerExerciseDeviceApi {
final APIClient _client = new APIClient();
Future<List<CustomerExerciseDevice>> getDevices(int customerId) async {
List<CustomerExerciseDevice> devices;
try {
final body = await _client.get("customer_exercise_device/customer/" + customerId.toString(), "");
final Iterable json = jsonDecode(body);
devices = json.map((device) => CustomerExerciseDevice.fromJson(device)).toList();
} on NotFoundException catch (e) {
print("No devices found");
}
return devices;
}
Future<CustomerExerciseDevice> addDevice(CustomerExerciseDevice device) async {
CustomerExerciseDevice savedDevice;
try {
final String body = JsonEncoder().convert(device.toJson());
print(" --- add customer_exercise_device: " + body);
final String responseBody = await _client.post("customer_exercise_device", body);
savedDevice = CustomerExerciseDevice.fromJson(jsonDecode(responseBody));
} on Exception catch (e) {
throw new Exception(e.toString());
}
return savedDevice;
}
Future<void> removeDevice(int id) async {
try {
print(" --- delete customer_exercise_device: " + id.toString());
await _client.post("customer_exercise_device/delete/" + id.toString(), "");
} on Exception catch (e) {
throw new Exception(e.toString());
}
return;
}
}

View File

@ -6,7 +6,6 @@ import 'package:aitrainer_app/model/property.dart';
import 'package:aitrainer_app/model/user.dart'; import 'package:aitrainer_app/model/user.dart';
import 'package:aitrainer_app/service/api.dart'; import 'package:aitrainer_app/service/api.dart';
import 'package:aitrainer_app/model/cache.dart'; import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/util/not_found_exception.dart';
class CustomerApi { class CustomerApi {
final APIClient _client = new APIClient(); final APIClient _client = new APIClient();

View File

@ -0,0 +1,17 @@
import 'package:aitrainer_app/model/cache.dart';
import 'dart:convert';
import 'package:aitrainer_app/model/exercise_device.dart';
import 'api.dart';
class ExerciseDeviceApi {
final APIClient _client = new APIClient();
Future<List<ExerciseDevice>> getDevices() async {
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);
return devices;
}
}

View File

@ -2,30 +2,27 @@ import 'dart:convert';
import 'package:aitrainer_app/model/exercise.dart'; import 'package:aitrainer_app/model/exercise.dart';
import 'package:aitrainer_app/service/api.dart'; import 'package:aitrainer_app/service/api.dart';
class ExerciseApi { class ExerciseApi {
final APIClient _client=new APIClient(); final APIClient _client = new APIClient();
Future<List<Exercise>> getExerciseTypes(String param) async { Future<List<Exercise>> getExerciseTypes(String param) async {
final body = await _client.get("exercises", param); final body = await _client.get("exercises", param);
final Iterable json = jsonDecode(body); final Iterable json = jsonDecode(body);
final List<Exercise> exerciseTypes = json.map( (exerciseType) => Exercise.fromJson(exerciseType) ).toList(); final List<Exercise> exerciseTypes = json.map((exerciseType) => Exercise.fromJson(exerciseType)).toList();
return exerciseTypes; return exerciseTypes;
} }
Future<void> saveExercise(Exercise exercise) async { Future<void> saveExercise(Exercise exercise) async {
String body = JsonEncoder().convert(exercise.toJson()); String body = JsonEncoder().convert(exercise.toJson());
print(" ===== saving exercise id: " + exercise.exerciseId.toString() + ":" + body ); print(" ===== saving exercise id: " + exercise.exerciseId.toString() + ":" + body);
await _client.post( await _client.post("exercises/" + exercise.exerciseId.toString(), body);
"exercises/"+exercise.exerciseId.toString(),
body);
} }
Future<List<Exercise>> getExercisesByCustomer(int customerId ) async { Future<List<Exercise>> getExercisesByCustomer(int customerId) async {
final body = await _client.get("exercises/customer/", customerId.toString() ); final body = await _client.get("exercises/customer/", customerId.toString());
final Iterable json = jsonDecode(body); final Iterable json = jsonDecode(body);
final List<Exercise> exercises = json.map( (exercise) { final List<Exercise> exercises = json.map((exercise) {
Exercise item = Exercise.fromJson(exercise); Exercise item = Exercise.fromJson(exercise);
return item; return item;
}).toList(); }).toList();
@ -36,19 +33,16 @@ class ExerciseApi {
Future<Exercise> addExercise(Exercise exercise) async { Future<Exercise> addExercise(Exercise exercise) async {
String body = JsonEncoder().convert(exercise.toJson()); String body = JsonEncoder().convert(exercise.toJson());
print(" ===== add new exercise: " + body ); print(" ===== add new exercise: " + body);
final String response = await _client.post( final String response = await _client.post("exercises", body);
"exercises",
body);
final Exercise savedExercise = Exercise.fromJson(jsonDecode(response)); final Exercise savedExercise = Exercise.fromJson(jsonDecode(response));
return savedExercise; return savedExercise;
} }
Future<void> deleteExercise(Exercise exercise) async { Future<void> deleteExercise(Exercise exercise) async {
int exerciseId = exercise.exerciseId; int exerciseId = exercise.exerciseId;
print(" ===== delete exercise: " + exerciseId.toString() ); print(" ===== delete exercise: " + exerciseId.toString());
final String response = await _client.post("exercises/" + exerciseId.toString(), ""); await _client.post("exercises/" + exerciseId.toString(), "");
return; return;
} }
} }

View File

@ -1,7 +1,7 @@
import 'package:aitrainer_app/model/cache.dart'; import 'package:aitrainer_app/model/cache.dart';
import 'package:firebase_auth/firebase_auth.dart'; import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_core/firebase_core.dart';
import 'package:flutter_facebook_auth/flutter_facebook_auth.dart'; //import 'package:flutter_facebook_auth/flutter_facebook_auth.dart';
class FirebaseApi { class FirebaseApi {
static FirebaseApi _instance; static FirebaseApi _instance;
@ -66,10 +66,6 @@ class FirebaseApi {
print('The account already exists for that email.'); print('The account already exists for that email.');
rc = REGISTER_EMAIL_IN_USE; rc = REGISTER_EMAIL_IN_USE;
throw Exception("The email address has been registered already"); throw Exception("The email address has been registered already");
/* userCredential = await FirebaseAuth.instance.signInWithEmailAndPassword(email: email, password: password);
if (rc != null) {
rc = SIGN_IN_OK;
} */
} }
} catch (e) { } catch (e) {
print(e); print(e);
@ -78,7 +74,7 @@ class FirebaseApi {
return rc; return rc;
} }
Future<UserCredential> signInWithFacebook() async { /*Future<UserCredential> signInWithFacebook() async {
// Trigger the sign-in flow // Trigger the sign-in flow
final LoginResult result = await FacebookAuth.instance.login(); final LoginResult result = await FacebookAuth.instance.login();
@ -87,7 +83,7 @@ class FirebaseApi {
// Once signed in, return the UserCredential // Once signed in, return the UserCredential
return await FirebaseAuth.instance.signInWithCredential(facebookAuthCredential); return await FirebaseAuth.instance.signInWithCredential(facebookAuthCredential);
} }*/
Future<void> signOut() async { Future<void> signOut() async {
await FirebaseAuth.instance.signOut(); await FirebaseAuth.instance.signOut();

View File

@ -1,19 +1,20 @@
import 'package:aitrainer_app/localization/app_language.dart'; import 'package:aitrainer_app/localization/app_language.dart';
import 'package:aitrainer_app/localization/app_localization.dart'; import 'package:aitrainer_app/localization/app_localization.dart';
import 'package:aitrainer_app/model/customer_exercise_device.dart';
import 'package:aitrainer_app/repository/exercise_repository.dart'; import 'package:aitrainer_app/repository/exercise_repository.dart';
import 'package:aitrainer_app/service/api.dart'; import 'package:aitrainer_app/service/api.dart';
import 'package:aitrainer_app/service/customer_exercise_device_service.dart';
import 'package:aitrainer_app/service/customer_service.dart'; import 'package:aitrainer_app/service/customer_service.dart';
import 'package:aitrainer_app/service/exercise_device_service.dart';
import 'package:aitrainer_app/service/exercise_tree_service.dart'; import 'package:aitrainer_app/service/exercise_tree_service.dart';
import 'package:aitrainer_app/service/exercisetype_service.dart'; import 'package:aitrainer_app/service/exercisetype_service.dart';
import 'package:aitrainer_app/service/firebase_api.dart'; import 'package:aitrainer_app/service/firebase_api.dart';
import 'package:aitrainer_app/service/property_service.dart'; import 'package:aitrainer_app/service/property_service.dart';
import 'package:devicelocale/devicelocale.dart'; import 'package:devicelocale/devicelocale.dart';
import 'package:flurry/flurry.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:aitrainer_app/model/cache.dart'; import 'package:aitrainer_app/model/cache.dart';
import 'package:firebase_core/firebase_core.dart';
//import '../push_notifications.dart';
class Session { class Session {
Future<SharedPreferences> _prefs = SharedPreferences.getInstance(); Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
@ -36,7 +37,6 @@ class Session {
// Create the initialization Future outside of `build`: // Create the initialization Future outside of `build`:
// PushNotificationsManager().init();
} }
} }
@ -100,15 +100,19 @@ class Session {
customerId = prefs.getInt(Cache.customerIdKey); customerId = prefs.getInt(Cache.customerIdKey);
await CustomerApi().getCustomer(customerId); await CustomerApi().getCustomer(customerId);
Cache().startPage = "home"; Cache().startPage = "home";
Flurry.setUserId(customerId.toString());
} }
} }
await ExerciseTypeApi().getExerciseTypes(); await ExerciseTypeApi().getExerciseTypes();
await ExerciseTreeApi().getExerciseTree(); await ExerciseTreeApi().getExerciseTree();
final customerDevices = await CustomerExerciseDeviceApi().getDevices(customerId);
Cache().setCustomerDevices(customerDevices);
if (customerId > 0) { if (customerId > 0) {
ExerciseRepository exerciseRepository = ExerciseRepository(); ExerciseRepository exerciseRepository = ExerciseRepository();
await exerciseRepository.getExercisesByCustomer(customerId); await exerciseRepository.getExercisesByCustomer(customerId);
} }
await ExerciseDeviceApi().getDevices();
print("--- Session finished"); print("--- Session finished");
} }
} }

View File

@ -4,6 +4,7 @@ import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/model/customer.dart'; import 'package:aitrainer_app/model/customer.dart';
import 'package:aitrainer_app/util/trans.dart'; import 'package:aitrainer_app/util/trans.dart';
import 'package:aitrainer_app/widgets/app_bar_min.dart'; import 'package:aitrainer_app/widgets/app_bar_min.dart';
import 'package:badges/badges.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:aitrainer_app/widgets/bottom_nav.dart'; import 'package:aitrainer_app/widgets/bottom_nav.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -57,7 +58,7 @@ class AccountPage extends StatelessWidget with Trans {
ListView accountWidget(BuildContext context, String customerName, AccountBloc accountBloc) { ListView accountWidget(BuildContext context, String customerName, AccountBloc accountBloc) {
return ListView(padding: EdgeInsets.only(top: 35), children: <Widget>[ return ListView(padding: EdgeInsets.only(top: 35), children: <Widget>[
ListTile( ListTile(
leading: Icon(Icons.perm_identity), leading: badgedIcon(Colors.grey, Icons.perm_identity, "personalData"), //Icon(Icons.perm_identity),
subtitle: Text(t("Profile")), subtitle: Text(t("Profile")),
title: FlatButton( title: FlatButton(
child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
@ -74,11 +75,33 @@ class AccountPage extends StatelessWidget with Trans {
}, },
), ),
), ),
devices(context, accountBloc),
loginOut(context, accountBloc), loginOut(context, accountBloc),
getMyTrainees(context, accountBloc), getMyTrainees(context, accountBloc),
]); ]);
} }
ListTile devices(BuildContext context, AccountBloc accountBloc) {
ListTile element = ListTile();
element = ListTile(
leading: badgedIcon(Colors.grey, Icons.device_hub, "customerDevice"),
title: FlatButton(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [Text(t("Available Devices"), style: TextStyle(color: Colors.orange)), Icon(Icons.arrow_forward_ios)]),
textColor: Colors.orange,
color: Colors.white,
onPressed: () => {
if (accountBloc.customerRepository.customer != null && Cache().userLoggedIn != null)
{
Navigator.of(context).pushNamed('customerExerciseDevicePage'),
}
},
),
);
return element;
}
ListTile loginOut(BuildContext context, AccountBloc accountBloc) { ListTile loginOut(BuildContext context, AccountBloc accountBloc) {
ListTile element = ListTile(); ListTile element = ListTile();
@ -203,4 +226,24 @@ class AccountPage extends StatelessWidget with Trans {
], ],
)); ));
} }
Widget badgedIcon(Color color, IconData icon, String badgeKey) {
bool show = Cache().getBadges()[badgeKey] != null;
int counter = Cache().getBadges()[badgeKey] != null ? Cache().getBadges()[badgeKey] : 0;
return Badge(
position: BadgePosition.topEnd(top: -10, end: -10),
animationDuration: Duration(milliseconds: 500),
animationType: BadgeAnimationType.slide,
badgeColor: Colors.red,
showBadge: show,
badgeContent: Text(
counter.toString(),
style: TextStyle(color: Colors.white),
),
child: Icon(
icon,
color: color,
),
);
}
} }

View File

@ -0,0 +1,246 @@
import 'package:aitrainer_app/bloc/customer_exercise_device/customer_exercise_device_bloc.dart';
import 'package:aitrainer_app/localization/app_language.dart';
import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/model/exercise_device.dart';
import 'package:aitrainer_app/repository/customer_exercise_device_repository.dart';
import 'package:aitrainer_app/util/trans.dart';
import 'package:aitrainer_app/widgets/app_bar.dart';
import 'package:aitrainer_app/widgets/image_button.dart';
import 'package:aitrainer_app/widgets/splash.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:google_fonts/google_fonts.dart';
// ignore: must_be_immutable
class CustomerExerciseDevicePage extends StatelessWidget with Trans {
List<Widget> listDevice;
@override
Widget build(BuildContext context) {
setContext(context);
double cWidth = MediaQuery.of(context).size.width;
return Scaffold(
appBar: AppBarNav(depth: 0),
body: Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('asset/image/WT_black_background.png'),
fit: BoxFit.cover,
alignment: Alignment.center,
),
),
child: BlocProvider(
create: (context) =>
CustomerExerciseDeviceBloc(repository: CustomerExerciseDeviceRepository(), devices: Cache().getDevices())
..add(CustomerExerciseDeviceLoad()),
child: BlocConsumer<CustomerExerciseDeviceBloc, CustomerExerciseDeviceState>(
listener: (context, state) {
if (state is CustomerExerciseDeviceLoading) {
return LoadingDialog();
} else if (state is CustomerExerciseDeviceError) {
Scaffold.of(context).showSnackBar(
SnackBar(backgroundColor: Colors.orange, content: Text(state.message, style: TextStyle(color: Colors.white))));
}
},
builder: (context, state) {
final bloc = BlocProvider.of<CustomerExerciseDeviceBloc>(context);
return getPage(bloc, cWidth);
},
))));
}
Widget getPage(CustomerExerciseDeviceBloc bloc, double cWidth) {
print("width" + cWidth.toString());
return CustomScrollView(scrollDirection: Axis.vertical, slivers: [
SliverGrid(
delegate: SliverChildListDelegate([
Text(t("Available Training Places"),
textAlign: TextAlign.center,
maxLines: 2,
softWrap: true,
style: GoogleFonts.archivoBlack(
fontSize: 24,
color: Colors.white,
shadows: <Shadow>[
Shadow(
offset: Offset(5.0, 5.0),
blurRadius: 12.0,
color: Colors.black54,
),
Shadow(
offset: Offset(-3.0, 3.0),
blurRadius: 12.0,
color: Colors.black54,
),
],
)),
Text(t("select your places by tapping"),
textAlign: TextAlign.center,
softWrap: true,
maxLines: 2,
style: GoogleFonts.archivoBlack(
fontSize: 14,
color: Colors.white,
shadows: <Shadow>[
Shadow(
offset: Offset(5.0, 5.0),
blurRadius: 12.0,
color: Colors.black54,
),
Shadow(
offset: Offset(-3.0, 3.0),
blurRadius: 12.0,
color: Colors.black54,
),
],
)),
]),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 1,
mainAxisSpacing: 0.0,
crossAxisSpacing: 0.0,
childAspectRatio: cWidth > 375 ? 9.1 : 4.1,
),
),
SliverGrid(
delegate: SliverChildListDelegate(getDevicesPlace(bloc, cWidth)),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 1,
mainAxisSpacing: 15.0,
crossAxisSpacing: 10.0,
childAspectRatio: 3.0,
),
),
SliverGrid(
delegate: SliverChildListDelegate([
SizedBox(
height: 1,
),
Text(t("Available Equipments"),
textAlign: TextAlign.center,
maxLines: 2,
style: GoogleFonts.archivoBlack(
fontSize: 24,
color: Colors.white,
shadows: <Shadow>[
Shadow(
offset: Offset(5.0, 5.0),
blurRadius: 12.0,
color: Colors.black54,
),
Shadow(
offset: Offset(-3.0, 3.0),
blurRadius: 12.0,
color: Colors.black54,
),
],
)),
Text(t("select your equipments by tapping"),
textAlign: TextAlign.center,
maxLines: 2,
style: GoogleFonts.archivoBlack(
fontSize: 14,
color: Colors.white,
shadows: <Shadow>[
Shadow(
offset: Offset(5.0, 5.0),
blurRadius: 12.0,
color: Colors.black54,
),
Shadow(
offset: Offset(-3.0, 3.0),
blurRadius: 12.0,
color: Colors.black54,
),
],
)),
]),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 1,
mainAxisSpacing: 2.0,
crossAxisSpacing: 5.0,
childAspectRatio: cWidth > 375 ? 9.1 : 6.1,
),
),
SliverGrid(
delegate: SliverChildListDelegate(getDevices(bloc)),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
mainAxisSpacing: 15.0,
crossAxisSpacing: 15.0,
childAspectRatio: 1.0,
),
),
]);
}
List<Widget> getDevices(CustomerExerciseDeviceBloc bloc) {
final bool isEnglish = AppLanguage().appLocal.languageCode == "en";
this.listDevice = List();
final devices = bloc.devices;
devices.sort((a, b) => a.sort.compareTo(b.sort));
if (devices != null) {
devices.forEach((element) {
if (element.place == false) {
final String url = "asset/image/" + element.imageUrl.substring(7);
ImageButton button = ImageButton(
width: 178,
height: 175,
textAlignment: Alignment.topCenter,
text: isEnglish ? element.name : element.nameTranslation,
style: GoogleFonts.archivoBlack(fontSize: 14, color: Colors.white, backgroundColor: Colors.black54.withOpacity(0.4)),
image: url,
left: 5,
onTap: () => changeButtonShape(element, bloc),
isLocked: false,
isMarked: bloc.hasCustomerDevice(element.exerciseDeviceId),
buttonIndex: element.exerciseDeviceId,
isShape: false,
);
listDevice.add(button);
}
});
}
return listDevice;
}
List<Widget> getDevicesPlace(CustomerExerciseDeviceBloc bloc, double cWidth) {
final bool isEnglish = AppLanguage().appLocal.languageCode == "en";
this.listDevice = List();
final devices = bloc.devices;
if (devices != null) {
devices.sort((a, b) => a.sort.compareTo(b.sort));
devices.forEach((element) {
if (element.place) {
ImageButton button = ImageButton(
width: cWidth - 80,
height: 125,
top: 10,
textAlignment: Alignment.topCenter,
text: isEnglish ? element.name : element.nameTranslation,
style: GoogleFonts.archivoBlack(fontSize: 14, color: Colors.white, backgroundColor: Colors.black54.withOpacity(0.4)),
image: element.imageUrl,
left: 35,
onTap: () => changeButtonShape(element, bloc),
isLocked: false,
buttonIndex: element.exerciseDeviceId,
isShape: false,
isMarked: bloc.hasCustomerDevice(element.exerciseDeviceId),
);
listDevice.add(button);
}
});
}
return listDevice;
}
void changeButtonShape(ExerciseDevice device, CustomerExerciseDeviceBloc bloc) {
print("Device clicked: " + device.name);
if (bloc.hasCustomerDevice(device.exerciseDeviceId)) {
bloc.add(CustomerExerciseDeviceRemove(device: device));
} else {
bloc.add(CustomerExerciseDeviceAdd(device: device));
}
}
}

View File

@ -27,43 +27,31 @@ class _ExerciseControlPage extends State<ExerciseControlPage> with Trans {
setContext(context); setContext(context);
return BlocProvider( return BlocProvider(
create: (context) => ExerciseControlBloc( create: (context) => ExerciseControlBloc(exerciseRepository: exerciseRepository, percentToCalculate: percent, readonly: readonly)
exerciseRepository: exerciseRepository, percentToCalculate: percent, readonly: readonly).. ..add(ExerciseControlLoad()),
add(ExerciseControlLoad()), child: BlocConsumer<ExerciseControlBloc, ExerciseControlState>(listener: (context, state) {
child:
BlocConsumer<ExerciseControlBloc, ExerciseControlState>(
listener: (context, state) {
if (state is ExerciseControlError) { if (state is ExerciseControlError) {
Scaffold.of(context).showSnackBar(SnackBar( Scaffold.of(context).showSnackBar(
backgroundColor: Colors.orange, SnackBar(backgroundColor: Colors.orange, content: Text(state.message, style: TextStyle(color: Colors.white))));
content:
Text(state.message, style: TextStyle(color: Colors.white))));
} else if (state is ExerciseControlLoading) { } else if (state is ExerciseControlLoading) {
return LoadingDialog(); return LoadingDialog();
} }
}, }, builder: (context, state) {
builder: (context, state) {
final exerciseBloc = BlocProvider.of<ExerciseControlBloc>(context); final exerciseBloc = BlocProvider.of<ExerciseControlBloc>(context);
if (state is ExerciseControlReady) { if (state is ExerciseControlReady) {
return getControlForm(exerciseBloc); return getControlForm(exerciseBloc);
} else { } else {
return getControlForm(exerciseBloc); return getControlForm(exerciseBloc);
} }
}) }));
);
} }
Form getControlForm(ExerciseControlBloc exerciseBloc) { Form getControlForm(ExerciseControlBloc exerciseBloc) {
String exerciseName = AppLanguage().appLocal == Locale("en") String exerciseName = AppLanguage().appLocal == Locale("en")
? exerciseBloc.exerciseRepository.exerciseType.name ? exerciseBloc.exerciseRepository.exerciseType.name
: exerciseBloc.exerciseRepository.exerciseType.nameTranslation; : exerciseBloc.exerciseRepository.exerciseType.nameTranslation;
return Form( return Form(
autovalidate: true,
child: Scaffold( child: Scaffold(
resizeToAvoidBottomInset: true, resizeToAvoidBottomInset: true,
appBar: AppBarNav(depth: 1), appBar: AppBarNav(depth: 1),
@ -97,8 +85,7 @@ class _ExerciseControlPage extends State<ExerciseControlPage> with Trans {
Icon(Icons.info), Icon(Icons.info),
Flexible( Flexible(
child: Text(t("Why do you need Exercise Control?"), child: Text(t("Why do you need Exercise Control?"),
style: style: TextStyle(color: Colors.blueAccent, fontWeight: FontWeight.normal, fontSize: 14)),
TextStyle(color: Colors.blueAccent, fontWeight: FontWeight.normal, fontSize: 14)),
), ),
Icon(Icons.arrow_forward_ios), Icon(Icons.arrow_forward_ios),
]), ]),
@ -137,19 +124,20 @@ class _ExerciseControlPage extends State<ExerciseControlPage> with Trans {
} }
Widget numberPickForm(ExerciseControlBloc exerciseBloc, int step) { Widget numberPickForm(ExerciseControlBloc exerciseBloc, int step) {
String strTimes = step == 2 ? exerciseBloc.origQuantity.toString() : "max."; String strTimes = step == 2 ? exerciseBloc.origQuantity.toString() : "max.";
String textInstruction = ""; String textInstruction = "";
textInstruction = t("Please repeat with ") + textInstruction = t("Please repeat with ") +
exerciseBloc.unitQuantity.toStringAsFixed(0) + exerciseBloc.unitQuantity.toStringAsFixed(0) +
" " + " " +
exerciseBloc.exerciseRepository.exerciseType.unitQuantityUnit + exerciseBloc.exerciseRepository.exerciseType.unitQuantityUnit +
t("hu_with") + " " + t("hu_with") +
strTimes + " " + t("times!"); " " +
strTimes +
" " +
t("times!");
String title = step.toString() + ". " + t("Control Exercise:"); String title = step.toString() + ". " + t("Control Exercise:");
List<Widget> listWidgets = [ List<Widget> listWidgets = [
Text( Text(
title, title,
@ -168,9 +156,7 @@ class _ExerciseControlPage extends State<ExerciseControlPage> with Trans {
minValue: 0, minValue: 0,
maxValue: 200, maxValue: 200,
step: 1, step: 1,
onChanged: (value) => { onChanged: (value) => {exerciseBloc.add(ExerciseControlQuantityChange(quantity: value.toDouble(), step: step))},
exerciseBloc.add(ExerciseControlQuantityChange(quantity: value.toDouble(), step: step))
},
listViewHeight: 80, listViewHeight: 80,
//decoration: _decoration, //decoration: _decoration,
), ),
@ -181,9 +167,7 @@ class _ExerciseControlPage extends State<ExerciseControlPage> with Trans {
focusColor: Colors.blueAccent, focusColor: Colors.blueAccent,
onPressed: () => { onPressed: () => {
exerciseBloc.add(ExerciseControlSubmit(step: step)), exerciseBloc.add(ExerciseControlSubmit(step: step)),
if ( step == 3 ) { if (step == 3) {confirmationDialog(exerciseBloc)}
confirmationDialog(exerciseBloc)
}
}, },
child: Text( child: Text(
t("Save"), t("Save"),
@ -191,52 +175,48 @@ class _ExerciseControlPage extends State<ExerciseControlPage> with Trans {
)), )),
], ],
), ),
]; ];
return return Column(
Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: listWidgets, children: listWidgets,
); );
} }
void confirmationDialog( ExerciseControlBloc bloc ) { void confirmationDialog(ExerciseControlBloc bloc) {
String unit = t(bloc.exerciseRepository.exerciseType.unit); String unit = t(bloc.exerciseRepository.exerciseType.unit);
showCupertinoDialog( showCupertinoDialog(
useRootNavigator: true, useRootNavigator: true,
context: context, context: context,
//barrierDismissible: false, //barrierDismissible: false,
builder:(_) => CupertinoAlertDialog( builder: (_) => CupertinoAlertDialog(
title: Text(t("Summary of your test")), title: Text(t("Summary of your test")),
content: Column( content: Column(children: [
Text(
children: [ t("Test") + ": " + bloc.repeats[1].toStringAsFixed(0) + "x" + bloc.repeats[0].toStringAsFixed(0) + " " + unit,
style: (TextStyle(color: Colors.blue)),
Text(t("Test") + ": " + bloc.repeats[1].toStringAsFixed(0) + "x" + bloc.repeats[0].toStringAsFixed(0) + " " + unit , ),
style: (TextStyle(color: Colors.blue)),),
Divider(), Divider(),
Text(t("1st Control") + ": " + bloc.repeats[2].toStringAsFixed(0) + "x" + bloc.unitQuantity.toStringAsFixed(0) + " " + unit , Text(
style: (TextStyle(color: Colors.blue)),), t("1st Control") + ": " + bloc.repeats[2].toStringAsFixed(0) + "x" + bloc.unitQuantity.toStringAsFixed(0) + " " + unit,
Text(t("2nd Control") + ": " + bloc.repeats[3].toStringAsFixed(0) + "x" + bloc.unitQuantity.toStringAsFixed(0) + " " + unit , style: (TextStyle(color: Colors.blue)),
style: (TextStyle(color: Colors.blue)),), ),
Text(t("3rd Control") + ": " + bloc.repeats [4].toStringAsFixed(0) + "x" + bloc.unitQuantity.toStringAsFixed(0) + " " + unit , Text(
style: (TextStyle(color: Colors.blue)),), t("2nd Control") + ": " + bloc.repeats[3].toStringAsFixed(0) + "x" + bloc.unitQuantity.toStringAsFixed(0) + " " + unit,
style: (TextStyle(color: Colors.blue)),
),
Text(
t("3rd Control") + ": " + bloc.repeats[4].toStringAsFixed(0) + "x" + bloc.unitQuantity.toStringAsFixed(0) + " " + unit,
style: (TextStyle(color: Colors.blue)),
),
]), ]),
actions: [ actions: [
FlatButton( FlatButton(
child: Text(t("OK")), child: Text(t("OK")),
onPressed: () => { onPressed: () => {Navigator.of(context).pop(), Navigator.of(context).pop()},
Navigator.of(context).pop(),
Navigator.of(context).pop()
},
) )
], ],
) ));
);
} }
} }

View File

@ -14,12 +14,11 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_form_bloc/flutter_form_bloc.dart'; import 'package:flutter_form_bloc/flutter_form_bloc.dart';
class ExerciseExecutePlanAddPage extends StatefulWidget{ class ExerciseExecutePlanAddPage extends StatefulWidget {
_ExerciseExecuteAddPage createState() => _ExerciseExecuteAddPage(); _ExerciseExecuteAddPage createState() => _ExerciseExecuteAddPage();
} }
class _ExerciseExecuteAddPage extends State<ExerciseExecutePlanAddPage> with Trans { class _ExerciseExecuteAddPage extends State<ExerciseExecutePlanAddPage> with Trans {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
LinkedHashMap arguments = ModalRoute.of(context).settings.arguments; LinkedHashMap arguments = ModalRoute.of(context).settings.arguments;
@ -31,57 +30,44 @@ class _ExerciseExecuteAddPage extends State<ExerciseExecutePlanAddPage> with Tra
setContext(context); setContext(context);
return BlocProvider( return BlocProvider(
create: (context) => create: (context) => ExerciseExecutePlanAddBloc(
ExerciseExecutePlanAddBloc(
exerciseRepository: exerciseRepository, exerciseRepository: exerciseRepository,
exercisePlanRepository: planBloc.exercisePlanRepository, exercisePlanRepository: planBloc.exercisePlanRepository,
customerId: customerId, customerId: customerId,
workoutTree: workoutTree, workoutTree: workoutTree,
planBloc: planBloc), planBloc: planBloc),
child: BlocConsumer<ExerciseExecutePlanAddBloc, ExerciseExecutePlanAddState>( child: BlocConsumer<ExerciseExecutePlanAddBloc, ExerciseExecutePlanAddState>(listener: (context, state) {
listener: (context, state) {
if (state is ExerciseExecutePlanAddError) { if (state is ExerciseExecutePlanAddError) {
Scaffold.of(context).showSnackBar(SnackBar( Scaffold.of(context).showSnackBar(
backgroundColor: Colors.orange, SnackBar(backgroundColor: Colors.orange, content: Text(state.message, style: TextStyle(color: Colors.white))));
content:
Text(state.message, style: TextStyle(color: Colors.white))));
} else if (state is ExerciseExecutePlanAddLoading) { } else if (state is ExerciseExecutePlanAddLoading) {
return LoadingDialog(); return LoadingDialog();
} }
}, }, builder: (context, state) {
builder: (context, state) {
// ignore: close_sinks // ignore: close_sinks
final exerciseBloc = BlocProvider.of<ExerciseExecutePlanAddBloc>(context); final exerciseBloc = BlocProvider.of<ExerciseExecutePlanAddBloc>(context);
if ( state is ExerciseExecutePlanAddLoading ) { if (state is ExerciseExecutePlanAddLoading) {
return LoadingDialog(); return LoadingDialog();
} else if ( state is ExerciseExecutePlanAddReady) { } else if (state is ExerciseExecutePlanAddReady) {
return getControlForm(exerciseBloc); return getControlForm(exerciseBloc);
} else { } else {
return getControlForm(exerciseBloc); return getControlForm(exerciseBloc);
} }
} }));
));
} }
Form getControlForm( ExerciseExecutePlanAddBloc exerciseBloc) { Form getControlForm(ExerciseExecutePlanAddBloc exerciseBloc) {
String exerciseName = AppLanguage().appLocal == Locale("en") ? String exerciseName = AppLanguage().appLocal == Locale("en")
exerciseBloc.exerciseRepository.exerciseType.name : ? exerciseBloc.exerciseRepository.exerciseType.name
exerciseBloc.exerciseRepository.exerciseType.nameTranslation; : exerciseBloc.exerciseRepository.exerciseType.nameTranslation;
return Form( return Form(
autovalidate: true,
child: Scaffold( child: Scaffold(
resizeToAvoidBottomInset: true, resizeToAvoidBottomInset: true,
appBar: AppBarNav(depth: 1), appBar: AppBarNav(depth: 1),
body: Container( body: Container(
width: MediaQuery width: MediaQuery.of(context).size.width,
.of(context) height: MediaQuery.of(context).size.height,
.size
.width,
height: MediaQuery
.of(context)
.size
.height,
decoration: BoxDecoration( decoration: BoxDecoration(
image: DecorationImage( image: DecorationImage(
image: AssetImage('asset/image/WT_light_background.png'), image: AssetImage('asset/image/WT_light_background.png'),
@ -90,68 +76,76 @@ class _ExerciseExecuteAddPage extends State<ExerciseExecutePlanAddPage> with Tra
), ),
), ),
child: Container( child: Container(
padding: const EdgeInsets.only (top: 25, left: 25, right: 25), padding: const EdgeInsets.only(top: 25, left: 25, right: 25),
child: SingleChildScrollView( child: SingleChildScrollView(
scrollDirection: Axis.vertical, scrollDirection: Axis.vertical,
controller: ScrollController( controller: ScrollController(
initialScrollOffset: exerciseBloc.scrollOffset, initialScrollOffset: exerciseBloc.scrollOffset,
), ),
child: Column( child: Column(mainAxisAlignment: MainAxisAlignment.spaceAround, children: <Widget>[
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Text(t("Save Exercise")), Text(t("Save Exercise")),
Text(exerciseName, Text(
style: TextStyle(fontWeight: FontWeight.bold, exerciseName,
fontSize: 18, style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18, color: Colors.deepOrange),
color: Colors.deepOrange),
overflow: TextOverflow.fade, overflow: TextOverflow.fade,
maxLines: 1, maxLines: 1,
softWrap: true, softWrap: true,
), ),
Divider(color: Colors.transparent,), Divider(
color: Colors.transparent,
),
Divider(), Divider(),
Column( Column(
children: repeatExercises(exerciseBloc), children: repeatExercises(exerciseBloc),
), ),
Divider(), Divider(),
]), ]),
) ))),
)
),
), ),
); );
} }
List<Column> repeatExercises(ExerciseExecutePlanAddBloc exerciseBloc) { List<Column> repeatExercises(ExerciseExecutePlanAddBloc exerciseBloc) {
List<Column> listColumns = List<Column>(); List<Column> listColumns = List<Column>();
for ( int i = 0; i < exerciseBloc.countSteps; i++) { for (int i = 0; i < exerciseBloc.countSteps; i++) {
Column col = Column( Column col = Column(
mainAxisAlignment: MainAxisAlignment.spaceAround, mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Divider(color: Colors.transparent,), Divider(
color: Colors.transparent,
),
Row( Row(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.baseline, crossAxisAlignment: CrossAxisAlignment.baseline,
children: [ children: [
Text(t("Execute the") + " ",style: TextStyle(fontWeight: FontWeight.bold),), Text(
Text((i+1).toString() + ". ",style: TextStyle(fontSize:24, fontWeight: FontWeight.bold),), t("Execute the") + " ",
Text(t("set!"),style: TextStyle(fontWeight: FontWeight.bold),), style: TextStyle(fontWeight: FontWeight.bold),
),
Text(
(i + 1).toString() + ". ",
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
),
Text(
t("set!"),
style: TextStyle(fontWeight: FontWeight.bold),
),
], ],
), ),
Divider(
color: Colors.transparent,
Divider(color: Colors.transparent,), ),
Text(t("Please repeat with") + " "+ exerciseBloc.unitQuantity.toStringAsFixed(0) + " " + Text(t("Please repeat with") +
exerciseBloc.exerciseRepository.exerciseType.unitQuantityUnit + " " + " " +
exerciseBloc.exercisePlanRepository.getActualPlanDetail().repeats.toString() + " " + t("times!")), exerciseBloc.unitQuantity.toStringAsFixed(0) +
Row( " " +
children: [ exerciseBloc.exerciseRepository.exerciseType.unitQuantityUnit +
" " +
exerciseBloc.exercisePlanRepository.getActualPlanDetail().repeats.toString() +
" " +
t("times!")),
Row(children: [
NumberPicker.horizontal( NumberPicker.horizontal(
highlightSelectedValue: (i + 1) == exerciseBloc.step, highlightSelectedValue: (i + 1) == exerciseBloc.step,
initialValue: exerciseBloc.unitQuantity.toInt(), initialValue: exerciseBloc.unitQuantity.toInt(),
@ -160,38 +154,27 @@ class _ExerciseExecuteAddPage extends State<ExerciseExecutePlanAddPage> with Tra
step: 1, step: 1,
textStyle: TextStyle(fontWeight: FontWeight.bold), textStyle: TextStyle(fontWeight: FontWeight.bold),
textStyleHighlighted: TextStyle(fontSize: 24, color: Colors.indigo, fontWeight: FontWeight.bold), textStyleHighlighted: TextStyle(fontSize: 24, color: Colors.indigo, fontWeight: FontWeight.bold),
onChanged: (value) => { onChanged: (value) => {exerciseBloc.add(ExerciseExecutePlanAddChangeUnitQuantity(quantity: value.toDouble()))},
exerciseBloc.add(ExerciseExecutePlanAddChangeUnitQuantity(quantity: value.toDouble()))
},
listViewHeight: 80, listViewHeight: 80,
//decoration: _decoration, //decoration: _decoration,
), ),
Text(exerciseBloc.exerciseRepository.exerciseType.unitQuantityUnit), Text(exerciseBloc.exerciseRepository.exerciseType.unitQuantityUnit),
] ]),
), Row(children: [
Row(
children: [
NumberPicker.horizontal( NumberPicker.horizontal(
highlightSelectedValue: (i+1) == exerciseBloc.step, highlightSelectedValue: (i + 1) == exerciseBloc.step,
initialValue: exerciseBloc.quantity.toInt(), initialValue: exerciseBloc.quantity.toInt(),
minValue: 0, minValue: 0,
maxValue: 200, maxValue: 200,
step: 1, step: 1,
textStyle: TextStyle(fontWeight: FontWeight.bold), textStyle: TextStyle(fontWeight: FontWeight.bold),
textStyleHighlighted: TextStyle(fontSize: 24, color: Colors.deepOrange, fontWeight: FontWeight.bold), textStyleHighlighted: TextStyle(fontSize: 24, color: Colors.deepOrange, fontWeight: FontWeight.bold),
onChanged: (value) => { onChanged: (value) => {exerciseBloc.add(ExerciseExecutePlanAddChangeQuantity(quantity: value.toDouble()))},
exerciseBloc.add(ExerciseExecutePlanAddChangeQuantity(quantity: value.toDouble()))
},
listViewHeight: 80, listViewHeight: 80,
//decoration: _decoration, //decoration: _decoration,
), ),
Text(t("repeat")), Text(t("repeat")),
] ]),
),
/*TextFieldBlocBuilder( /*TextFieldBlocBuilder(
readOnly: exerciseBloc.step != i+1, readOnly: exerciseBloc.step != i+1,
@ -239,25 +222,19 @@ class _ExerciseExecuteAddPage extends State<ExerciseExecutePlanAddPage> with Tra
), ),
),*/ ),*/
RaisedButton( RaisedButton(
padding: EdgeInsets.all(0), padding: EdgeInsets.all(0),
textColor: Colors.white, textColor: Colors.white,
color: exerciseBloc.step == i+1 ? Colors.blue : Colors.black26, color: exerciseBloc.step == i + 1 ? Colors.blue : Colors.black26,
focusColor: Colors.blueAccent, focusColor: Colors.blueAccent,
onPressed: () => onPressed: () => {
{ print("Submit step " + exerciseBloc.step.toString() + " (i) " + i.toString()),
print ("Submit step " + exerciseBloc.step.toString() + " (i) " + i.toString()), if (exerciseBloc.step == i + 1) {exerciseBloc.add(ExerciseExecutePlanAddSubmit())},
if ( exerciseBloc.step == i+1 ) { if (i + 1 == exerciseBloc.countSteps) {Navigator.of(context).pop()}
exerciseBloc.add(ExerciseExecutePlanAddSubmit())
},
if ( i+1 == exerciseBloc.countSteps) {
Navigator.of(context).pop()
}
}, },
child: Text( child: Text(
t("Save"), t("Save"),
style: TextStyle(fontSize: 12),) style: TextStyle(fontSize: 12),
), )),
Divider(), Divider(),
], ],
); );

View File

@ -1,10 +1,6 @@
import 'package:aitrainer_app/bloc/login_form_bloc.dart';
import 'package:aitrainer_app/bloc/account/account_bloc.dart';
import 'package:aitrainer_app/bloc/reset_password_bloc.dart'; import 'package:aitrainer_app/bloc/reset_password_bloc.dart';
import 'package:aitrainer_app/localization/app_localization.dart'; import 'package:aitrainer_app/localization/app_localization.dart';
import 'package:aitrainer_app/repository/user_repository.dart'; import 'package:aitrainer_app/repository/user_repository.dart';
import 'package:aitrainer_app/service/firebase_api.dart';
import 'package:aitrainer_app/util/common.dart';
import 'package:aitrainer_app/util/trans.dart'; import 'package:aitrainer_app/util/trans.dart';
import 'package:aitrainer_app/widgets/app_bar_min.dart'; import 'package:aitrainer_app/widgets/app_bar_min.dart';
import 'package:aitrainer_app/widgets/splash.dart'; import 'package:aitrainer_app/widgets/splash.dart';
@ -69,20 +65,14 @@ class ResetPasswordPage extends StatelessWidget with Trans {
key: _formKey, key: _formKey,
child: Container( child: Container(
padding: const EdgeInsets.only(left: 25, right: 50), padding: const EdgeInsets.only(left: 25, right: 50),
child: ListView( child: ListView(shrinkWrap: false, padding: EdgeInsets.only(top: 150.0), children: <Widget>[
shrinkWrap: false,
padding: EdgeInsets.only(top: 150.0),
children: <Widget>[
Divider(), Divider(),
Row( Row(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
children: [ children: [
new InkWell( new InkWell(
child: new Text( child: new Text(AppLocalizations.of(context).translate('I forgot the password'),
AppLocalizations.of(context) style: TextStyle(fontWeight: FontWeight.bold, fontSize: 24)),
.translate('I forgot the password'),
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 24)),
), ),
], ],
), ),
@ -102,24 +92,18 @@ class ResetPasswordPage extends StatelessWidget with Trans {
Divider( Divider(
color: Colors.transparent, color: Colors.transparent,
), ),
Row( Row(mainAxisAlignment: MainAxisAlignment.end, children: <Widget>[
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
new FlatButton( new FlatButton(
key: LibraryKeys.loginOKButton, key: LibraryKeys.loginOKButton,
child: Image.asset('asset/image/WT_OK.png', child: Image.asset('asset/image/WT_OK.png', width: 100, height: 100),
width: 100, height: 100),
onPressed: () => {formBloc.add(SubmitFormBloc())}), onPressed: () => {formBloc.add(SubmitFormBloc())}),
]), ]),
Divider( Divider(
color: Colors.transparent, color: Colors.transparent,
), ),
Row( Row(mainAxisAlignment: MainAxisAlignment.spaceAround, children: <Widget>[
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
new InkWell( new InkWell(
child: new Text( child: new Text(AppLocalizations.of(context).translate('Login')),
AppLocalizations.of(context).translate('Login')),
onTap: () => Navigator.of(context).pushNamed('login'), onTap: () => Navigator.of(context).pushNamed('login'),
), ),
Spacer(flex: 1), Spacer(flex: 1),
@ -129,8 +113,7 @@ class ResetPasswordPage extends StatelessWidget with Trans {
} }
void showInSnackBar(String error) { void showInSnackBar(String error) {
_scaffoldKey.currentState.showSnackBar(SnackBar( _scaffoldKey.currentState
backgroundColor: Colors.orange, .showSnackBar(SnackBar(backgroundColor: Colors.orange, content: Text(error, style: TextStyle(color: Colors.white))));
content: Text(error, style: TextStyle(color: Colors.white))));
} }
} }

View File

@ -1,21 +1,11 @@
import 'dart:async';
import 'package:aitrainer_app/bloc/menu/menu_bloc.dart';
import 'package:aitrainer_app/localization/app_localization.dart';
import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/repository/exercise_repository.dart';
import 'package:aitrainer_app/util/common.dart'; import 'package:aitrainer_app/util/common.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:percent_indicator/linear_percent_indicator.dart';
import 'package:rainbow_color/rainbow_color.dart';
// ignore: must_be_immutable // ignore: must_be_immutable
class AppBarMin extends StatefulWidget implements PreferredSizeWidget { class AppBarMin extends StatefulWidget implements PreferredSizeWidget {
bool back = false; bool back = false;
AppBarMin({this.back = false }); AppBarMin({this.back = false});
@override @override
_AppBarNav createState() => _AppBarNav(); _AppBarNav createState() => _AppBarNav();
@ -32,7 +22,6 @@ class _AppBarNav extends State<AppBarMin> with Common {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return AppBar( return AppBar(
backgroundColor: Colors.black, backgroundColor: Colors.black,
title: Row( title: Row(
@ -47,19 +36,14 @@ class _AppBarNav extends State<AppBarMin> with Common {
), ),
leading: IconButton( leading: IconButton(
icon: Icon(Icons.arrow_back, color: widget.back ? Colors.white : Colors.black), icon: Icon(Icons.arrow_back, color: widget.back ? Colors.white : Colors.black),
onPressed: () => onPressed: () => {
{ if (widget.back) {Navigator.of(context).pop()}
if ( widget.back ) {
Navigator.of(context).pop()
}
}, },
) ));
);
} }
@override @override
void dispose() { void dispose() {
super.dispose(); super.dispose();
} }
} }

View File

@ -2,6 +2,7 @@ import 'package:aitrainer_app/bloc/exercise_new/exercise_new_bloc.dart';
import 'package:aitrainer_app/localization/app_localization.dart'; import 'package:aitrainer_app/localization/app_localization.dart';
import 'package:aitrainer_app/util/trans.dart'; import 'package:aitrainer_app/util/trans.dart';
import 'package:animated_widgets/widgets/rotation_animated.dart'; import 'package:animated_widgets/widgets/rotation_animated.dart';
import 'package:flurry/flurry.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
@ -70,6 +71,7 @@ class _BMIState extends State<BMI> with Trans {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
setContext(context); setContext(context);
Flurry.logEvent("BMI");
widget.exerciseBloc.getBMI(); widget.exerciseBloc.getBMI();
return Form( return Form(
child: Scaffold( child: Scaffold(
@ -91,7 +93,7 @@ class _BMIState extends State<BMI> with Trans {
child: child:
Column(crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: [ Column(crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: [
getWeightInput(), getWeightInput(),
Text(AppLocalizations.of(context).translate("Body Mass Index"), Text(t("Body Mass Index"),
style: GoogleFonts.archivoBlack( style: GoogleFonts.archivoBlack(
shadows: <Shadow>[ shadows: <Shadow>[
Shadow( Shadow(

View File

@ -2,6 +2,7 @@ import 'package:aitrainer_app/bloc/exercise_new/exercise_new_bloc.dart';
import 'package:aitrainer_app/localization/app_localization.dart'; import 'package:aitrainer_app/localization/app_localization.dart';
import 'package:aitrainer_app/model/fitness_state.dart'; import 'package:aitrainer_app/model/fitness_state.dart';
import 'package:aitrainer_app/util/trans.dart'; import 'package:aitrainer_app/util/trans.dart';
import 'package:flurry/flurry.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
@ -74,6 +75,7 @@ class _BMRState extends State<BMR> with Trans {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
setContext(context); setContext(context);
Flurry.logEvent("BMR");
return Form( return Form(
child: Scaffold( child: Scaffold(
resizeToAvoidBottomInset: true, resizeToAvoidBottomInset: true,

View File

@ -1,4 +1,8 @@
import 'package:aitrainer_app/localization/app_localization.dart'; import 'package:aitrainer_app/localization/app_localization.dart';
import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/util/trans.dart';
import 'package:badges/badges.dart';
import 'package:flurry/flurry.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:gradient_bottom_navigation_bar/gradient_bottom_navigation_bar.dart'; import 'package:gradient_bottom_navigation_bar/gradient_bottom_navigation_bar.dart';
@ -13,7 +17,7 @@ class BottomNavigator extends StatefulWidget {
_NawDrawerWidget createState() => _NawDrawerWidget(); _NawDrawerWidget createState() => _NawDrawerWidget();
} }
class _NawDrawerWidget extends State<BottomNavigator> { class _NawDrawerWidget extends State<BottomNavigator> with Trans {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
@ -25,32 +29,19 @@ class _NawDrawerWidget extends State<BottomNavigator> {
final Color bgrColorEnd = Colors.blue; final Color bgrColorEnd = Colors.blue;
final Color active = Colors.black; final Color active = Colors.black;
final Color inactive = Colors.black26; final Color inactive = Colors.black26;
setContext(context);
/*final Color bgrColor = Colors.black;
final Color active = Colors.yellowAccent;
final Color inactive = Colors.white60;*/
//
return GradientBottomNavigationBar( return GradientBottomNavigationBar(
currentIndex: currentIndex: widget.bottomNavIndex, // this will be set when a new tab is tapped
widget.bottomNavIndex, // this will be set when a new tab is tapped
backgroundColorStart: bgrColorEnd, backgroundColorStart: bgrColorEnd,
backgroundColorEnd: bgrColor, backgroundColorEnd: bgrColor,
fixedColor: active, fixedColor: active,
//selectedItemColor: active,
//unselectedItemColor: inactive,
//showSelectedLabels: true,
//showUnselectedLabels: true,
items: [ items: [
BottomNavigationBarItem( BottomNavigationBarItem(
backgroundColor: bgrColor, backgroundColor: bgrColor,
icon: new Icon(Icons.home, color: inactive), icon: badgedIcon(inactive, Icons.home, "home"),
activeIcon: new Icon( activeIcon: badgedIcon(active, Icons.home, "home"),
Icons.home, title: new Text(t("Home"), style: TextStyle(fontSize: 12)),
color: active,
),
title: new Text(AppLocalizations.of(context).translate("Home"),
style: TextStyle(fontSize: 9)),
), ),
BottomNavigationBarItem( BottomNavigationBarItem(
backgroundColor: bgrColor, backgroundColor: bgrColor,
@ -60,8 +51,8 @@ class _NawDrawerWidget extends State<BottomNavigator> {
color: active, color: active,
), ),
title: new Text( title: new Text(
AppLocalizations.of(context).translate("My Development"), t("My Development"),
style: TextStyle(fontSize: 9), style: TextStyle(fontSize: 12),
), ),
), ),
BottomNavigationBarItem( BottomNavigationBarItem(
@ -72,23 +63,17 @@ class _NawDrawerWidget extends State<BottomNavigator> {
color: active, color: active,
), ),
title: new Text( title: new Text(
AppLocalizations.of(context).translate("My Training Plan"), t("My Training Plan"),
style: TextStyle(fontSize: 9), style: TextStyle(fontSize: 12),
), ),
), ),
BottomNavigationBarItem( BottomNavigationBarItem(
backgroundColor: bgrColor, backgroundColor: bgrColor,
icon: Icon( icon: badgedIcon(inactive, Icons.person, "account"),
Icons.person, activeIcon: badgedIcon(active, Icons.person, "account"),
color: inactive,
),
activeIcon: new Icon(
Icons.person,
color: active,
),
title: Text( title: Text(
AppLocalizations.of(context).translate("Account"), AppLocalizations.of(context).translate("Account"),
style: TextStyle(fontSize: 9), style: TextStyle(fontSize: 12),
)), )),
BottomNavigationBarItem( BottomNavigationBarItem(
backgroundColor: bgrColor, backgroundColor: bgrColor,
@ -97,8 +82,7 @@ class _NawDrawerWidget extends State<BottomNavigator> {
Icons.settings, Icons.settings,
color: active, color: active,
), ),
title: Text(AppLocalizations.of(context).translate("Settings"), title: Text(t("Settings"), style: TextStyle(fontSize: 12)))
style: TextStyle(fontSize: 9)))
], ],
onTap: (index) { onTap: (index) {
setState(() { setState(() {
@ -106,25 +90,30 @@ class _NawDrawerWidget extends State<BottomNavigator> {
switch (index) { switch (index) {
case 0: case 0:
Navigator.of(context).pop(); Navigator.of(context).pop();
Flurry.logEvent("Home");
Navigator.of(context).pushNamed('home'); Navigator.of(context).pushNamed('home');
break; break;
case 1: case 1:
Navigator.of(context).pop(); Navigator.of(context).pop();
Flurry.logEvent("myDevelopment");
Navigator.of(context).pushNamed('myDevelopment'); Navigator.of(context).pushNamed('myDevelopment');
break; break;
case 2: case 2:
Navigator.of(context).pop(); Navigator.of(context).pop();
Flurry.logEvent("myExercisePlan");
Navigator.of(context).pushNamed('myExercisePlan'); Navigator.of(context).pushNamed('myExercisePlan');
break; break;
case 3: case 3:
Navigator.of(context).pop(); Navigator.of(context).pop();
Flurry.logEvent("Account");
Navigator.of(context).pushNamed('account'); Navigator.of(context).pushNamed('account');
break; break;
case 4: case 4:
Navigator.of(context).pop(); Navigator.of(context).pop();
Flurry.logEvent("Settings");
Navigator.of(context).pushNamed('settings'); Navigator.of(context).pushNamed('settings');
break; break;
@ -132,4 +121,24 @@ class _NawDrawerWidget extends State<BottomNavigator> {
}); });
}); });
} }
Widget badgedIcon(Color color, IconData icon, String badgeKey) {
bool show = Cache().getBadges()[badgeKey] != null;
int counter = Cache().getBadges()[badgeKey] != null ? Cache().getBadges()[badgeKey] : 0;
return Badge(
position: BadgePosition.topEnd(top: -10, end: -10),
animationDuration: Duration(milliseconds: 500),
animationType: BadgeAnimationType.slide,
badgeColor: Colors.red,
showBadge: show,
badgeContent: Text(
counter.toString(),
style: TextStyle(color: Colors.white),
),
child: Icon(
icon,
color: color,
),
);
}
} }

View File

@ -1,7 +1,10 @@
import 'dart:ui';
import 'package:aitrainer_app/model/cache.dart'; import 'package:aitrainer_app/model/cache.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:bloc/bloc.dart'; import 'package:bloc/bloc.dart';
import 'package:google_fonts/google_fonts.dart';
// ignore: must_be_immutable // ignore: must_be_immutable
class ImageButton extends StatelessWidget { class ImageButton extends StatelessWidget {
@ -10,13 +13,15 @@ class ImageButton extends StatelessWidget {
final String image; final String image;
final double top; final double top;
final double left; final double left;
final double height; double height;
double width = 180; double width;
final bool isShape; bool isShape;
final Bloc bloc; final Bloc bloc;
final Alignment textAlignment; final Alignment textAlignment;
final VoidCallback onTap; final VoidCallback onTap;
bool isLocked; bool isLocked;
bool isMarked;
int buttonIndex;
ImageButton( ImageButton(
{this.text, {this.text,
@ -30,20 +35,23 @@ class ImageButton extends StatelessWidget {
this.isShape, this.isShape,
this.textAlignment, this.textAlignment,
this.onTap, this.onTap,
this.buttonIndex,
this.isMarked,
@required this.isLocked}) { @required this.isLocked}) {
width = width ?? 180; width = width ?? 180;
style = style ?? TextStyle(fontSize: 14, fontFamily: "Roboto Mono"); height = height ?? 180;
isMarked = isMarked ?? false;
style = style ??
GoogleFonts.archivoBlack(
fontSize: 14,
);
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
double top = width - (style.fontSize - 5) * text.length - 2 * left < 0 double top =
? width - 2 * style.fontSize - 10 height - (style.fontSize - 5) * text.length - 2 * left < 0 ? height - 2 * style.fontSize - 22 : height - style.fontSize - 17;
: width - style.fontSize - 10; //print("Top: " + top.toStringAsFixed(0) + " length: " + ((style.fontSize - 5) * text.length).toString());
print("Top: " +
top.toStringAsFixed(0) +
" length: " +
((style.fontSize - 5) * text.length).toString());
return Stack( return Stack(
//alignment: textAlignment, //alignment: textAlignment,
fit: StackFit.passthrough, fit: StackFit.passthrough,
@ -52,24 +60,27 @@ class ImageButton extends StatelessWidget {
FlatButton( FlatButton(
child: image == null child: image == null
? _getButtonImage("asset/image/WT_menu_dark.png") ? _getButtonImage("asset/image/WT_menu_dark.png")
: isMarked
? Stack(
children: [
_getButtonImage(image),
Container(
width: width,
height: height,
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 1, sigmaY: 1),
child: Container(
color: Colors.black.withOpacity(0.3),
),
),
)
],
)
: _getButtonImage(image), : _getButtonImage(image),
padding: EdgeInsets.only(left: 0.0, bottom: 0), padding: EdgeInsets.only(left: 0.0, bottom: 0),
shape: getShape(isShape), shape: getShape(isShape),
onPressed: onTap ?? onTap, onPressed: onTap ?? onTap,
), ),
Stack(alignment: Alignment.topLeft, children: [
Positioned(
top: 50,
left: 50,
child: this.isLocked
? Image.asset(
'asset/image/lock.png',
height: 60,
width: 60,
)
: Container(),
)
]),
Positioned( Positioned(
top: top, top: top,
left: left, left: left,
@ -87,6 +98,31 @@ class ImageButton extends StatelessWidget {
color: Colors.transparent, color: Colors.transparent,
), ),
), ),
Stack(alignment: Alignment.topLeft, children: [
Positioned(
top: height / 2 - 30,
left: width / 2 - 30,
child: this.isLocked
? GestureDetector(
child: Image.asset(
'asset/image/lock.png',
height: 60,
width: 60,
),
onTap: onTap ?? onTap,
)
: isMarked
? GestureDetector(
child: Image.asset(
'asset/image/haken.png',
height: 70,
width: 70,
),
onTap: onTap ?? onTap,
)
: Container(),
)
]),
] ]
//) //)
// ) // )
@ -110,12 +146,8 @@ class ImageButton extends StatelessWidget {
fit: BoxFit.fitWidth, fit: BoxFit.fitWidth,
alignment: Alignment.center, alignment: Alignment.center,
errorBuilder: (context, error, stackTrace) { errorBuilder: (context, error, stackTrace) {
String url = Cache.mediaUrl + 'images/' + imageName.substring(11); String url = Cache.mediaUrl + '/' + imageName; //.substring(11);
Widget image = FadeInImage.assetNetwork( Widget image = FadeInImage.assetNetwork(placeholder: 'asset/image/dots.gif', image: url, height: this.height);
placeholder: 'asset/image/dots.gif',
image: url,
height: 180,
);
return image; return image;
}, },
); );
@ -124,7 +156,7 @@ class ImageButton extends StatelessWidget {
image = FadeInImage.assetNetwork( image = FadeInImage.assetNetwork(
placeholder: 'asset/image/dots.gif', placeholder: 'asset/image/dots.gif',
image: url, image: url,
height: 180, height: 50,
); );
} }

View File

@ -5,6 +5,7 @@ import 'package:aitrainer_app/localization/app_localization.dart';
import 'package:aitrainer_app/model/cache.dart'; import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/model/workout_menu_tree.dart'; import 'package:aitrainer_app/model/workout_menu_tree.dart';
import 'package:aitrainer_app/util/trans.dart'; import 'package:aitrainer_app/util/trans.dart';
import 'package:badges/badges.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/painting.dart'; import 'package:flutter/painting.dart';
@ -24,15 +25,13 @@ class MenuPageWidget extends StatelessWidget with Trans {
MenuBloc menuBloc = BlocProvider.of<MenuBloc>(context); MenuBloc menuBloc = BlocProvider.of<MenuBloc>(context);
setContext(context); setContext(context);
return CustomScrollView( return CustomScrollView(scrollDirection: Axis.vertical, slivers: <Widget>[buildMenuColumn(parent, context, menuBloc)]);
scrollDirection: Axis.vertical,
slivers: <Widget>[buildMenuColumn(parent, context, menuBloc)]);
} }
SliverList buildMenuColumn(int parent, BuildContext context, MenuBloc menuBloc) { SliverList buildMenuColumn(int parent, BuildContext context, MenuBloc menuBloc) {
final List<Widget> _columnChildren = List(); final List<Widget> _columnChildren = List();
if ( context != null ) { if (context != null) {
menuBloc.setContext(context); menuBloc.setContext(context);
menuBloc.setMenuInfo(); menuBloc.setMenuInfo();
@ -52,20 +51,16 @@ class MenuPageWidget extends StatelessWidget with Trans {
_columnChildren.add(info); _columnChildren.add(info);
} }
menuBloc.menuTreeRepository.getBranch(menuBloc.parent).forEach((treeName, value) {
menuBloc.menuTreeRepository
.getBranch(menuBloc.parent)
.forEach((treeName, value) {
WorkoutMenuTree workoutTree = value as WorkoutMenuTree; WorkoutMenuTree workoutTree = value as WorkoutMenuTree;
_columnChildren.add(Container( _columnChildren.add(Container(
padding: EdgeInsets.only(top: 16.0), padding: EdgeInsets.only(top: 16.0),
child: Center( child: Center(
child: Stack( child: Stack(alignment: Alignment.bottomLeft,
alignment: Alignment.bottomLeft,
//clipBehavior: Clip.antiAliasWithSaveLayer, //clipBehavior: Clip.antiAliasWithSaveLayer,
children: [ children: [
FlatButton( FlatButton(
child: _getButtonImage(workoutTree), child: badgedIcon(workoutTree),
padding: EdgeInsets.only(left: 0.0, bottom: 0), padding: EdgeInsets.only(left: 0.0, bottom: 0),
shape: getShape(workoutTree), shape: getShape(workoutTree),
onPressed: () => menuClick(workoutTree, menuBloc, context), onPressed: () => menuClick(workoutTree, menuBloc, context),
@ -77,7 +72,7 @@ class MenuPageWidget extends StatelessWidget with Trans {
height: 300, height: 300,
width: 280, width: 280,
child: InkWell( child: InkWell(
onTap:() => menuClick(workoutTree, menuBloc, context), onTap: () => menuClick(workoutTree, menuBloc, context),
child: Text( child: Text(
" " + workoutTree.name, " " + workoutTree.name,
maxLines: 2, maxLines: 2,
@ -86,28 +81,20 @@ class MenuPageWidget extends StatelessWidget with Trans {
fontSize: workoutTree.fontSize, fontSize: workoutTree.fontSize,
), ),
), ),
highlightColor: workoutTree.color, highlightColor: workoutTree.color,
), ),
color: Colors.transparent, color: Colors.transparent,
), ),
), ),
]))));
]
)
)
)
);
}); });
SliverList sliverList = SliverList sliverList = SliverList(delegate: SliverChildListDelegate(_columnChildren));
SliverList(delegate: SliverChildListDelegate(_columnChildren));
return sliverList; return sliverList;
} }
void menuClick( void menuClick(WorkoutMenuTree workoutTree, MenuBloc menuBloc, BuildContext context) {
WorkoutMenuTree workoutTree, MenuBloc menuBloc, BuildContext context) {
print("Hi!, Menu clicked " + workoutTree.id.toString()); print("Hi!, Menu clicked " + workoutTree.id.toString());
if (workoutTree.child == false) { if (workoutTree.child == false) {
menuBloc.add(MenuTreeDown(item: workoutTree, parent: workoutTree.id)); menuBloc.add(MenuTreeDown(item: workoutTree, parent: workoutTree.id));
@ -116,16 +103,12 @@ class MenuPageWidget extends StatelessWidget with Trans {
if (Cache().userLoggedIn == null) { if (Cache().userLoggedIn == null) {
Scaffold.of(context).showSnackBar(SnackBar( Scaffold.of(context).showSnackBar(SnackBar(
backgroundColor: Colors.orange, backgroundColor: Colors.orange,
content: Text( content: Text(AppLocalizations.of(context).translate('Please log in'), style: TextStyle(color: Colors.white))));
AppLocalizations.of(context).translate('Please log in'),
style: TextStyle(color: Colors.white))));
} else { } else {
if (workoutTree.exerciseType.name == "Custom" && Cache().userLoggedIn.admin == 1) { if (workoutTree.exerciseType.name == "Custom" && Cache().userLoggedIn.admin == 1) {
Navigator.of(context).pushNamed('exerciseCustomPage', Navigator.of(context).pushNamed('exerciseCustomPage', arguments: workoutTree.exerciseType);
arguments: workoutTree.exerciseType);
} else { } else {
Navigator.of(context).pushNamed('exerciseNewPage', Navigator.of(context).pushNamed('exerciseNewPage', arguments: workoutTree.exerciseType);
arguments: workoutTree.exerciseType);
} }
} }
} }
@ -148,8 +131,7 @@ class MenuPageWidget extends StatelessWidget with Trans {
workoutTree.imageName, workoutTree.imageName,
height: 180, height: 180,
errorBuilder: (context, error, stackTrace) { errorBuilder: (context, error, stackTrace) {
String url = String url = Cache.mediaUrl + 'images/' + workoutTree.imageName.substring(11);
Cache.mediaUrl + 'images/' + workoutTree.imageName.substring(11);
Widget image = FadeInImage.assetNetwork( Widget image = FadeInImage.assetNetwork(
placeholder: 'asset/image/dots.gif', placeholder: 'asset/image/dots.gif',
image: url, image: url,
@ -169,4 +151,24 @@ class MenuPageWidget extends StatelessWidget with Trans {
return image; return image;
} }
Widget badgedIcon(WorkoutMenuTree workoutMenuTree) {
String badgeKey = workoutMenuTree.nameEnglish;
bool show = Cache().getBadges()[badgeKey] != null;
int counter = Cache().getBadges()[badgeKey] != null ? Cache().getBadges()[badgeKey] : 0;
return Badge(
padding: EdgeInsets.all(8),
position: BadgePosition.topEnd(top: 3, end: 3),
animationDuration: Duration(milliseconds: 500),
animationType: BadgeAnimationType.slide,
badgeColor: Colors.red,
showBadge: show,
badgeContent: Text(counter.toString(),
style: TextStyle(
color: Colors.white,
fontSize: 16,
)),
child: _getButtonImage(workoutMenuTree),
);
}
} }

View File

@ -52,7 +52,7 @@ class _SizeState extends State<SizeWidget> with Trans {
List<Widget> getSizeFigure() { List<Widget> getSizeFigure() {
double mediaWidth = MediaQuery.of(context).size.width * .8; double mediaWidth = MediaQuery.of(context).size.width * .8;
double mediaHeight = MediaQuery.of(context).size.height * .8; double mediaHeight = MediaQuery.of(context).size.height * .8;
print("w " + mediaWidth.toString() + "h " + mediaHeight.toString()); //print("w " + mediaWidth.toString() + "h " + mediaHeight.toString());
widget.exerciseBloc.setMediaDimensions(mediaWidth, mediaHeight); widget.exerciseBloc.setMediaDimensions(mediaWidth, mediaHeight);
List<Widget> list = List(); List<Widget> list = List();
list.add(GestureDetector( list.add(GestureDetector(

View File

@ -43,6 +43,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.5.0-nullsafety.1" version: "2.5.0-nullsafety.1"
badges:
dependency: "direct main"
description:
name: badges
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.4"
bloc: bloc:
dependency: transitive dependency: transitive
description: description:
@ -70,14 +77,14 @@ packages:
name: build name: build
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.5.0" version: "1.5.1"
build_config: build_config:
dependency: transitive dependency: transitive
description: description:
name: build_config name: build_config
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.4.2" version: "0.4.3"
build_daemon: build_daemon:
dependency: transitive dependency: transitive
description: description:
@ -98,14 +105,14 @@ packages:
name: build_runner name: build_runner
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.10.4" version: "1.10.6"
build_runner_core: build_runner_core:
dependency: transitive dependency: transitive
description: description:
name: build_runner_core name: build_runner_core
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "6.0.3" version: "6.1.1"
built_collection: built_collection:
dependency: transitive dependency: transitive
description: description:
@ -203,7 +210,7 @@ packages:
name: dart_style name: dart_style
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.3.9" version: "1.3.10"
devicelocale: devicelocale:
dependency: "direct main" dependency: "direct main"
description: description:
@ -217,7 +224,7 @@ packages:
name: dropdown_search name: dropdown_search
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.4.6" version: "0.4.8"
equatable: equatable:
dependency: "direct main" dependency: "direct main"
description: description:
@ -246,41 +253,34 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "6.0.0-nullsafety.2" version: "6.0.0-nullsafety.2"
firebase:
dependency: transitive
description:
name: firebase
url: "https://pub.dartlang.org"
source: hosted
version: "7.3.2"
firebase_auth: firebase_auth:
dependency: "direct main" dependency: "direct main"
description: description:
name: firebase_auth name: firebase_auth
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.18.1+2" version: "0.18.3"
firebase_auth_platform_interface: firebase_auth_platform_interface:
dependency: transitive dependency: transitive
description: description:
name: firebase_auth_platform_interface name: firebase_auth_platform_interface
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.1" version: "2.1.3"
firebase_auth_web: firebase_auth_web:
dependency: transitive dependency: transitive
description: description:
name: firebase_auth_web name: firebase_auth_web
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.3.1+1" version: "0.3.2"
firebase_core: firebase_core:
dependency: "direct main" dependency: "direct main"
description: description:
name: firebase_core name: firebase_core
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.5.0+1" version: "0.5.2"
firebase_core_platform_interface: firebase_core_platform_interface:
dependency: transitive dependency: transitive
description: description:
@ -316,6 +316,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.12.0" version: "0.12.0"
flurry:
dependency: "direct main"
description:
name: flurry
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.7"
flutter: flutter:
dependency: "direct main" dependency: "direct main"
description: flutter description: flutter
@ -333,13 +340,6 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.0" version: "0.0.0"
flutter_facebook_auth:
dependency: "direct main"
description:
name: flutter_facebook_auth
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.3"
flutter_form_bloc: flutter_form_bloc:
dependency: "direct main" dependency: "direct main"
description: description:
@ -492,7 +492,7 @@ packages:
name: json_annotation name: json_annotation
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "3.1.0" version: "3.1.1"
json_rpc_2: json_rpc_2:
dependency: transitive dependency: transitive
description: description:
@ -1001,7 +1001,7 @@ packages:
name: win32 name: win32
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.7.3" version: "1.7.4"
xdg_directories: xdg_directories:
dependency: transitive dependency: transitive
description: description:

View File

@ -15,10 +15,10 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at # Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.1.2+2 version: 1.1.2+34
environment: environment:
sdk: ">=2.7.0 <3.1.0" sdk: ">=2.10.0 <3.0.0"
dependencies: dependencies:
flutter: flutter:
@ -28,9 +28,9 @@ dependencies:
google_fonts: ^1.1.1 google_fonts: ^1.1.1
devicelocale: ^0.3.3 devicelocale: ^0.3.3
sentry: ^3.0.1 sentry: ^3.0.1
flutter_bloc: ^6.1.0 flutter_bloc: ^6.1.1
equatable: ^1.2.5 equatable: ^1.2.5
freezed: ^0.12.1 freezed: ^0.12.2
flutter_form_bloc: ^0.19.0 flutter_form_bloc: ^0.19.0
spider_chart: ^0.1.5 spider_chart: ^0.1.5
rainbow_color: ^0.1.1 rainbow_color: ^0.1.1
@ -40,16 +40,19 @@ dependencies:
infinite_listview: ^1.0.1+1 infinite_listview: ^1.0.1+1
toggle_switch: ^0.1.8 toggle_switch: ^0.1.8
keyboard_actions: ^3.3.1+1 keyboard_actions: ^3.3.1+1
dropdown_search: ^0.4.6 dropdown_search: ^0.4.8
badges: ^1.1.4
firebase_core: 0.5.0+1 firebase_core: ^0.5.2
#firebase_analytics: ^6.0.2 #firebase_analytics: ^6.2.0
firebase_messaging: ^7.0.3 firebase_messaging: ^7.0.3
firebase_auth: ^0.18.1+2 firebase_auth: ^0.18.3
flutter_facebook_auth: ^0.3.3 #flutter_facebook_auth: ^1.0.1
flurry: ^0.0.7
animated_widgets: ^1.0.6 animated_widgets: ^1.0.6
mockito: ^4.1.1 mockito: ^4.1.3
flutter_localizations: flutter_localizations:
sdk: flutter sdk: flutter
@ -63,9 +66,9 @@ dev_dependencies:
build_runner: build_runner:
http: 0.12.1 http: ^0.12.1
intl: 0.16.1 intl: ^0.16.1
shared_preferences: ^0.5.12+2 shared_preferences: ^0.5.12+4
flutter_launcher_icons: ^0.8.1 flutter_launcher_icons: ^0.8.1
@ -126,6 +129,27 @@ flutter:
- asset/image/BMI_diagram_b.png - asset/image/BMI_diagram_b.png
- asset/image/BMI_graph_c.png - asset/image/BMI_graph_c.png
- asset/image/BMI_mutato.png - asset/image/BMI_mutato.png
- asset/image/equipment_specialshome.jpg
- asset/image/equipment_none.jpg
- asset/image/equipment_cables.jpg
- asset/image/equipment_weightplates.jpg
- asset/image/equipment_kettlebells.jpg
- asset/image/equipment_bands.jpg
- asset/image/equipment_ez-baar_.jpg
- asset/image/equipment_exerciseball.jpg
- asset/image/equipment_strap.jpg
- asset/image/equipment_roll.jpg
- asset/image/equipment_instabils.jpg
- asset/image/equipment_medicine.jpg
- asset/image/equipment_rope.jpg
- asset/image/equipment_home.jpg
- asset/image/equipment_baar.jpg
- asset/image/equipment_others.jpg
- asset/image/equipment_barbells.jpg
- asset/image/equipment_machine.jpg
- asset/image/equipment_street.jpg
- asset/image/equipment_dumbbells.jpg
- asset/image/haken.png
- asset/menu/1.cardio.png - asset/menu/1.cardio.png
- asset/menu/1.1.aerob.png - asset/menu/1.1.aerob.png
- asset/menu/1.2.anaerob.png - asset/menu/1.2.anaerob.png

View File

@ -2,6 +2,7 @@ import 'package:aitrainer_app/bloc/exercise_plan/exercise_plan_bloc.dart';
import 'package:aitrainer_app/model/cache.dart'; import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/model/exercise_plan.dart'; import 'package:aitrainer_app/model/exercise_plan.dart';
import 'package:aitrainer_app/model/exercise_plan_detail.dart'; import 'package:aitrainer_app/model/exercise_plan_detail.dart';
import 'package:aitrainer_app/model/model_change.dart';
import 'package:aitrainer_app/repository/workout_tree_repository.dart'; import 'package:aitrainer_app/repository/workout_tree_repository.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
@ -65,17 +66,14 @@ main() {
bloc.customerId = 101; bloc.customerId = 101;
bloc.add(ExercisePlanLoad()); bloc.add(ExercisePlanLoad());
final expectedResponse = [ final expectedResponse = [ExercisePlanLoading(), ExercisePlanReady()];
ExercisePlanLoading(),
ExercisePlanReady()
];
expectLater( expectLater(
bloc, bloc,
emitsInOrder(expectedResponse), emitsInOrder(expectedResponse),
).then((_) { ).then((_) {
expect(bloc.exercisePlanRepository.newPlan, false); expect(bloc.exercisePlanRepository.newPlan, false);
expect(bloc.exercisePlanRepository.exercisePlan.name, "Test Plan2" ); expect(bloc.exercisePlanRepository.exercisePlan.name, "Test Plan2");
expect(bloc.exercisePlanRepository.exercisePlanDetails[4].weightEquation, "95"); expect(bloc.exercisePlanRepository.exercisePlanDetails[4].weightEquation, "95");
expect(Cache().getMyExercisePlan().name, "Test Plan2"); expect(Cache().getMyExercisePlan().name, "Test Plan2");
expect(Cache().getMyExercisePlanDetails()[4].weightEquation, "95"); expect(Cache().getMyExercisePlanDetails()[4].weightEquation, "95");
@ -93,14 +91,9 @@ main() {
detail4.weightEquation = "55"; detail4.weightEquation = "55";
detail4.serie = 3; detail4.serie = 3;
bloc.add(ExercisePlanAddExercise(exercisePlanDetail: detail4)); bloc.add(ExercisePlanAddExercise(exercisePlanDetail: detail4));
final expectedResponse2 = [ final expectedResponse2 = [ExercisePlanLoading(), ExercisePlanReady()];
ExercisePlanLoading(),
ExercisePlanReady()
];
expectLater( expectLater(
bloc, bloc,
@ -110,10 +103,8 @@ main() {
expect(bloc.exercisePlanRepository.exercisePlan.customerId, 101); expect(bloc.exercisePlanRepository.exercisePlan.customerId, 101);
expect(bloc.exercisePlanRepository.exercisePlanDetails.length, 3); expect(bloc.exercisePlanRepository.exercisePlanDetails.length, 3);
expect(bloc.exercisePlanRepository.exercisePlanDetails[5].repeats, 20); expect(bloc.exercisePlanRepository.exercisePlanDetails[5].repeats, 20);
expect(bloc.exercisePlanRepository.exercisePlanDetails[5].change, ExercisePlanDetailChange.add); expect(bloc.exercisePlanRepository.exercisePlanDetails[5].change, ModelChange.add);
expect(Cache() expect(Cache().getMyExercisePlan().name, "Test Plan2");
.getMyExercisePlan()
.name, "Test Plan2");
expect(Cache().getMyExercisePlanDetails()[5].weightEquation, "55"); expect(Cache().getMyExercisePlanDetails()[5].weightEquation, "55");
expect(Cache().getMyExercisePlanDetails()[5].repeats, 20); expect(Cache().getMyExercisePlanDetails()[5].repeats, 20);
}); });
@ -127,10 +118,7 @@ main() {
bloc.add(ExercisePlanAddExercise(exercisePlanDetail: bloc.exercisePlanRepository.exercisePlanDetails[3])); bloc.add(ExercisePlanAddExercise(exercisePlanDetail: bloc.exercisePlanRepository.exercisePlanDetails[3]));
final expectedResponse2 = [ final expectedResponse2 = [ExercisePlanLoading(), ExercisePlanReady()];
ExercisePlanLoading(),
ExercisePlanReady()
];
expectLater( expectLater(
bloc, bloc,
@ -140,7 +128,6 @@ main() {
expect(bloc.exercisePlanRepository.exercisePlanDetails[3].repeats, 25); expect(bloc.exercisePlanRepository.exercisePlanDetails[3].repeats, 25);
expect(Cache().getMyExercisePlanDetails()[3].repeats, 25); expect(Cache().getMyExercisePlanDetails()[3].repeats, 25);
}); });
}); });
test('Delete bloc', () async { test('Delete bloc', () async {
bloc.customerId = 101; bloc.customerId = 101;
@ -148,10 +135,7 @@ main() {
bloc.exercisePlanRepository.getExercisePlanDetails(); bloc.exercisePlanRepository.getExercisePlanDetails();
bloc.add(ExercisePlanRemoveExercise(exercisePlanDetail: bloc.exercisePlanRepository.exercisePlanDetails[3])); bloc.add(ExercisePlanRemoveExercise(exercisePlanDetail: bloc.exercisePlanRepository.exercisePlanDetails[3]));
final expectedResponse2 = [ final expectedResponse2 = [ExercisePlanLoading(), ExercisePlanReady()];
ExercisePlanLoading(),
ExercisePlanReady()
];
expectLater( expectLater(
bloc, bloc,
@ -184,7 +168,5 @@ main() {
expect(bloc.exercisePlanRepository.exercisePlanDetails.length, 0); expect(bloc.exercisePlanRepository.exercisePlanDetails.length, 0);
});*/ });*/
}); });
});
});
} }

View File

@ -1,16 +1,15 @@
import 'package:aitrainer_app/model/cache.dart'; import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/model/exercise_plan.dart'; import 'package:aitrainer_app/model/exercise_plan.dart';
import 'package:aitrainer_app/model/exercise_plan_detail.dart'; import 'package:aitrainer_app/model/exercise_plan_detail.dart';
import 'package:aitrainer_app/model/model_change.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
import 'mocks.dart'; import 'mocks.dart';
main() { main() {
SimExercisePlanRepository _exercisePlanRepository; SimExercisePlanRepository _exercisePlanRepository;
int _customerId; int _customerId;
Future<void> setUpPlan() async { Future<void> setUpPlan() async {
final String planName2 = "Test Plan2"; final String planName2 = "Test Plan2";
ExercisePlan plan2 = ExercisePlan(planName2, 101); ExercisePlan plan2 = ExercisePlan(planName2, 101);
_exercisePlanRepository.setCustomerId(101); _exercisePlanRepository.setCustomerId(101);
@ -40,8 +39,6 @@ main() {
await setUpPlan(); await setUpPlan();
}); });
group('New Plan', () { group('New Plan', () {
test('add new plan and plan details and save', () async { test('add new plan and plan details and save', () async {
final String planName = "Boss Test Plan"; final String planName = "Boss Test Plan";
@ -69,11 +66,8 @@ main() {
expect(_exercisePlanRepository.getExercisePlan().name, planName); expect(_exercisePlanRepository.getExercisePlan().name, planName);
expect(_exercisePlanRepository.getExercisePlan().exercisePlanId > 0, true); expect(_exercisePlanRepository.getExercisePlan().exercisePlanId > 0, true);
ExercisePlanDetail detail = ExercisePlanDetail detail = _exercisePlanRepository.getExercisePlanDetailByExerciseId(55);
_exercisePlanRepository.getExercisePlanDetailByExerciseId(55);
expect(detail.exercisePlanId, _exercisePlanRepository.getExercisePlan().exercisePlanId); expect(detail.exercisePlanId, _exercisePlanRepository.getExercisePlan().exercisePlanId);
}); });
test('save new plan and plan details second', () async { test('save new plan and plan details second', () async {
int customerId = 100; int customerId = 100;
@ -104,23 +98,21 @@ main() {
ExercisePlanDetail detail = _exercisePlanRepository.getExercisePlanDetailByExerciseId(13); ExercisePlanDetail detail = _exercisePlanRepository.getExercisePlanDetailByExerciseId(13);
expect(detail.exercisePlanId, _exercisePlanRepository.getExercisePlan().exercisePlanId); expect(detail.exercisePlanId, _exercisePlanRepository.getExercisePlan().exercisePlanId);
expect(detail.repeats, 33); expect(detail.repeats, 33);
}); });
}); });
group('Existing Plan', () { group('Existing Plan', () {
test('Get Last Plan and Details from DB', () async { test('Get Last Plan and Details from DB', () async {
ExercisePlan exercisePlan = await _exercisePlanRepository.getLastExercisePlan(); ExercisePlan exercisePlan = await _exercisePlanRepository.getLastExercisePlan();
expect(exercisePlan.customerId,101); expect(exercisePlan.customerId, 101);
await _exercisePlanRepository.getExercisePlanDetails(); await _exercisePlanRepository.getExercisePlanDetails();
expect(_exercisePlanRepository.exercisePlanDetails[3].repeats,23 ); expect(_exercisePlanRepository.exercisePlanDetails[3].repeats, 23);
expect(_exercisePlanRepository.exercisePlanDetails[4].weightEquation,"95" ); expect(_exercisePlanRepository.exercisePlanDetails[4].weightEquation, "95");
//Test Cache //Test Cache
expect(Cache().getMyExercisePlan().name,"Test Plan2"); expect(Cache().getMyExercisePlan().name, "Test Plan2");
expect(Cache().getMyExercisePlanDetails()[3].weightEquation,"60"); expect(Cache().getMyExercisePlanDetails()[3].weightEquation, "60");
}); });
test('Add new PlanDetail', () async { test('Add new PlanDetail', () async {
@ -138,20 +130,14 @@ main() {
expect(_exercisePlanRepository.getExercisePlan().name, "Test Plan2"); expect(_exercisePlanRepository.getExercisePlan().name, "Test Plan2");
expect(Cache().getMyExercisePlanDetails()[5].weightEquation, "105"); expect(Cache().getMyExercisePlanDetails()[5].weightEquation, "105");
expect(Cache().getMyExercisePlanDetails()[5].repeats, 6); expect(Cache().getMyExercisePlanDetails()[5].repeats, 6);
}); });
test('Delete from PlanDetails', () async { test('Delete from PlanDetails', () async {
_exercisePlanRepository.removeExerciseTypeFromPlanByExerciseTypeId(4); _exercisePlanRepository.removeExerciseTypeFromPlanByExerciseTypeId(4);
_exercisePlanRepository.saveExercisePlan(); _exercisePlanRepository.saveExercisePlan();
expect(_exercisePlanRepository.exercisePlanDetails[4].change, ExercisePlanDetailChange.delete); expect(_exercisePlanRepository.exercisePlanDetails[4].change, ModelChange.delete);
expect(Cache().getMyExercisePlanDetails()[4], isNull); expect(Cache().getMyExercisePlanDetails()[4], isNull);
}); });
}); });
} }

View File

@ -3,6 +3,7 @@ import 'dart:collection';
import 'package:aitrainer_app/model/cache.dart'; import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/model/exercise_plan.dart'; import 'package:aitrainer_app/model/exercise_plan.dart';
import 'package:aitrainer_app/model/exercise_plan_detail.dart'; import 'package:aitrainer_app/model/exercise_plan_detail.dart';
import 'package:aitrainer_app/model/model_change.dart';
import 'package:aitrainer_app/repository/exercise_plan_repository.dart'; import 'package:aitrainer_app/repository/exercise_plan_repository.dart';
import 'package:aitrainer_app/service/exercise_plan_service.dart'; import 'package:aitrainer_app/service/exercise_plan_service.dart';
import 'package:mockito/mockito.dart'; import 'package:mockito/mockito.dart';
@ -33,7 +34,7 @@ class MockExercisePlanApi extends Mock implements ExercisePlanApi {
Future<ExercisePlanDetail> updateExercisePlanDetail(ExercisePlanDetail detail, int planDetailId) async { Future<ExercisePlanDetail> updateExercisePlanDetail(ExercisePlanDetail detail, int planDetailId) async {
ExercisePlanDetail updated; ExercisePlanDetail updated;
memoryExercisePlanDetail.forEach((element) { memoryExercisePlanDetail.forEach((element) {
if ( element.exercisePlanDetailId == planDetailId ) { if (element.exercisePlanDetailId == planDetailId) {
element = detail; element = detail;
} }
}); });
@ -45,12 +46,12 @@ class MockExercisePlanApi extends Mock implements ExercisePlanApi {
int index = -1; int index = -1;
int countIndex = 0; int countIndex = 0;
memoryExercisePlanDetail.forEach((element) { memoryExercisePlanDetail.forEach((element) {
if ( element.exercisePlanId == exercisePlanId ) { if (element.exercisePlanId == exercisePlanId) {
index = countIndex; index = countIndex;
} }
countIndex++; countIndex++;
}); });
if ( index > -1) { if (index > -1) {
memoryExercisePlanDetail.removeAt(index); memoryExercisePlanDetail.removeAt(index);
} }
} }
@ -58,7 +59,7 @@ class MockExercisePlanApi extends Mock implements ExercisePlanApi {
Future<List<ExercisePlanDetail>> getExercisePlanDetail(int exercisePlanId) async { Future<List<ExercisePlanDetail>> getExercisePlanDetail(int exercisePlanId) async {
List<ExercisePlanDetail> foundList = List(); List<ExercisePlanDetail> foundList = List();
memoryExercisePlanDetail.forEach((element) { memoryExercisePlanDetail.forEach((element) {
if ( element.exercisePlanId == exercisePlanId ) { if (element.exercisePlanId == exercisePlanId) {
foundList.add(element); foundList.add(element);
} }
}); });
@ -68,7 +69,7 @@ class MockExercisePlanApi extends Mock implements ExercisePlanApi {
Future<ExercisePlan> getLastExercisePlan(int customerId) async { Future<ExercisePlan> getLastExercisePlan(int customerId) async {
ExercisePlan found; ExercisePlan found;
memoryExercisePlan.forEach((element) { memoryExercisePlan.forEach((element) {
if ( element.customerId == customerId ) { if (element.customerId == customerId) {
found = element; found = element;
} }
}); });
@ -77,11 +78,10 @@ class MockExercisePlanApi extends Mock implements ExercisePlanApi {
} }
class SimExercisePlanRepository with ExercisePlanRepository { class SimExercisePlanRepository with ExercisePlanRepository {
Future<void> getExercisePlanDetails() async { Future<void> getExercisePlanDetails() async {
if (exercisePlan == null) { if (exercisePlan == null) {
ExercisePlan exercisePlan = await this.getLastExercisePlan(); ExercisePlan exercisePlan = await this.getLastExercisePlan();
if ( exercisePlan == null ) { if (exercisePlan == null) {
exercisePlanDetails = LinkedHashMap<int, ExercisePlanDetail>(); exercisePlanDetails = LinkedHashMap<int, ExercisePlanDetail>();
return; return;
} }
@ -89,7 +89,7 @@ class SimExercisePlanRepository with ExercisePlanRepository {
List<ExercisePlanDetail> list = List(); List<ExercisePlanDetail> list = List();
LinkedHashMap<int, ExercisePlanDetail> listCache = Cache().getMyExercisePlanDetails(); LinkedHashMap<int, ExercisePlanDetail> listCache = Cache().getMyExercisePlanDetails();
if ( listCache.length > 0) { if (listCache.length > 0) {
exercisePlanDetails = listCache; exercisePlanDetails = listCache;
return; return;
} else { } else {
@ -109,11 +109,11 @@ class SimExercisePlanRepository with ExercisePlanRepository {
} }
Future<ExercisePlan> getLastExercisePlan() async { Future<ExercisePlan> getLastExercisePlan() async {
if ( customerId == 0) { if (customerId == 0) {
return null; return null;
} }
ExercisePlan myExercisePlan = Cache().getMyExercisePlan(); ExercisePlan myExercisePlan = Cache().getMyExercisePlan();
if ( myExercisePlan != null ) { if (myExercisePlan != null) {
newPlan = false; newPlan = false;
return myExercisePlan; return myExercisePlan;
} }
@ -125,13 +125,13 @@ class SimExercisePlanRepository with ExercisePlanRepository {
} }
Future<void> saveExercisePlan() async { Future<void> saveExercisePlan() async {
if ( exercisePlan == null ) { if (exercisePlan == null) {
if ( Cache().userLoggedIn == null ) { if (Cache().userLoggedIn == null) {
throw Exception("please log in"); throw Exception("please log in");
} }
String exercisePlanName; String exercisePlanName;
if ( this.customerId == Cache().userLoggedIn.customerId) { if (this.customerId == Cache().userLoggedIn.customerId) {
exercisePlanName = Cache().userLoggedIn.name + " private"; exercisePlanName = Cache().userLoggedIn.name + " private";
} else { } else {
exercisePlanName = Cache().getTrainee().name + " " + Cache().getTrainee().firstname + " private"; exercisePlanName = Cache().getTrainee().name + " " + Cache().getTrainee().firstname + " private";
@ -139,13 +139,11 @@ class SimExercisePlanRepository with ExercisePlanRepository {
exercisePlan = ExercisePlan(exercisePlanName, this.customerId); exercisePlan = ExercisePlan(exercisePlanName, this.customerId);
} }
if ( newPlan ) { if (newPlan) {
exercisePlan.dateAdd = DateTime.now(); exercisePlan.dateAdd = DateTime.now();
exercisePlan.private = true; exercisePlan.private = true;
ExercisePlan savedExercisePlan ExercisePlan savedExercisePlan = await MockExercisePlanApi().saveExercisePlan(exercisePlan);
= await MockExercisePlanApi().saveExercisePlan(exercisePlan);
LinkedHashMap<int, ExercisePlanDetail> savedExercisePlanDetails = LinkedHashMap(); LinkedHashMap<int, ExercisePlanDetail> savedExercisePlanDetails = LinkedHashMap();
exercisePlanDetails.forEach((exerciseTypeId, exercisePlanDetail) async { exercisePlanDetails.forEach((exerciseTypeId, exercisePlanDetail) async {
@ -158,21 +156,17 @@ class SimExercisePlanRepository with ExercisePlanRepository {
exercisePlan = savedExercisePlan; exercisePlan = savedExercisePlan;
} else { } else {
await MockExercisePlanApi().updateExercisePlan(exercisePlan, exercisePlan.exercisePlanId); await MockExercisePlanApi().updateExercisePlan(exercisePlan, exercisePlan.exercisePlanId);
exercisePlanDetails.forEach((exerciseTypeId, exercisePlanDetail) async { exercisePlanDetails.forEach((exerciseTypeId, exercisePlanDetail) async {
if ( exercisePlanDetail.change == ExercisePlanDetailChange.delete ) { if (exercisePlanDetail.change == ModelChange.delete) {
await MockExercisePlanApi() await MockExercisePlanApi().deleteExercisePlanDetail(exercisePlanDetail.exercisePlanDetailId);
.deleteExercisePlanDetail(exercisePlanDetail.exercisePlanDetailId);
Cache().deleteMyExercisePlanDetail(exercisePlanDetail); Cache().deleteMyExercisePlanDetail(exercisePlanDetail);
} else if ( exercisePlanDetail.change == ExercisePlanDetailChange.update ) { } else if (exercisePlanDetail.change == ModelChange.update) {
await MockExercisePlanApi() await MockExercisePlanApi().updateExercisePlanDetail(exercisePlanDetail, exercisePlanDetail.exercisePlanDetailId);
.updateExercisePlanDetail(exercisePlanDetail, exercisePlanDetail.exercisePlanDetailId);
Cache().updateMyExercisePlanDetail(exercisePlanDetail); Cache().updateMyExercisePlanDetail(exercisePlanDetail);
} else if ( exercisePlanDetail.change == ExercisePlanDetailChange.add ) { } else if (exercisePlanDetail.change == ModelChange.add) {
await MockExercisePlanApi() await MockExercisePlanApi().saveExercisePlanDetail(exercisePlanDetail);
.saveExercisePlanDetail(exercisePlanDetail);
Cache().addToMyExercisePlanDetails(exercisePlanDetail); Cache().addToMyExercisePlanDetails(exercisePlanDetail);
} }
}); });