Add onFieldSubmitted to allow "enter" button interaction

This commit is contained in:
OmarHatem 2023-02-18 00:13:51 +02:00
parent 1b89228893
commit c920b62aa0
4 changed files with 25 additions and 13 deletions

View file

@ -66,6 +66,7 @@ class IoniaCreateAccountPage extends BasePage {
validator: EmailValidator(),
keyboardType: TextInputType.emailAddress,
controller: _emailController,
onSubmit: (_) => _createAccount(),
),
),
bottomSectionPadding: EdgeInsets.symmetric(vertical: 36, horizontal: 24),
@ -77,12 +78,7 @@ class IoniaCreateAccountPage extends BasePage {
Observer(
builder: (_) => LoadingPrimaryButton(
text: S.of(context).create_account,
onPressed: () async {
if (_formKey.currentState != null && !_formKey.currentState!.validate()) {
return;
}
await _authViewModel.createUser(_emailController.text);
},
onPressed: _createAccount,
isLoading: _authViewModel.createUserState is IoniaCreateStateLoading,
color: Theme.of(context).accentTextTheme!.bodyText1!.color!,
textColor: Colors.white,
@ -151,4 +147,11 @@ class IoniaCreateAccountPage extends BasePage {
Routes.ioniaVerifyIoniaOtpPage,
arguments: [authViewModel.email, false],
);
void _createAccount() async {
if (_formKey.currentState != null && !_formKey.currentState!.validate()) {
return;
}
await _authViewModel.createUser(_emailController.text);
}
}

View file

@ -57,6 +57,7 @@ class IoniaLoginPage extends BasePage {
keyboardType: TextInputType.emailAddress,
validator: EmailValidator(),
controller: _emailController,
onSubmit: (text) => _login(),
),
),
bottomSectionPadding: EdgeInsets.symmetric(vertical: 36, horizontal: 24),
@ -68,12 +69,7 @@ class IoniaLoginPage extends BasePage {
Observer(
builder: (_) => LoadingPrimaryButton(
text: S.of(context).login,
onPressed: () async {
if (_formKey.currentState != null && !_formKey.currentState!.validate()) {
return;
}
await _authViewModel.signIn(_emailController.text);
},
onPressed: _login,
isLoading: _authViewModel.signInState is IoniaCreateStateLoading,
color: Theme.of(context).accentTextTheme!.bodyText1!.color!,
textColor: Colors.white,
@ -106,4 +102,11 @@ class IoniaLoginPage extends BasePage {
Routes.ioniaVerifyIoniaOtpPage,
arguments: [authViewModel.email, true],
);
void _login() async {
if (_formKey.currentState != null && !_formKey.currentState!.validate()) {
return;
}
await _authViewModel.signIn(_emailController.text);
}
}

View file

@ -82,6 +82,7 @@ class IoniaVerifyIoniaOtp extends BasePage {
keyboardType: TextInputType.numberWithOptions(signed: false, decimal: true),
focusNode: _codeFocus,
controller: _codeController,
onSubmit: (_) => _verify(),
),
SizedBox(height: 14),
Text(
@ -116,7 +117,7 @@ class IoniaVerifyIoniaOtp extends BasePage {
Observer(
builder: (_) => LoadingPrimaryButton(
text: S.of(context).continue_text,
onPressed: () async => await _authViewModel.verifyEmail(_codeController.text),
onPressed: _verify,
isDisabled: _authViewModel.otpState is IoniaOtpSendDisabled,
isLoading: _authViewModel.otpState is IoniaOtpValidating,
color: Theme.of(context).accentTextTheme!.bodyText1!.color!,
@ -148,4 +149,6 @@ class IoniaVerifyIoniaOtp extends BasePage {
void _onOtpSuccessful(BuildContext context) =>
Navigator.of(context)
.pushNamedAndRemoveUntil(Routes.ioniaManageCardsPage, (route) => route.isFirst);
void _verify() async => await _authViewModel.verifyEmail(_codeController.text);
}

View file

@ -27,6 +27,7 @@ class BaseTextFormField extends StatelessWidget {
this.maxLength,
this.focusNode,
this.initialValue,
this.onSubmit,
this.borderWidth = 1.0});
final TextEditingController? controller;
@ -54,6 +55,7 @@ class BaseTextFormField extends StatelessWidget {
final bool? enableInteractiveSelection;
final String? initialValue;
final double borderWidth;
final void Function(String)? onSubmit;
@override
Widget build(BuildContext context) {
@ -71,6 +73,7 @@ class BaseTextFormField extends StatelessWidget {
inputFormatters: inputFormatters,
enabled: enabled,
maxLength: maxLength,
onFieldSubmitted: onSubmit,
style: textStyle ??
TextStyle(
fontSize: 16.0,