diff --git a/CHANGELOG.md b/CHANGELOG.md index 41cc7d8..918f750 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/example/lib/main.dart b/example/lib/main.dart index d6c66e9..94b1b34 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -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'), ), ); diff --git a/lib/src/config/login_options.dart b/lib/src/config/login_options.dart index 3347388..dcf23fa 100644 --- a/lib/src/config/login_options.dart +++ b/lib/src/config/login_options.dart @@ -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( diff --git a/lib/src/widgets/email_password_login.dart b/lib/src/widgets/email_password_login.dart index db3fc2a..3d2a6d3 100644 --- a/lib/src/widgets/email_password_login.dart +++ b/lib/src/widgets/email_password_login.dart @@ -159,6 +159,7 @@ class _EmailPasswordLoginFormState extends State { widget.onForgotPassword?.call(_currentEmail); }, false, + () {}, ), ), ], @@ -170,6 +171,9 @@ class _EmailPasswordLoginFormState extends State { context, _handleLogin, !_formValid.value, + () { + _formKey.currentState?.validate(); + }, ); }, ), @@ -183,6 +187,7 @@ class _EmailPasswordLoginFormState extends State { ); }, false, + () {}, ), ] ], diff --git a/lib/src/widgets/forgot_password_form.dart b/lib/src/widgets/forgot_password_form.dart index f879cd6..3a1a5eb 100644 --- a/lib/src/widgets/forgot_password_form.dart +++ b/lib/src/widgets/forgot_password_form.dart @@ -33,6 +33,7 @@ class _ForgotPasswordFormState extends State { void initState() { super.initState(); _focusNode.requestFocus(); + _currentEmail = widget.initialEmail ?? widget.options.initialEmail; } @override @@ -123,11 +124,15 @@ class _ForgotPasswordFormState extends State { child: widget.options.requestForgotPasswordButtonBuilder( context, () { + _formKey.currentState?.validate(); if (_formValid.value) { widget.onRequestForgotPassword(_currentEmail); } }, !_formValid.value, + () { + _formKey.currentState?.validate(); + }, ), ); }, diff --git a/pubspec.yaml b/pubspec.yaml index 74d5c1d..11e5e60 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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"