import 'package:aitrainer_app/bloc/account/account_bloc.dart'; import 'package:aitrainer_app/bloc/customer_change_form_bloc.dart'; import 'package:aitrainer_app/localization/app_localization.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{ final _formKey = GlobalKey(); @override Widget build(BuildContext context) { // ignore: close_sinks final accountBloc = BlocProvider.of(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(context); return Scaffold( resizeToAvoidBottomInset: true, appBar: AppBar( title: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ 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: AppLocalizations.of(context) .translate('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: AppLocalizations.of(context) .translate('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: AppLocalizations.of(context) .translate('Name'), ), ), ) ], ), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Expanded( child: TextFieldBlocBuilder( style: TextStyle(fontSize: 12), textFieldBloc: customerBloc.firstNameField, decoration: InputDecoration( fillColor: Colors.white24, filled: true, labelText: AppLocalizations.of(context) .translate('First Name'), ), ), ) ], ), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Expanded( child: TextFieldBlocBuilder( style: TextStyle(fontSize: 12), textFieldBloc: customerBloc.birthYearField, inputFormatters: [ WhitelistingTextInputFormatter (RegExp(r"[\d]")) ], decoration: InputDecoration( fillColor: Colors.white24, filled: true, labelText: AppLocalizations.of(context) .translate('Birth Year'), ), ), ) ], ), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Expanded( child: TextFieldBlocBuilder( style: TextStyle(fontSize: 12), textFieldBloc: customerBloc.weightField, inputFormatters: [ WhitelistingTextInputFormatter (RegExp(r"[\d]")) ], decoration: InputDecoration( fillColor: Colors.white24, filled: true, labelText: AppLocalizations.of(context) .translate('Weight'), ), ), ) ], ), Divider(), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Expanded( child: DropdownFieldBlocBuilder( selectFieldBloc: customerBloc.genderField, itemBuilder: (context, item) => item, decoration: InputDecoration( labelText: AppLocalizations.of(context).translate( 'Select a gender'), ) ), ) /* child: DropdownButtonHideUnderline( child: DropdownButton( hint: Text( AppLocalizations.of(context).translate( 'Select a gender')), style: TextStyle( fontSize: 12, color: Colors.black), focusColor: Colors.white24, // value: selectedGender, items: genders.map((GenderItem gender) { return DropdownMenuItem( value: gender, child: Text(gender.name) ); }).toList(), onChanged: (GenderItem gender) => { // setState(() { // selectedGender = gender; // customerChangingViewModel.customer.setSex(gender.dbValue); print ("Gender " + gender.name); //}) //model.customer.sex = }, ) ) */ ], ), Row( mainAxisAlignment: MainAxisAlignment.end, children: [ Expanded( child: RaisedButton( color: Colors.orange, textColor: Colors.white, child: InkWell( child: Text( AppLocalizations.of(context).translate( "Next"))), onPressed: () => { customerBloc.add(SubmitFormBloc()), Navigator.of(context).pushNamed("customerGoalPage", arguments: customerBloc.customerRepository) }, ) ) ], ), ], ), ), ), ) ) ); }) ); } }