246 lines
7.8 KiB
Dart
246 lines
7.8 KiB
Dart
|
|
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/exercise_changing_view_model.dart';
|
|
import 'package:aitrainer_app/viewmodel/exercise_view_model.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'package:aitrainer_app/viewmodel/user_view_model.dart';
|
|
import 'package:aitrainer_app/widgets/bottom_nav.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
class AccountPage extends StatefulWidget{
|
|
_AccountPagePageState _state;
|
|
|
|
_AccountPagePageState createState() {
|
|
_state = new _AccountPagePageState();
|
|
return _state;
|
|
}
|
|
}
|
|
|
|
class _AccountPagePageState extends State<AccountPage> {
|
|
final UserViewModel user = UserViewModel();
|
|
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;
|
|
|
|
|
|
|
|
@override
|
|
void initState() {
|
|
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 Scaffold(
|
|
appBar: AppBar(
|
|
title: Text(AppLocalizations.of(context).translate('Account')),
|
|
backgroundColor: Colors.transparent,
|
|
),
|
|
body: Container(
|
|
foregroundDecoration: BoxDecoration(
|
|
image: DecorationImage(
|
|
image: AssetImage('asset/image/WT_long_logo.png'),
|
|
alignment: Alignment.topRight,
|
|
),
|
|
),
|
|
decoration: BoxDecoration(
|
|
image: DecorationImage(
|
|
image: AssetImage('asset/image/WT_light_background.png'),
|
|
fit: BoxFit.cover,
|
|
alignment: Alignment.center,
|
|
),
|
|
),
|
|
child:
|
|
ListView(
|
|
padding: EdgeInsets.only(top: 135),
|
|
children: <Widget>[
|
|
ListTile(
|
|
leading: Icon(Icons.perm_identity),
|
|
subtitle: Text(
|
|
AppLocalizations.of(context).translate("Profile")),
|
|
title: FlatButton(
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(_loggedIn ? Auth().userLoggedIn.email + " " +
|
|
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");
|
|
}
|
|
},
|
|
),
|
|
|
|
),
|
|
ListTile(
|
|
leading: Icon(Icons.language),
|
|
title: Text(appLanguage.appLocal == Locale('en') ?
|
|
AppLocalizations.of(context).translate("English") :
|
|
AppLocalizations.of(context).translate("Hungarian")),
|
|
subtitle: Text(AppLocalizations.of(context).translate(
|
|
"Selected Language")),
|
|
),
|
|
loginOut(),
|
|
exercises( model ),
|
|
]
|
|
)
|
|
),
|
|
bottomNavigationBar: bottomNav.buildBottomNavigator(context, widget._state)
|
|
);
|
|
}
|
|
|
|
ListTile loginOut() {
|
|
ListTile element = ListTile();
|
|
|
|
String text = "Logout";
|
|
Color buttonColor = Colors.orange;
|
|
|
|
if ( ! _loggedIn ) {
|
|
text = "Login";
|
|
buttonColor = Colors.blue;
|
|
}
|
|
|
|
element = ListTile(
|
|
enabled: true,
|
|
leading: Icon(Icons.input),
|
|
title: FlatButton(
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(AppLocalizations.of(context).translate(text),
|
|
style: TextStyle(
|
|
color: buttonColor
|
|
)),
|
|
Icon(Icons.arrow_forward_ios),
|
|
]),
|
|
textColor: buttonColor,
|
|
color: Colors.white,
|
|
onPressed: () {
|
|
setState(() {
|
|
if ( ! _loggedIn) {
|
|
print("Login");
|
|
Navigator.of(context).pushNamed("login");
|
|
} else {
|
|
print("Logout");
|
|
_loggedIn = false;
|
|
Auth().logout();
|
|
|
|
}
|
|
|
|
});
|
|
},
|
|
),
|
|
);
|
|
|
|
return element;
|
|
}
|
|
|
|
ListTile exercises( ExerciseChangingViewModel model ) {
|
|
ListTile element = ListTile();
|
|
if ( Auth().userLoggedIn == null ) {
|
|
return element;
|
|
}
|
|
|
|
element = ListTile(
|
|
title: Text(AppLocalizations.of(context).translate("Exercises")),
|
|
subtitle: Column(
|
|
children: [
|
|
FutureBuilder<List<ExerciseViewModel>>(
|
|
future: _exercises,
|
|
builder: (context, snapshot) {
|
|
if (snapshot.hasData) {
|
|
return getExercises( model );//CustomerListWidget(customers: _exerciseViewModel.exerciseList);
|
|
} else if (snapshot.hasError) {
|
|
return Text("${snapshot.error}");
|
|
}
|
|
|
|
// By default, show a loading spinner.
|
|
return CircularProgressIndicator();
|
|
}
|
|
),]
|
|
));
|
|
|
|
return element;
|
|
}
|
|
|
|
Widget getExercises( ExerciseChangingViewModel model ) {
|
|
List<ExerciseViewModel> exercises = model.exerciseList;
|
|
|
|
Column element = Column();
|
|
if (exercises.length > 0) {
|
|
List<Column> rows = List();
|
|
|
|
exercises.forEach((exercise) {
|
|
String exerciseName = AppLocalizations.of(context).translate(
|
|
Common.getExerciseType(exercise.getExercise().exerciseTypeId).name);
|
|
|
|
String quantity = exercise.getExercise().quantity.toString() + " " +
|
|
AppLocalizations.of(context).translate(exercise.getExercise().unit);
|
|
|
|
String unitQuantity = "";
|
|
String unitQuantityUnit = "";
|
|
String date = Common.getDateLocale(exercise.getExercise().dateAdd, false);
|
|
if (exercise.getExercise().unitQuantity != null) {
|
|
unitQuantity = exercise.getExercise().unitQuantity.toString();
|
|
unitQuantityUnit = AppLocalizations.of(context).translate(
|
|
Common.getExerciseType(exercise.getExercise().exerciseTypeId).unitQuantityUnit);
|
|
}
|
|
|
|
TableRow row = TableRow(
|
|
children: [
|
|
Text(date),
|
|
Text(exerciseName),
|
|
Text(quantity),
|
|
|
|
Text(unitQuantity + " " + unitQuantityUnit),
|
|
]
|
|
);
|
|
|
|
Table table = Table(
|
|
defaultColumnWidth: FractionColumnWidth(0.28),
|
|
children: [row],
|
|
);
|
|
|
|
Column col = Column(
|
|
children: [
|
|
table,
|
|
Row(
|
|
children: [
|
|
Text(" "),
|
|
]
|
|
)
|
|
],
|
|
);
|
|
rows.add(col);
|
|
});
|
|
|
|
|
|
element = Column(
|
|
children: rows,
|
|
);
|
|
}
|
|
|
|
return element;
|
|
|
|
}
|
|
} |