Skip to content

Commit

Permalink
Merge pull request #303 from sudip39/master
Browse files Browse the repository at this point in the history
Fixed label text not changing according to user type #289
  • Loading branch information
juliansteenbakker authored Mar 15, 2022
2 parents 944dbf8 + fc1b98f commit 7e2b8d4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
7 changes: 3 additions & 4 deletions lib/src/providers/login_messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:flutter/material.dart';

class LoginMessages with ChangeNotifier {
LoginMessages({
this.userHint = defaultUserHint,
this.userHint,
this.passwordHint = defaultPasswordHint,
this.confirmPasswordHint = defaultConfirmPasswordHint,
this.forgotPasswordButton = defaultForgotPasswordButton,
Expand Down Expand Up @@ -38,7 +38,6 @@ class LoginMessages with ChangeNotifier {
this.recoverCodePasswordDescription = defaultRecoverCodePasswordDescription,
});

static const defaultUserHint = 'Email';
static const defaultPasswordHint = 'Password';
static const defaultConfirmPasswordHint = 'Confirm Password';
static const defaultForgotPasswordButton = 'Forgot Password?';
Expand Down Expand Up @@ -80,8 +79,8 @@ class LoginMessages with ChangeNotifier {
static const defaultConfirmSignupSuccess = 'Account confirmed.';

/// Hint text of the userHint [TextField]
/// By default is Email
final String userHint;
/// Default will be selected based on userType
final String? userHint;

/// Additional signup form button's label
final String additionalSignUpSubmitButton;
Expand Down
25 changes: 25 additions & 0 deletions lib/src/utils/text_field_utils.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_login/src/models/login_user_type.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';

class TextFieldUtils {
static String getAutofillHints(LoginUserType userType) {
Expand All @@ -25,4 +26,28 @@ class TextFieldUtils {
return TextInputType.emailAddress;
}
}

static Icon getPrefixIcon(LoginUserType userType) {
switch (userType) {
case LoginUserType.name:
return const Icon(FontAwesomeIcons.userCircle);
case LoginUserType.phone:
return const Icon(FontAwesomeIcons.phoneSquareAlt);
case LoginUserType.email:
default:
return const Icon(FontAwesomeIcons.envelopeSquare);
}
}

static String getLabelText(LoginUserType userType) {
switch (userType) {
case LoginUserType.name:
return "Name";
case LoginUserType.phone:
return "Phone";
case LoginUserType.email:
default:
return "Email";
}
}
}
5 changes: 3 additions & 2 deletions lib/src/widgets/cards/login_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,12 @@ class _LoginCardState extends State<_LoginCard> with TickerProviderStateMixin {
width: width,
loadingController: widget.loadingController,
interval: _nameTextFieldLoadingAnimationInterval,
labelText: messages.userHint,
labelText:
messages.userHint ?? TextFieldUtils.getLabelText(widget.userType),
autofillHints: _isSubmitting
? null
: [TextFieldUtils.getAutofillHints(widget.userType)],
prefixIcon: const Icon(FontAwesomeIcons.solidUserCircle),
prefixIcon: TextFieldUtils.getPrefixIcon(widget.userType),
keyboardType: TextFieldUtils.getKeyboardType(widget.userType),
textInputAction: TextInputAction.next,
onFieldSubmitted: (value) {
Expand Down

0 comments on commit 7e2b8d4

Please sign in to comment.