Skip to content

Commit

Permalink
fix: Sign up page: Fix trimmed text not being done correctly (#1545)
Browse files Browse the repository at this point in the history
* Sign up page: Fix trimmed text not being done correctly

* Add missing file
  • Loading branch information
g123k authored Apr 12, 2022
1 parent 6488e44 commit 3bfe7f7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
6 changes: 6 additions & 0 deletions packages/smooth_app/lib/helpers/user_management_helper.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:flutter/widgets.dart';

class UserManagementHelper {
UserManagementHelper._();

Expand All @@ -20,3 +22,7 @@ class UserManagementHelper {

static bool isPasswordValid(final String password) => password.length >= 6;
}

extension UserManagementTextController on TextEditingController {
String get trimmedText => text.trim();
}
34 changes: 17 additions & 17 deletions packages/smooth_app/lib/pages/user_management/sign_up_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,12 @@ class _SignUpPageState extends State<SignUpPage> {
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),
Expand All @@ -114,8 +113,8 @@ class _SignUpPageState extends State<SignUpPage> {
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;
Expand All @@ -136,11 +135,11 @@ class _SignUpPageState extends State<SignUpPage> {
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),
Expand All @@ -157,12 +156,13 @@ class _SignUpPageState extends State<SignUpPage> {
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),
Expand Down Expand Up @@ -290,17 +290,17 @@ class _SignUpPageState extends State<SignUpPage> {
return;
}
final User user = User(
userId: _userController.text,
userId: _userController.trimmedText,
password: _password1Controller.text,
);
final Status? status = await LoadingDialog.run<Status>(
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,
);
Expand Down

0 comments on commit 3bfe7f7

Please sign in to comment.