From ff85850c5d34625cc47d26e2c8847349c6497ba5 Mon Sep 17 00:00:00 2001 From: Edouard Marquez Date: Mon, 11 Apr 2022 14:51:08 +0200 Subject: [PATCH 1/2] Sign up page: Fix trimmed text not being done correctly --- packages/smooth_app/lib/helpers/user_management_helper.dart | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/smooth_app/lib/helpers/user_management_helper.dart b/packages/smooth_app/lib/helpers/user_management_helper.dart index ada0b7e5f60..c95aee58618 100644 --- a/packages/smooth_app/lib/helpers/user_management_helper.dart +++ b/packages/smooth_app/lib/helpers/user_management_helper.dart @@ -1,3 +1,5 @@ +import 'package:flutter/widgets.dart'; + class UserManagementHelper { UserManagementHelper._(); @@ -20,3 +22,7 @@ class UserManagementHelper { static bool isPasswordValid(final String password) => password.length >= 6; } + +extension UserManagementTextController on TextEditingController { + String get trimmedText => text.trim(); +} From c9b4058072016bbc1a10064b8c721044ce84eb3f Mon Sep 17 00:00:00 2001 From: Edouard Marquez Date: Mon, 11 Apr 2022 15:16:54 +0200 Subject: [PATCH 2/2] Add missing file --- .../pages/user_management/sign_up_page.dart | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/smooth_app/lib/pages/user_management/sign_up_page.dart b/packages/smooth_app/lib/pages/user_management/sign_up_page.dart index 35a6b6927a2..d620bbd203a 100644 --- a/packages/smooth_app/lib/pages/user_management/sign_up_page.dart +++ b/packages/smooth_app/lib/pages/user_management/sign_up_page.dart @@ -87,13 +87,12 @@ class _SignUpPageState extends State { validator: (String? value) { if (value == null || value.isEmpty) { return appLocalizations.sign_up_page_email_error_empty; - } - _emailController.text = value.trim(); - if (!UserManagementHelper.isEmailValid(value.trim())) { + } else if (!UserManagementHelper.isEmailValid( + _emailController.trimmedText)) { return appLocalizations.sign_up_page_email_error_invalid; + } else { + return null; } - - return null; }, ), const SizedBox(height: space), @@ -108,8 +107,8 @@ class _SignUpPageState extends State { if (value == null || value.isEmpty) { return appLocalizations.sign_up_page_username_error_empty; } - _userController.text = value.trim(); - if (!UserManagementHelper.isUsernameValid(value.trim())) { + if (!UserManagementHelper.isUsernameValid( + _userController.trimmedText)) { return appLocalizations.sign_up_page_username_description; } return null; @@ -128,11 +127,11 @@ class _SignUpPageState extends State { validator: (String? value) { if (value == null || value.isEmpty) { return appLocalizations.sign_up_page_password_error_empty; - } - if (!UserManagementHelper.isPasswordValid(value)) { + } else if (!UserManagementHelper.isPasswordValid(value)) { return appLocalizations.sign_up_page_password_error_invalid; + } else { + return null; } - return null; }, ), const SizedBox(height: space), @@ -149,12 +148,13 @@ class _SignUpPageState extends State { if (value == null || value.isEmpty) { return appLocalizations .sign_up_page_confirm_password_error_empty; - } - if (value != _password1Controller.text) { + } else if (_password2Controller.text != + _password1Controller.text) { return appLocalizations .sign_up_page_confirm_password_error_invalid; + } else { + return null; } - return null; }, ), const SizedBox(height: space), @@ -282,17 +282,17 @@ class _SignUpPageState extends State { return; } final User user = User( - userId: _userController.text, + userId: _userController.trimmedText, password: _password1Controller.text, ); final Status? status = await LoadingDialog.run( context: context, future: OpenFoodAPIClient.register( user: user, - name: _displayNameController.text, - email: _emailController.text, + name: _displayNameController.trimmedText, + email: _emailController.trimmedText, newsletter: _subscribe, - orgName: _foodProducer ? _brandController.text : null, + orgName: _foodProducer ? _brandController.trimmedText : null, ), title: AppLocalizations.of(context)!.sign_up_page_action_doing_it, );