wt1.0 bug fixing, push notification

This commit is contained in:
Bossanyi Tibor
2020-07-12 14:17:59 +02:00
parent f0f0136d65
commit 4e38d3da22
67 changed files with 1472 additions and 213 deletions
+27
View File
@@ -0,0 +1,27 @@
import 'package:firebase_messaging/firebase_messaging.dart';
class PushNotificationsManager {
PushNotificationsManager._();
factory PushNotificationsManager() => _instance;
static final PushNotificationsManager _instance = PushNotificationsManager._();
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
bool _initialized = false;
Future<void> init() async {
if (!_initialized) {
// For iOS request permission first.
_firebaseMessaging.requestNotificationPermissions();
_firebaseMessaging.configure();
// For testing purposes print the Firebase Messaging token
String token = await _firebaseMessaging.getToken();
print("FirebaseMessaging token: $token");
_initialized = true;
}
}
}
+7 -4
View File
@@ -1,4 +1,5 @@
import 'dart:convert';
import 'package:aitrainer_app/util/common.dart';
import 'package:flutter/cupertino.dart';
import 'package:http/http.dart' as http;
import 'package:aitrainer_app/model/auth.dart';
@@ -39,16 +40,18 @@ class APIClient extends ChangeNotifier {
);
authToken = responseJson['token'];
}
final response = await http.post(url,
headers: {
'Content-Type': 'application/json',
'Content-Type': 'application/json; charset=UTF-8',
'Authorization' : "Bearer " + authToken
},
body: body
body: body,
);
print(" ------------ response: " + response.body.toString());
String decodedResponse = Common.utf8convert(response.body);
print(" ------------ response: " + decodedResponse);
notifyListeners();
return response.body;
return decodedResponse;
}
static dynamic authenticateUser(String email, String password) async {
+15 -4
View File
@@ -37,8 +37,13 @@ class CustomerApi {
final String responseBody = await _client.post(
"registration",
body);
Customer customer = Customer.fromJson(jsonDecode(responseBody));
Auth().afterRegistration(customer);
Customer customer;
try {
customer = Customer.fromJson(jsonDecode(responseBody));
Auth().afterRegistration(customer);
} on FormatException catch(exception) {
throw new Exception(responseBody);
}
}
@@ -48,10 +53,16 @@ class CustomerApi {
final String responseBody = await _client.post(
"login",
body);
Customer customer = Customer.fromJson(jsonDecode(responseBody));
Auth().afterRegistration(customer);
Customer customer;
try {
customer = Customer.fromJson(jsonDecode(responseBody));
Auth().afterRegistration(customer);
} on FormatException catch(exception) {
throw new Exception(responseBody);
}
}
Future<void> getCustomer(int customerId) async {
String body = "";
print(" ===== get the customer by id: " + customerId.toString() );
+7
View File
@@ -1,3 +1,5 @@
import 'dart:convert';
import 'package:aitrainer_app/localization/app_language.dart';
import 'package:aitrainer_app/model/auth.dart';
import 'package:aitrainer_app/model/exercise_type.dart';
@@ -40,4 +42,9 @@ class Common {
return dateName;
}
static String utf8convert(String text) {
List<int> bytes = text.toString().codeUnits;
return utf8.decode(bytes);
}
}
+3
View File
@@ -7,6 +7,8 @@ import 'package:flutter/services.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:aitrainer_app/model/auth.dart';
import '../push_notifications.dart';
class Session {
Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
@@ -22,6 +24,7 @@ class Session {
_fetchToken(_sharedPreferences, callback);
initDeviceLocale();
appLanguage.fetchLocale();
PushNotificationsManager().init();
}
}
+44 -24
View File
@@ -1,8 +1,9 @@
import 'package:aitrainer_app/localization/app_language.dart';
import 'package:aitrainer_app/localization/app_localization.dart';
import 'package:aitrainer_app/model/auth.dart';
import 'package:aitrainer_app/util/common.dart';
import 'package:aitrainer_app/viewmodel/customer_changing_view_model.dart';
import 'package:aitrainer_app/viewmodel/customer_view_model.dart';
import 'package:aitrainer_app/viewmodel/exercise_changing_view_model.dart';
import 'package:aitrainer_app/viewmodel/exercise_view_model.dart';
import 'package:shared_preferences/shared_preferences.dart';
@@ -20,6 +21,10 @@ class AccountPage extends StatefulWidget{
_state = new _AccountPagePageState();
return _state;
}
State getState() {
return _state;
}
}
class _AccountPagePageState extends State<AccountPage> {
@@ -27,23 +32,36 @@ class _AccountPagePageState extends State<AccountPage> {
final AppLanguage appLanguage = AppLanguage();
final Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
final BottomNavigator bottomNav = BottomNavigator();
bool _loggedIn = Auth().userLoggedIn != null && Auth().userLoggedIn.email.length > 0;
Future<List<ExerciseViewModel>> _exercises;
ExerciseChangingViewModel model;
ExerciseChangingViewModel exerciseChangingViewModel;
@override
void initState() {
exerciseChangingViewModel = Provider.of<ExerciseChangingViewModel>(context, listen: false);
super.initState();
model = Provider.of<ExerciseChangingViewModel>(context, listen: false);
if ( Auth().userLoggedIn != null ) {
_exercises = model.getExercisesByCustomer(Auth().userLoggedIn.customerId);
}
}
@override
Widget build(BuildContext context) {
return Consumer<CustomerChangingViewModel>(
builder: (context, model, child ) {
if ( model.customer == null ) {
CustomerViewModel customerViewModel = CustomerViewModel();
model.customer = customerViewModel;
if ( model.customer.getCustomer() == null ) {
model.customer.setCustomer(Auth().userLoggedIn);
}
}
if ( Auth().userLoggedIn != null ) {
_exercises =
exerciseChangingViewModel.getExercisesByCustomer(
Auth().userLoggedIn.customerId);
}
return Scaffold(
appBar: AppBar(
title: Text(AppLocalizations.of(context).translate('Account')),
@@ -75,18 +93,19 @@ class _AccountPagePageState extends State<AccountPage> {
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(_loggedIn ? Auth().userLoggedIn.email + " " +
Auth().userLoggedIn.name + " " +
Text(Auth().userLoggedIn != null ?
Auth().userLoggedIn.name + " " +
Auth().userLoggedIn.firstname : "",
style: TextStyle(color: Colors.blue)),
Icon(Icons.arrow_forward_ios),
]),
textColor: Colors.grey,
color: Colors.white,
onPressed: () {
if (_loggedIn) {
Navigator.of(context).pushNamed('customerModifyPage');
print("Profile");
onPressed: () => {
if (model.customer.getCustomer() != null) {
Navigator.of(context).pushNamed(
'customerModifyPage'),
print("Profile"),
}
},
),
@@ -100,22 +119,24 @@ class _AccountPagePageState extends State<AccountPage> {
subtitle: Text(AppLocalizations.of(context).translate(
"Selected Language")),
),
loginOut(),
exercises( model ),
loginOut( model ),
exercises(exerciseChangingViewModel),
]
)
),
bottomNavigationBar: bottomNav.buildBottomNavigator(context, widget._state)
bottomNavigationBar: bottomNav.buildBottomNavigator(
context, widget._state)
);
});
}
ListTile loginOut() {
ListTile loginOut( CustomerChangingViewModel model ) {
ListTile element = ListTile();
String text = "Logout";
Color buttonColor = Colors.orange;
if ( ! _loggedIn ) {
if ( model.customer.getCustomer() == null ) {
text = "Login";
buttonColor = Colors.blue;
}
@@ -135,19 +156,18 @@ class _AccountPagePageState extends State<AccountPage> {
]),
textColor: buttonColor,
color: Colors.white,
onPressed: () {
onPressed: () => {
setState(() {
if ( ! _loggedIn) {
if ( model.customer.getCustomer() == null ) {
print("Login");
Navigator.of(context).pushNamed("login");
Navigator.of(context).pushNamed("login", arguments: widget._state);
} else {
print("Logout");
_loggedIn = false;
Auth().logout();
model.customer.setCustomer(null);
}
});
})
},
),
);
+139 -30
View File
@@ -12,16 +12,19 @@ class CustomerBodyTypePage extends StatefulWidget{
}
}
class GenderItem {
GenderItem(this.dbValue,this.name);
final String dbValue;
String name;
class BodyTypeItem {
static String endomorph = "endomorph";
static String ectomorph = "ectomorph";
static String mesomorph = "mesomorph";
}
class _CustomerBodyTypePageState extends State<CustomerBodyTypePage> {
String selected;
@override
Widget build(BuildContext context) {
final CustomerChangingViewModel changingViewModel = ModalRoute.of(context).settings.arguments;
final double cWidth = MediaQuery.of(context).size.width*0.75;
return Scaffold(
appBar: AppBar(
@@ -46,36 +49,142 @@ class _CustomerBodyTypePageState extends State<CustomerBodyTypePage> {
alignment: Alignment.center,
),
),
child: Center(
child: Column(
children: [
Divider(),
InkWell(
child: Text("Your Body Type",
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Divider(),
Wrap(
//runAlignment: WrapAlignment.center,
alignment: WrapAlignment.center,
children: [
Text(
AppLocalizations.of(context).translate("Your Body Type"),
textAlign: TextAlign.center,
style: TextStyle(color: Colors.orange,
fontSize: 50, fontFamily: 'Arial',
fontWeight: FontWeight.w900 ),),
highlightColor: Colors.white,
),
RaisedButton(
color: Colors.orange,
textColor: Colors.white,
child: InkWell(
child: Text(AppLocalizations.of(context).translate("Next"))),
onPressed: () => {
//changingViewModel.saveCustomer(),
Navigator.of(context).pop(),
Navigator.of(context).pushNamed("customerWelcomePage", arguments: changingViewModel)
},
)
],
fontSize: 42, fontFamily: 'Arial',
fontWeight: FontWeight.w900 ),)
]
),
)
Divider(),
FlatButton(
child: Container(
width: cWidth,
child: Column(
children: [
Text(AppLocalizations.of(context).translate("Endomorph"),
textWidthBasis: TextWidthBasis.longestLine,
style: TextStyle(color: Colors.blue,
fontSize: 32, fontFamily: 'Arial',
fontWeight: FontWeight.w900 )),
],
)
),
padding: EdgeInsets.all(10.0),
shape: getShape(changingViewModel, BodyTypeItem.endomorph ),
onPressed:() =>
{
setState((){
selected = BodyTypeItem.endomorph;
changingViewModel.customer.setBodyType(selected);
print(selected);
}),
}
),
Divider(),
FlatButton(
child: Container(
width: cWidth,
child: Column(
children: [
InkWell(
child: Text(AppLocalizations.of(context).translate("Ectomorph"),
style: TextStyle(color: Colors.blue,
fontSize: 32, fontFamily: 'Arial',
fontWeight: FontWeight.w900 ),),
highlightColor: Colors.white,
),
],
),
),
padding: EdgeInsets.all(10.0),
shape: getShape(changingViewModel, BodyTypeItem.ectomorph ),
onPressed:() =>
{
setState((){
selected = BodyTypeItem.ectomorph;
changingViewModel.customer.setBodyType(selected);
print(selected);
}),
}
),
Divider(),
FlatButton(
child: Container(
width: cWidth,
child: Column(
children: [
InkWell(
child: Text(AppLocalizations.of(context).translate("Mesomorph"),
style: TextStyle(color: Colors.blue,
fontSize: 32, fontFamily: 'Arial',
fontWeight: FontWeight.w900 ),),
highlightColor: Colors.white,
),
],
),
),
padding: EdgeInsets.all(10.0),
shape: getShape(changingViewModel, BodyTypeItem.mesomorph ),
onPressed:() =>
{
setState((){
selected = BodyTypeItem.mesomorph;
changingViewModel.customer.setBodyType(selected);
print(selected);
}),
}
),
Divider(),
RaisedButton(
color: Colors.orange,
textColor: Colors.white,
child: InkWell(
child: Text(AppLocalizations.of(context).translate("Next"))),
onPressed: () => {
changingViewModel.saveCustomer(),
Navigator.of(context).pop(),
Navigator.of(context).pushNamed("customerWelcomePage", arguments: changingViewModel)
},
)
],
),
),
);
}
dynamic getShape( CustomerChangingViewModel changingViewModel, String fitnessLevel ) {
String selected = changingViewModel.customer.bodyType;
dynamic returnCode = ( selected == fitnessLevel ) ?
RoundedRectangleBorder(
side: BorderSide(width: 4, color: Colors.orange),
)
:
RoundedRectangleBorder(
side: BorderSide(width: 1, color: Colors.blue),
);
//return
return returnCode;
}
}
+203 -32
View File
@@ -1,6 +1,8 @@
import 'package:aitrainer_app/localization/app_localization.dart';
import 'package:aitrainer_app/viewmodel/customer_changing_view_model.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
// ignore: must_be_immutable
class CustomerFitnessPage extends StatefulWidget{
@@ -12,17 +14,24 @@ class CustomerFitnessPage extends StatefulWidget{
}
}
class GenderItem {
GenderItem(this.dbValue,this.name);
final String dbValue;
String name;
class FitnessItem {
static String beginner = "beginner";
static String intermediate = "intermediate";
static String advanced = "advanced";
static String professional = "professional";
}
//TODO
// dropbox for professional sport
class _CustomerFitnessPageState extends State<CustomerFitnessPage> {
String selected;
@override
Widget build(BuildContext context) {
final double cWidth = MediaQuery.of(context).size.width*0.75;
final CustomerChangingViewModel changingViewModel = ModalRoute.of(context).settings.arguments;
selected = changingViewModel.customer.fitnessLevel;
return Scaffold(
appBar: AppBar(
title: Row(
@@ -38,43 +47,205 @@ class _CustomerFitnessPageState extends State<CustomerFitnessPage> {
),
backgroundColor: Colors.transparent,
),
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('asset/image/WT_light_background.png'),
fit: BoxFit.cover,
alignment: Alignment.center,
body: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Container(
padding: EdgeInsets.only(bottom: 200),
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('asset/image/WT_light_background.png'),
fit: BoxFit.cover,
alignment: Alignment.center,
),
),
),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Divider(),
InkWell(
child: Text("Your Fitness State",
style: TextStyle(color: Colors.orange,
fontSize: 50, fontFamily: 'Arial',
fontWeight: FontWeight.w900 ),),
highlightColor: Colors.white,
Wrap(
//runAlignment: WrapAlignment.center,
alignment: WrapAlignment.center,
children: [
Text(
AppLocalizations.of(context).translate("Your Fitness State"),
textAlign: TextAlign.center,
style: TextStyle(color: Colors.orange,
fontSize: 42, fontFamily: 'Arial',
fontWeight: FontWeight.w900 ),)
]
),
RaisedButton(
color: Colors.orange,
textColor: Colors.white,
child: InkWell(
child: Text(AppLocalizations.of(context).translate("Next"))),
onPressed: () => {
//changingViewModel.saveCustomer(),
Navigator.of(context).pop(),
Navigator.of(context).pushNamed("customerBodyTypePage", arguments: changingViewModel)
},
)
],
Divider(),
FlatButton(
child: Container(
width: cWidth,
child: Column(
children: [
Text(AppLocalizations.of(context).translate("Beginner"),
textWidthBasis: TextWidthBasis.longestLine,
style: TextStyle(color: Colors.blue,
fontSize: 32, fontFamily: 'Arial',
fontWeight: FontWeight.w900 )),
Text(AppLocalizations.of(context).translate("I am beginner"),
style: TextStyle(color: Colors.black,
fontSize: 20, fontFamily: 'Arial',
fontWeight: FontWeight.w100 ),),
],
)
),
padding: EdgeInsets.all(10.0),
shape: getShape(changingViewModel, FitnessItem.beginner ),
onPressed:() =>
{
setState((){
selected = FitnessItem.beginner;
changingViewModel.customer.setFitnessLevel(selected);
print(selected);
}),
}
),
Divider(),
FlatButton(
child: Container(
width: cWidth,
child: Column(
children: [
InkWell(
child: Text(AppLocalizations.of(context).translate("Intermediate"),
style: TextStyle(color: Colors.blue,
fontSize: 32, fontFamily: 'Arial',
fontWeight: FontWeight.w900 ),),
highlightColor: Colors.white,
),
InkWell(
child: Text(AppLocalizations.of(context).translate("I am intermediate"),
style: TextStyle(color: Colors.black,
fontSize: 20, fontFamily: 'Arial',
fontWeight: FontWeight.w100 ),),
highlightColor: Colors.white,
),
],
),
),
padding: EdgeInsets.all(10.0),
shape: getShape(changingViewModel, FitnessItem.intermediate ),
onPressed:() =>
{
setState((){
selected = FitnessItem.intermediate;
changingViewModel.customer.setFitnessLevel(selected);
print(selected);
}),
}
),
Divider(),
FlatButton(
child: Container(
width: cWidth,
child: Column(
children: [
InkWell(
child: Text(AppLocalizations.of(context).translate("Advanced"),
style: TextStyle(color: Colors.blue,
fontSize: 32, fontFamily: 'Arial',
fontWeight: FontWeight.w900 ),),
highlightColor: Colors.white,
),
InkWell(
child: Text(AppLocalizations.of(context).translate("I am advanced"),
style: TextStyle(color: Colors.black,
fontSize: 20, fontFamily: 'Arial',
fontWeight: FontWeight.w100 ),),
highlightColor: Colors.white,
),
],
),
),
padding: EdgeInsets.all(10.0),
shape: getShape(changingViewModel, FitnessItem.advanced ),
onPressed:() =>
{
setState((){
selected = FitnessItem.advanced;
changingViewModel.customer.setFitnessLevel(selected);
print(selected);
}),
}
),
Divider(),
FlatButton(
child: Container(
width: cWidth,
child: Column(
children: [
InkWell(
child: Text(AppLocalizations.of(context).translate("Professional"),
style: TextStyle(color: Colors.blue,
fontSize: 32, fontFamily: 'Arial',
fontWeight: FontWeight.w900 ),),
highlightColor: Colors.white,
),
InkWell(
child: Text(AppLocalizations.of(context).translate("I am professional"),
style: TextStyle(color: Colors.black,
fontSize: 20, fontFamily: 'Arial',
fontWeight: FontWeight.w100 ),),
highlightColor: Colors.white,
),
],
),
),
padding: EdgeInsets.all(10.0),
shape: getShape(changingViewModel, FitnessItem.professional ),
onPressed:() =>
{
setState((){
selected = FitnessItem.professional;
changingViewModel.customer.setFitnessLevel(selected);
print(selected);
}),
}
),
Divider(),
RaisedButton(
color: Colors.orange,
textColor: Colors.white,
child: InkWell(
child: Text(AppLocalizations.of(context).translate("Next"))),
onPressed: () => {
changingViewModel.saveCustomer(),
Navigator.of(context).pop(),
Navigator.of(context).pushNamed("customerBodyTypePage", arguments: changingViewModel)
},
)
],
),
)
),
)
);
}
dynamic getShape( CustomerChangingViewModel changingViewModel, String fitnessLevel ) {
String selected = changingViewModel.customer.fitnessLevel;
dynamic returnCode = ( selected == fitnessLevel ) ?
RoundedRectangleBorder(
side: BorderSide(width: 4, color: Colors.orange),
)
:
RoundedRectangleBorder(
side: BorderSide(width: 1, color: Colors.blue),
);
//return
return returnCode;
}
}
+99 -67
View File
@@ -1,5 +1,6 @@
import 'package:aitrainer_app/localization/app_localization.dart';
import 'package:aitrainer_app/viewmodel/customer_changing_view_model.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
// ignore: must_be_immutable
@@ -12,17 +13,23 @@ class CustomerGoalPage extends StatefulWidget{
}
}
class GenderItem {
GenderItem(this.dbValue,this.name);
final String dbValue;
String name;
class GoalsItem{
static String muscle = "gain_muscle";
static String weight = "weight_loss";
}
class _CustomerGoalPageState extends State<CustomerGoalPage> {
String selected;
initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
final double cWidth = MediaQuery.of(context).size.width*0.75;
final CustomerChangingViewModel changingViewModel = ModalRoute.of(context).settings.arguments;
selected = changingViewModel.customer.goal;
return Scaffold(
appBar: AppBar(
title: Row(
@@ -46,79 +53,104 @@ class _CustomerGoalPageState extends State<CustomerGoalPage> {
alignment: Alignment.center,
),
),
child: Center(
child: Column(
children: [
Divider(),
InkWell(
child: Text("Set Your Goals",
style: TextStyle(color: Colors.orange,
fontSize: 50, fontFamily: 'Arial',
fontWeight: FontWeight.w900 ),),
highlightColor: Colors.white,
),
child: SingleChildScrollView(
child: Center(
child: Column(
children: [
Divider(),
InkWell(
child: Text(AppLocalizations.of(context).translate("Set Your Goals"),
style: TextStyle(color: Colors.orange,
fontSize: 50, fontFamily: 'Arial',
fontWeight: FontWeight.w900 ),),
highlightColor: Colors.white,
),
Stack(
alignment: Alignment.bottomLeft,
overflow: Overflow.visible,
children: [
FlatButton(
child: Image.asset("asset/image/WT_gain_muscle.png", height: 250,),
padding: EdgeInsets.all(0.0),
onPressed:() =>
{
print("gain muscle"),
changingViewModel.customer.setGoal("gain_muscle"),
}
),
InkWell(
child: Text("Gain Muscle",
style: TextStyle(color: Colors.white,
fontSize: 36, fontFamily: 'Arial',
fontWeight: FontWeight.w900 ),),
highlightColor: Colors.white,
)
]
),
Stack(
alignment: Alignment.bottomLeft,
overflow: Overflow.visible,
children: [
FlatButton(
child: Image.asset("asset/image/WT_weight_loss.png", height: 220,),
Stack(
alignment: Alignment.bottomLeft,
overflow: Overflow.visible,
children: [
FlatButton(
child: Image.asset("asset/image/WT_gain_muscle.png", height: 180,),
padding: EdgeInsets.all(0.0),
shape: getShape(changingViewModel, GoalsItem.muscle ),
onPressed:() =>
{
print("weight_loss"),
changingViewModel.customer.setGoal("weight_loss"),
print("gain muscle"),
setState((){
selected = GoalsItem.muscle;
changingViewModel.customer.setGoal(GoalsItem.muscle);
}),
}
),
InkWell(
child: Text("Loose Weight",
style: TextStyle(color: Colors.white,
fontSize: 36, fontFamily: 'Arial',
fontWeight: FontWeight.w900 ),),
highlightColor: Colors.white,
)
InkWell(
child: Text(AppLocalizations.of(context).translate("Gain Muscle"),
style: TextStyle(color: Colors.white,
fontSize: 32, fontFamily: 'Arial',
fontWeight: FontWeight.w900 ),),
highlightColor: Colors.white,
)
]
),
RaisedButton(
),
Divider(),
Stack(
alignment: Alignment.bottomLeft,
overflow: Overflow.visible,
children: [
FlatButton(
child: Image.asset("asset/image/WT_weight_loss.png", height: 180,),
padding: EdgeInsets.all(0.0),
shape: getShape(changingViewModel, GoalsItem.weight ),
onPressed:() =>
{
print("weight_loss"),
setState((){
selected = GoalsItem.weight;
changingViewModel.customer.setGoal(GoalsItem.weight);
}),
color: Colors.orange,
textColor: Colors.white,
child: InkWell(
child: Text(AppLocalizations.of(context).translate("Next"))),
onPressed: () => {
//changingViewModel.saveCustomer(),
Navigator.of(context).pop(),
Navigator.of(context).pushNamed("customerFitnessPage", arguments: changingViewModel)
},
)
],
),
}
),
InkWell(
child: Text(AppLocalizations.of(context).translate("Loose Weight"),
style: TextStyle(color: Colors.white,
fontSize: 32, fontFamily: 'Arial',
fontWeight: FontWeight.w900 ),),
highlightColor: Colors.white,
)
]
),
Divider(),
RaisedButton(
color: Colors.orange,
textColor: Colors.white,
child: InkWell(
child: Text(AppLocalizations.of(context).translate("Next"))),
onPressed: () => {
changingViewModel.saveCustomer(),
Navigator.of(context).pop(),
Navigator.of(context).pushNamed("customerFitnessPage", arguments: changingViewModel)
},
)
],
),
)
)
),
);
}
dynamic getShape( CustomerChangingViewModel changingViewModel, String goal ) {
String selectedGoal = changingViewModel.customer.goal;
dynamic returnCode = ( selectedGoal == goal ) ?
RoundedRectangleBorder(
side: BorderSide(width: 4, color: Colors.red),
)
: null;
//return
return returnCode;
}
}
+23 -22
View File
@@ -1,11 +1,11 @@
import 'package:aitrainer_app/localization/app_localization.dart';
import 'package:aitrainer_app/model/auth.dart';
import 'package:aitrainer_app/viewmodel/customer_changing_view_model.dart';
import 'package:aitrainer_app/viewmodel/customer_view_model.dart';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
// ignore: must_be_immutable
class CustomerModifyPage extends StatefulWidget{
_CustomerModifyPageState _state;
@@ -39,11 +39,12 @@ class _CustomerModifyPageState extends State<CustomerModifyPage> {
@override
Widget build(BuildContext context) {
final CustomerViewModel model = CustomerViewModel();
model.customer = Auth().userLoggedIn;
final CustomerChangingViewModel customerChangeModel =
CustomerChangingViewModel(model);
customerChangeModel.customer.customer.sex = selectedGender.dbValue;
//final CustomerViewModel model = CustomerViewModel();
//model.customer = Auth().userLoggedIn;
//final CustomerChangingViewModel customerChangeModel =
// CustomerChangingViewModel(model);
CustomerChangingViewModel customerChangingViewModel = Provider.of<CustomerChangingViewModel>(context, listen: false);
customerChangingViewModel.customer.customer.sex = selectedGender.dbValue;
// we cannot initialize the translations in the initState
genders.forEach((GenderItem element) {
@@ -103,8 +104,8 @@ class _CustomerModifyPageState extends State<CustomerModifyPage> {
filled: true,
labelText: AppLocalizations.of(context).translate('Email'),
),
initialValue: customerChangeModel.customer.customer.email,
onFieldSubmitted: (input) => customerChangeModel.customer.setEmail(input)
initialValue: customerChangingViewModel.customer.customer.email,
onFieldSubmitted: (input) => customerChangingViewModel.customer.setEmail(input)
)
)
],
@@ -123,8 +124,8 @@ class _CustomerModifyPageState extends State<CustomerModifyPage> {
filled: true,
labelText: AppLocalizations.of(context).translate('Password (Leave empty if you don\'t want to change)' ),
),
initialValue: customerChangeModel.customer.customer.password,
onFieldSubmitted: (input) => customerChangeModel.customer.setPassword(input)
initialValue: customerChangingViewModel.customer.customer.password,
onFieldSubmitted: (input) => customerChangingViewModel.customer.setPassword(input)
)
)
],
@@ -142,8 +143,8 @@ class _CustomerModifyPageState extends State<CustomerModifyPage> {
filled: true,
labelText: AppLocalizations.of(context).translate('Name'),
),
initialValue: customerChangeModel.customer.customer.name,
onFieldSubmitted: (input) => customerChangeModel.customer.setName(input)
initialValue: customerChangingViewModel.customer.customer.name,
onFieldSubmitted: (input) => customerChangingViewModel.customer.setName(input)
)
)
],
@@ -163,8 +164,8 @@ class _CustomerModifyPageState extends State<CustomerModifyPage> {
labelText: AppLocalizations.of(context).translate('First Name'),
),
keyboardType: TextInputType.emailAddress,
initialValue: customerChangeModel.customer.customer.firstname,
onFieldSubmitted: (input) => customerChangeModel.customer.setFirstName(input)
initialValue: customerChangingViewModel.customer.customer.firstname,
onFieldSubmitted: (input) => customerChangingViewModel.customer.setFirstName(input)
)
)
],
@@ -186,8 +187,8 @@ class _CustomerModifyPageState extends State<CustomerModifyPage> {
inputFormatters: <TextInputFormatter>[
WhitelistingTextInputFormatter.digitsOnly
],
initialValue: customerChangeModel.customer.customer.birthYear.toString(),
onFieldSubmitted: (input) => customerChangeModel.customer.setBirthYear(int.parse(input))
initialValue: customerChangingViewModel.customer.customer.birthYear.toString(),
onFieldSubmitted: (input) => customerChangingViewModel.customer.setBirthYear(int.parse(input))
)
)
],
@@ -208,9 +209,9 @@ class _CustomerModifyPageState extends State<CustomerModifyPage> {
inputFormatters: <TextInputFormatter>[
WhitelistingTextInputFormatter.digitsOnly
],
initialValue: customerChangeModel.customer.customer.weight.toString(),
initialValue: customerChangingViewModel.customer.customer.weight.toString(),
keyboardType: TextInputType.number,
onFieldSubmitted: (input) => customerChangeModel.customer.setWeight(int.parse(input)),
onFieldSubmitted: (input) => customerChangingViewModel.customer.setWeight(int.parse(input)),
)
)
],
@@ -236,7 +237,7 @@ class _CustomerModifyPageState extends State<CustomerModifyPage> {
onChanged:(GenderItem gender) => {
setState(() {
selectedGender = gender;
customerChangeModel.customer.setSex(gender.dbValue);
customerChangingViewModel.customer.setSex(gender.dbValue);
print ("Gender " + gender.name);
})
@@ -259,8 +260,8 @@ class _CustomerModifyPageState extends State<CustomerModifyPage> {
child: InkWell(
child: Text(AppLocalizations.of(context).translate("Next"))),
onPressed: () => {
customerChangeModel.saveCustomer(),
Navigator.of(context).pushNamed("customerGoalPage", arguments: customerChangeModel)
customerChangingViewModel.saveCustomer(),
Navigator.of(context).pushNamed("customerGoalPage", arguments: customerChangingViewModel)
},
)
)
+1 -9
View File
@@ -1,5 +1,4 @@
import 'package:aitrainer_app/localization/app_localization.dart';
import 'package:aitrainer_app/viewmodel/customer_changing_view_model.dart';
import 'package:flutter/material.dart';
// ignore: must_be_immutable
@@ -12,16 +11,9 @@ class CustomerWelcomePage extends StatefulWidget{
}
}
class GenderItem {
GenderItem(this.dbValue,this.name);
final String dbValue;
String name;
}
class _CustomerWelcomePageState extends State<CustomerWelcomePage> {
@override
Widget build(BuildContext context) {
final CustomerChangingViewModel changingViewModel = ModalRoute.of(context).settings.arguments;
return Scaffold(
appBar: AppBar(
@@ -62,7 +54,7 @@ class _CustomerWelcomePageState extends State<CustomerWelcomePage> {
onPressed: () => {
Navigator.of(context).pop(),
Navigator.of(context).pushNamed("home", arguments: changingViewModel)
Navigator.of(context).pushNamed("home")
},
)
],
+30 -7
View File
@@ -1,6 +1,7 @@
import 'package:aitrainer_app/localization/app_localization.dart';
import 'package:aitrainer_app/model/auth.dart';
import 'package:aitrainer_app/viewmodel/exercise_changing_view_model.dart';
import 'package:aitrainer_app/view/account.dart';
import 'package:aitrainer_app/viewmodel/customer_changing_view_model.dart';
import 'package:aitrainer_app/viewmodel/user_changing_view_model.dart';
import 'package:aitrainer_app/viewmodel/user_view_model.dart';
import 'package:flutter/material.dart';
@@ -12,7 +13,8 @@ class LoginPage extends StatefulWidget{
_LoginPageState createState() => _LoginPageState();
}
class _LoginPageState extends State {
class _LoginPageState extends State<LoginPage> {
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
final UserViewModel user = UserViewModel();
final bool _obscureText = true;
final _formKey = GlobalKey<FormState>();
@@ -20,10 +22,13 @@ class _LoginPageState extends State {
@override
Widget build(BuildContext context) {
UserChangingViewModel model = UserChangingViewModel(user);
ExerciseChangingViewModel exerciseModel = Provider.of<ExerciseChangingViewModel>(context, listen: false);
CustomerChangingViewModel customerChangingViewModel = Provider.of<CustomerChangingViewModel>(context, listen: false);
user.createNew();
Future<dynamic> customer;
final State<AccountPage> stateAccount = ModalRoute.of(context).settings.arguments;
return Scaffold(
key: _scaffoldKey,
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
@@ -100,10 +105,17 @@ class _LoginPageState extends State {
{
if (_formKey.currentState.validate()) {
model = UserChangingViewModel(user),
model.getUser(),
exerciseModel.setCustomer(
Auth().userLoggedIn),
Navigator.pop(context),
model.getUser().then((_) =>
{
if ( stateAccount != null ) {
stateAccount.setState(() {
print("update account");
}),
},
customerChangingViewModel.customer.setCustomer(Auth().userLoggedIn),
Navigator.pop(context),
}).catchError(( error, stackTrace )=> showInSnackBar(error)
),
}
}),
]),
@@ -136,4 +148,15 @@ class _LoginPageState extends State {
)
);
}
void showInSnackBar(String error) {
_scaffoldKey.currentState.showSnackBar(
SnackBar(
backgroundColor: Colors.orange,
content: Text(
AppLocalizations.of(context).translate("Customer does not exist or the password is wrong") + " " + error,
style: TextStyle(color: Colors.white))
)
);
}
}
+7 -1
View File
@@ -111,7 +111,13 @@ class _MenuPageState extends State<MenuPage> {
model.setCustomer(Auth().userLoggedIn),
if ( Auth().userLoggedIn == null ) {
Scaffold.of(context)
. showSnackBar(SnackBar(content: Text('Please log in')))
. showSnackBar(
SnackBar(
backgroundColor: Colors.orange,
content: Text(
AppLocalizations.of(context).translate('Please log in'),
style: TextStyle(color: Colors.white))
))
} else {
Navigator.of(context).pushNamed('exerciseNewPage'),
}
+25 -5
View File
@@ -1,16 +1,19 @@
import 'package:aitrainer_app/localization/app_localization.dart';
import 'package:aitrainer_app/model/auth.dart';
import 'package:aitrainer_app/viewmodel/customer_changing_view_model.dart';
import 'package:aitrainer_app/viewmodel/user_changing_view_model.dart';
import 'package:aitrainer_app/viewmodel/user_view_model.dart';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:aitrainer_app/widgets/nav_drawer.dart';
import 'package:provider/provider.dart';
class RegistrationPage extends StatefulWidget{
_RegistrationPageState createState() => _RegistrationPageState();
}
class _RegistrationPageState extends State {
class _RegistrationPageState extends State<RegistrationPage> {
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
final UserViewModel user = UserViewModel();
bool _obscureText = true;
@@ -19,10 +22,11 @@ class _RegistrationPageState extends State {
@override
Widget build(BuildContext context) {
UserChangingViewModel model = UserChangingViewModel(user);
CustomerChangingViewModel customerChangingViewModel = Provider.of<CustomerChangingViewModel>(context, listen: false);
user.createNew();
return Scaffold(
key: _scaffoldKey,
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
@@ -91,8 +95,13 @@ class _RegistrationPageState extends State {
onPressed:() => {
if (_formKey.currentState.validate()) {
model = UserChangingViewModel(user),
model.addUser(),
Navigator.of(context).pushNamed("customerModifyPage",)
model.addUser().then((_) =>
{
Navigator.of(context).pushNamed("customerModifyPage",),
customerChangingViewModel.customer.setCustomer(Auth().userLoggedIn),
}).catchError(( error, stackTrace )=> showInSnackBar()
),
}
}),
]),
@@ -119,4 +128,15 @@ class _RegistrationPageState extends State {
);
}
void showInSnackBar() {
_scaffoldKey.currentState.showSnackBar(
SnackBar(
backgroundColor: Colors.orange,
content: Text(
AppLocalizations.of(context).translate("Customer exists"),
style: TextStyle(color: Colors.white))
)
);
}
}
+17 -1
View File
@@ -19,7 +19,19 @@ class CustomerViewModel {
}
int get birthYear {
return this.birthYear;
return this.customer.birthYear;
}
String get goal {
return this.customer.goal;
}
String get fitnessLevel {
return this.customer.fitnessLevel;
}
String get bodyType {
return this.customer.bodyType;
}
setName(String name) {
@@ -69,4 +81,8 @@ class CustomerViewModel {
Customer getCustomer() {
return this.customer;
}
void setCustomer ( Customer customer ) {
this.customer = customer;
}
}
+1 -1
View File
@@ -42,7 +42,7 @@ class BottomNavigator {
break;
case 1:
throw new StateError('This is a Dart exception on event.');
//throw new StateError('This is a Dart exception on event.');
break;
case 2: