workouttest_app/lib/view/customer_modify_page.dart
2020-10-09 07:54:54 +02:00

236 lines
11 KiB
Dart

import 'package:aitrainer_app/bloc/account/account_bloc.dart';
import 'package:aitrainer_app/bloc/customer_change_form_bloc.dart';
import 'package:aitrainer_app/util/trans.dart';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_form_bloc/flutter_form_bloc.dart';
import '../library_keys.dart';
// ignore: must_be_immutable
class CustomerModifyPage extends StatelessWidget with Trans {
final _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
setContext(context);
// ignore: close_sinks
final accountBloc = BlocProvider.of<AccountBloc>(context);
// we cannot initialize the translations in the initState
/* genders.forEach((GenderItem element) {
if (element.dbValue == "m") {
element.name = AppLocalizations.of(context).translate("Man");
}
if (element.dbValue == "w") {
element.name = AppLocalizations.of(context).translate("Woman");
}
});
*/
return BlocProvider(
create: (context) => CustomerChangeFormBloc(customerRepository: accountBloc.customerRepository),
child: Builder(builder: (context) {
// ignore: close_sinks
final customerBloc = BlocProvider.of<CustomerChangeFormBloc>(context);
return Scaffold(
resizeToAvoidBottomInset: true,
appBar: AppBar(
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text("Profil"),
Image.asset(
'asset/image/WT_long_logo.png',
fit: BoxFit.cover,
height: 65.0,
),
],
),
//title: Text(AppLocalizations.of(context).translate('Settings')),
backgroundColor: Colors.transparent,
),
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('asset/image/WT_light_background.png'),
fit: BoxFit.cover,
alignment: Alignment.center,
),
),
child: Form(
key: _formKey,
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
padding: EdgeInsets.only(top: 40, left: 25, right: 45, bottom: 100),
child: Container(
alignment: Alignment.center,
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: TextFieldBlocBuilder(
key: LibraryKeys.loginEmailField,
style: TextStyle(fontSize: 12),
textFieldBloc: customerBloc.emailField,
decoration: InputDecoration(
fillColor: Colors.white24,
filled: true,
labelText: t('Email'),
),
),
/* TextFormField(
style: TextStyle(fontSize: 12),
decoration: InputDecoration(
fillColor: Colors.white24,
filled: true,
labelText: AppLocalizations.of(context)
.translate('Email'),
), */
// initialValue: customerChangingViewModel.customer
// .customer.email,
// onFieldSubmitted: (input) =>
// customerChangingViewModel.customer.setEmail(
// input)
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: TextFieldBlocBuilder(
style: TextStyle(fontSize: 12),
textFieldBloc: customerBloc.passwordField,
suffixButton: SuffixButton.obscureText,
decoration: InputDecoration(
fillColor: Colors.white24,
filled: true,
labelText: t('Password (Leave empty if no change)'),
),
),
/*TextFormField(
style: TextStyle(fontSize: 12),
obscureText: true,
decoration: InputDecoration(
fillColor: Colors.white24,
filled: true,
labelText: AppLocalizations.of(context)
.translate(
'Password (Leave empty if you don\'t want to change)'),
),
//initialValue: customerChangingViewModel.customer.customer.password,
// onFieldSubmitted: (input) => customerChangingViewModel.customer.setPassword(input)
)*/
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: TextFieldBlocBuilder(
style: TextStyle(fontSize: 12),
textFieldBloc: customerBloc.nameField,
decoration: InputDecoration(
fillColor: Colors.white24,
filled: true,
labelText: t('Name'),
),
),
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: TextFieldBlocBuilder(
style: TextStyle(fontSize: 12),
textFieldBloc: customerBloc.firstNameField,
decoration: InputDecoration(
fillColor: Colors.white24,
filled: true,
labelText: t('First Name'),
),
),
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: TextFieldBlocBuilder(
style: TextStyle(fontSize: 12),
textFieldBloc: customerBloc.birthYearField,
inputFormatters: [FilteringTextInputFormatter.allow(RegExp(r"[\d]"))],
decoration: InputDecoration(
fillColor: Colors.white24,
filled: true,
labelText: t('Birth Year'),
),
),
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: TextFieldBlocBuilder(
style: TextStyle(fontSize: 12),
textFieldBloc: customerBloc.weightField,
inputFormatters: [FilteringTextInputFormatter.allow(RegExp(r"[\d]"))],
decoration: InputDecoration(
fillColor: Colors.white24,
filled: true,
labelText: t('Weight'),
),
),
)
],
),
Divider(),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: DropdownFieldBlocBuilder(
selectFieldBloc: customerBloc.genderField,
itemBuilder: (context, item) => item,
decoration: InputDecoration(
labelText: t('Select a gender'),
)),
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Expanded(
child: RaisedButton(
color: Colors.orange,
textColor: Colors.white,
child: InkWell(child: Text(t("Next"))),
onPressed: () => {
customerBloc.add(SubmitFormBloc()),
Navigator.of(context)
.pushNamed("customerGoalPage", arguments: customerBloc.customerRepository)
},
))
],
),
],
),
),
),
)));
}));
}
}