feat: add password validation and fix initialEmail

This commit is contained in:
Joey Boerwinkel 2022-10-31 14:37:09 +01:00
parent c4f66f3c69
commit 0aeab11d58
6 changed files with 37 additions and 10 deletions

View file

@ -1,3 +1,10 @@
## 2.0.0
* add forgot password validation on button press
* add onDisabledPress param for methods
* correctly use initialEmail in forgot password screen
## 0.0.1
* TODO: Describe initial release.

View file

@ -11,11 +11,16 @@ final loginOptions = LoginOptions(
passwordInputPrefix: const Icon(Icons.password),
title: const Text('Login'),
image: const FlutterLogo(),
requestForgotPasswordButtonBuilder: (context, onPressed, isDisabled) {
requestForgotPasswordButtonBuilder: (
context,
onPressed,
isDisabled,
onDisabledPress,
) {
return Opacity(
opacity: isDisabled ? 0.5 : 1.0,
child: ElevatedButton(
onPressed: onPressed,
onPressed: isDisabled ? onDisabledPress : onPressed,
child: const Text('Send request'),
),
);

View file

@ -71,11 +71,12 @@ Widget _createLoginButton(
BuildContext context,
OptionalAsyncCallback onPressed,
bool disabled,
OptionalAsyncCallback onDisabledPress,
) {
return Opacity(
opacity: disabled ? 0.5 : 1.0,
child: ElevatedButton(
onPressed: onPressed,
onPressed: !disabled ? onPressed : onDisabledPress,
child: const Text('Login'),
),
);
@ -85,11 +86,12 @@ Widget _createForgotPasswordButton(
BuildContext context,
OptionalAsyncCallback onPressed,
bool disabled,
OptionalAsyncCallback onDisabledPress,
) {
return Opacity(
opacity: disabled ? 0.5 : 1.0,
child: TextButton(
onPressed: onPressed,
child: ElevatedButton(
onPressed: !disabled ? onPressed : onDisabledPress,
child: const Text('Forgot password?'),
),
);
@ -99,11 +101,12 @@ Widget _createRequestForgotPasswordButton(
BuildContext context,
OptionalAsyncCallback onPressed,
bool disabled,
OptionalAsyncCallback onDisabledPress,
) {
return Opacity(
opacity: disabled ? 0.5 : 1.0,
child: TextButton(
onPressed: onPressed,
child: ElevatedButton(
onPressed: !disabled ? onPressed : onDisabledPress,
child: const Text('Send request'),
),
);
@ -113,11 +116,12 @@ Widget _createRegisterButton(
BuildContext context,
OptionalAsyncCallback onPressed,
bool disabled,
OptionalAsyncCallback onDisabledPress,
) {
return Opacity(
opacity: disabled ? 0.5 : 1.0,
child: TextButton(
onPressed: onPressed,
child: ElevatedButton(
onPressed: !disabled ? onPressed : onDisabledPress,
child: const Text('Create Account'),
),
);
@ -127,6 +131,7 @@ typedef ButtonBuilder = Widget Function(
BuildContext context,
OptionalAsyncCallback onPressed,
bool isDisabled,
OptionalAsyncCallback onDisabledPress,
);
typedef InputContainerBuilder = Widget Function(

View file

@ -159,6 +159,7 @@ class _EmailPasswordLoginFormState extends State<EmailPasswordLoginForm> {
widget.onForgotPassword?.call(_currentEmail);
},
false,
() {},
),
),
],
@ -170,6 +171,9 @@ class _EmailPasswordLoginFormState extends State<EmailPasswordLoginForm> {
context,
_handleLogin,
!_formValid.value,
() {
_formKey.currentState?.validate();
},
);
},
),
@ -183,6 +187,7 @@ class _EmailPasswordLoginFormState extends State<EmailPasswordLoginForm> {
);
},
false,
() {},
),
]
],

View file

@ -33,6 +33,7 @@ class _ForgotPasswordFormState extends State<ForgotPasswordForm> {
void initState() {
super.initState();
_focusNode.requestFocus();
_currentEmail = widget.initialEmail ?? widget.options.initialEmail;
}
@override
@ -123,11 +124,15 @@ class _ForgotPasswordFormState extends State<ForgotPasswordForm> {
child: widget.options.requestForgotPasswordButtonBuilder(
context,
() {
_formKey.currentState?.validate();
if (_formValid.value) {
widget.onRequestForgotPassword(_currentEmail);
}
},
!_formValid.value,
() {
_formKey.currentState?.validate();
},
),
);
},

View file

@ -1,6 +1,6 @@
name: flutter_login
description: A new Flutter package project.
version: 1.0.0
version: 2.0.0
environment:
sdk: ">=2.18.1 <3.0.0"