workouttest_app/lib/view/account.dart
2020-08-17 12:38:47 +02:00

231 lines
7.4 KiB
Dart

import 'package:aitrainer_app/bloc/account/account_bloc.dart';
import 'package:aitrainer_app/localization/app_localization.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:aitrainer_app/widgets/bottom_nav.dart';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
// ignore: must_be_immutable
class AccountPage extends StatelessWidget {
// ignore: close_sinks
AccountBloc accountBloc;
@override
Widget build(BuildContext context) {
accountBloc = BlocProvider.of<AccountBloc>(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: BlocConsumer<AccountBloc, AccountState>(
listener: (context, state) {
if (state is AccountError) {
Scaffold.of(context).showSnackBar(SnackBar(
backgroundColor: Colors.orange,
content:
Text(state.message, style: TextStyle(color: Colors.white))));
} else if (state is AccountLoading) {
}
},
builder: (context, state) {
if ( state is AccountInitial ) {
String customerName = accountBloc.customerRepository.firstName +
" " + accountBloc.customerRepository.name;
return accountWidget(context, customerName, accountBloc);
} else if ( state is AccountLoggedIn ) {
String customerName = accountBloc.customerRepository.firstName +
" " + accountBloc.customerRepository.name;
return accountWidget(context, customerName, accountBloc);
} else if ( state is AccountLoggedOut ) {
String customerName = "";
return accountWidget(context, customerName, accountBloc);
} else if ( state is AccountReady ) {
String customerName = accountBloc.customerRepository.firstName +
" " + accountBloc.customerRepository.name;
return accountWidget(context, customerName, accountBloc);
} else {
return accountWidget(context, "", accountBloc);
}
}
),
),
bottomNavigationBar: BottomNavigator(bottomNavIndex: 2));
}
ListView accountWidget(BuildContext context, String customerName, AccountBloc accountBloc) {
return 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(customerName,
style: TextStyle(color: Colors.blue)),
Icon(Icons.arrow_forward_ios),
]),
textColor: Colors.grey,
color: Colors.white,
onPressed: () => {
if (accountBloc.customerRepository.customer != null) {
Navigator.of(context).pushNamed('customerModifyPage'),
print("Profile"),
}
},
),
),
loginOut( context, accountBloc ),
//exercises(exerciseChangingViewModel),
]);
}
ListTile loginOut( BuildContext context, AccountBloc accountBloc ) {
ListTile element = ListTile();
String text = "Logout";
Color buttonColor = Colors.orange;
if ( accountBloc.customerRepository.customer == null || accountBloc.customerRepository.customer.email == null) {
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: () => {
if ( accountBloc.loggedIn ) {
accountBloc.add(AccountLogout())
} else {
accountBloc.add(AccountLogin()),
Navigator.of(context).pushNamed('login'),
}
},
),
);
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;
} */
}