diff --git a/lib/flutter_login_view.dart b/lib/flutter_login_view.dart index f0abde8..f68c92a 100644 --- a/lib/flutter_login_view.dart +++ b/lib/flutter_login_view.dart @@ -9,7 +9,6 @@ import 'plugins/login/choose_login.dart'; import 'widgets/custom_navigator.dart'; export '../plugins/form/form.dart'; export '../plugins/login/email_password_form.dart'; -export '../plugins/login/forgot_password_form.dart'; export '../plugins/login/login_email_password.dart'; export 'buttons.dart'; export 'login_config.dart'; diff --git a/lib/plugins/login/forgot_password.dart b/lib/plugins/login/forgot_password.dart index 59ce69b..dd3f1cc 100644 --- a/lib/plugins/login/forgot_password.dart +++ b/lib/plugins/login/forgot_password.dart @@ -1,189 +1,186 @@ import 'package:flutter/material.dart'; import 'package:flutter_login/flutter_login_view.dart'; - -import '../../extensions/widget.dart'; -import '../dialog/alert_dialog.dart'; import '../form/inputs/validators/email_validator.dart'; class ForgotPassword extends StatefulWidget { + const ForgotPassword({super.key}); + @override - _ForgotPasswordState createState() => _ForgotPasswordState(); + ForgotPasswordState createState() => ForgotPasswordState(); } -class _ForgotPasswordState extends State - with NavigateWidgetMixin { +class ForgotPasswordState extends State { String? email; bool showError = false; @override - Widget build(BuildContext context) => Material( - child: Scaffold( - body: context.login().screens.getAppshellScreenWrapper( - context, - backgroundImg: - context.login().config.loginOptions.backgroundImage, - child: Column( - children: [ - Expanded( - child: ListView( - children: [ - Container( - alignment: Alignment.topLeft, - padding: const EdgeInsets.only( - top: 27, - left: 5, - ), - child: context - .login() - .config - .appTheme - .buttons - .backButton( - context: context, - ), - ), - Container( - alignment: Alignment.topCenter, - child: Column( - children: [ - Text( - context - .translate('forgot_password.text.title'), - style: Theme.of(context).textTheme.headline6, - ), - Padding( - padding: const EdgeInsets.all(30.0), - child: Text( - context - .translate('forgot_password.text.body'), - style: - Theme.of(context).textTheme.subtitle1, - textAlign: TextAlign.left, - ), - ), - ], - ), - ), - Padding( - padding: const EdgeInsets.only(left: 30, right: 30), - child: Column( - children: [ - const Padding( - padding: EdgeInsets.only(bottom: 20), - ), - context - .login() - .config - .appTheme - .inputs - .textField( - title: context.translate( - 'forgot_password.input.email', - ), - validators: [ - EmailValidator( - errorMessage: context.translate( - 'forgot_password.error.invalid_email', - ), - ) - ], - onChange: (value, valid) { - setState(() { - showError = false; - }); - if (valid) email = value; - }, - ), - if (showError) ...[ - Text( - context.translate( - 'forgot_password.error.email_does_not_exist', - ), - style: Theme.of(context) - .textTheme - .bodyText2! - .copyWith( - color: Theme.of(context).errorColor, - ), - ), - ], - const Padding( - padding: EdgeInsets.only(bottom: 30), - ), - ], - ), - ), - ], - ), - ), - Container( - margin: const EdgeInsets.symmetric(horizontal: 30), - padding: const EdgeInsets.only(bottom: 40.0), - child: context - .login() - .config - .appTheme - .buttons - .primaryButton( - context: context, - child: Text( - context - .translate('forgot_password.button.submit'), - style: Theme.of(context).textTheme.button, - ), - onPressed: () async { - if (email != null) { - setState(() { - showError = false; - }); - - var result = await context - .loginRepository() - .forgotPassword(email!); - - if (result) { - await context.login().dialogs.showDialog( - context: context, - builder: (ctx) => AppShellAlertDialog - .singleButtonIcon( - title: - 'forgot_password.dialog.text.title', - body: context.translate( - 'forgot_password.dialog.text.body', - arguments: [email!], - ), - icon: Icon( - context - .login() - .config - .appTheme - .icons - .forgotPasswordMail, - size: 70, - ), - buttonText: - 'forgot_password.dialog.text.button', - onPressed: () { - Navigator.of(ctx).pop(); - context - .login() - .screens - .openLoginScreen(context); - }, - ), - ); - } else { - setState(() { - showError = true; - }); - } - } - }, - ), - ), - ], - ), + Widget build(BuildContext context) { + void showAlert({ + required String title, + required String text, + required String buttonTitle, + VoidCallback? buttonAction, + }) => + showDialog( + context: context, + builder: (BuildContext context) => AlertDialog( + title: Text(title), + content: Text(text), + actions: [ + TextButton( + onPressed: () { + Navigator.pop(context); + if (buttonAction != null) { + buttonAction(); + } + }, + child: Text(buttonTitle), ), + ], + ), + ); + + return Material( + child: Scaffold( + appBar: AppBar( + title: Text( + context.translate('forgot_password.text.title'), + ), ), - ); + body: context.login().screens.getAppshellScreenWrapper( + context, + backgroundImg: + context.login().config.loginOptions.backgroundImage, + child: Column( + children: [ + Expanded( + child: ListView( + children: [ + Container( + alignment: Alignment.topLeft, + padding: const EdgeInsets.only( + top: 27, + left: 5, + ), + child: context + .login() + .config + .appTheme + .buttons + .backButton( + context: context, + ), + ), + Padding( + padding: const EdgeInsets.all(30.0), + child: Text( + context.translate('forgot_password.text.body'), + style: Theme.of(context).textTheme.subtitle1, + textAlign: TextAlign.left, + ), + ), + Padding( + padding: const EdgeInsets.only(left: 30, right: 30), + child: Column( + children: [ + const Padding( + padding: EdgeInsets.only(bottom: 20), + ), + context.login().config.appTheme.inputs.textField( + title: context.translate( + 'forgot_password.input.email', + ), + validators: [ + EmailValidator( + errorMessage: context.translate( + 'forgot_password.error.invalid_email', + ), + ) + ], + onChange: (value, valid) { + setState(() { + showError = false; + }); + if (valid) { + email = value; + } + }, + ), + if (showError) ...[ + Text( + context.translate( + 'forgot_password.error.email_does_not_exist', + ), + style: Theme.of(context) + .textTheme + .bodyText2! + .copyWith( + color: Theme.of(context).errorColor, + ), + ), + ], + const Padding( + padding: EdgeInsets.only(bottom: 30), + ), + ], + ), + ), + ], + ), + ), + Container( + margin: const EdgeInsets.symmetric(horizontal: 30), + padding: const EdgeInsets.only(bottom: 40.0), + child: context + .login() + .config + .appTheme + .buttons + .primaryButton( + context: context, + child: Text( + context.translate('forgot_password.button.submit'), + style: Theme.of(context).textTheme.button, + ), + onPressed: () async { + if (email != null) { + setState(() { + showError = false; + }); + + var result = await context + .loginRepository() + .forgotPassword(email!); + + if (result) { + showAlert( + title: context.translate( + 'forgot_password.dialog.text.title', + ), + text: context.translate( + 'forgot_password.dialog.text.body', + arguments: [email], + ), + buttonTitle: context.translate( + 'forgot_password.dialog.text.button', + ), + buttonAction: () { + Navigator.pop(context); + }, + ); + } else { + setState(() { + showError = true; + }); + } + } + }, + ), + ), + ], + ), + ), + ), + ); + } } diff --git a/lib/plugins/login/forgot_password_form.dart b/lib/plugins/login/forgot_password_form.dart deleted file mode 100644 index 90468df..0000000 --- a/lib/plugins/login/forgot_password_form.dart +++ /dev/null @@ -1,188 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_login/flutter_login_view.dart'; -import '../../extensions/widget.dart'; -import '../dialog/alert_dialog.dart'; -import '../form/inputs/validators/email_validator.dart'; - -class ForgotPasswordForm extends StatefulWidget { - const ForgotPasswordForm({ - required this.onComplete, - required this.onBack, - super.key, - }); - - final VoidCallback onComplete; - final VoidCallback onBack; - - @override - _ForgotPasswordFormState createState() => _ForgotPasswordFormState(); -} - -class _ForgotPasswordFormState extends State - with NavigateWidgetMixin { - String? email; - bool showError = false; - - @override - Widget build(BuildContext context) { - return Material( - child: Scaffold( - body: context.login().screens.getAppshellScreenWrapper( - context, - backgroundImg: - context.login().config.loginOptions.backgroundImage, - child: Column( - children: [ - Expanded( - child: ListView( - children: [ - Container( - alignment: Alignment.topLeft, - padding: const EdgeInsets.only(top: 27, left: 5), - child: context - .login() - .config - .appTheme - .buttons - .backButton( - context: context, - onPressed: widget.onBack, - ), - ), - Container( - alignment: Alignment.topCenter, - child: Column( - children: [ - Text( - context.translate('forgot_password.text.title'), - style: Theme.of(context).textTheme.headline6, - ), - Padding( - padding: const EdgeInsets.all(30.0), - child: Text( - context - .translate('forgot_password.text.body'), - style: Theme.of(context).textTheme.subtitle1, - textAlign: TextAlign.left, - ), - ), - ], - ), - ), - Padding( - padding: const EdgeInsets.only(left: 30, right: 30), - child: Column( - children: [ - const Padding( - padding: EdgeInsets.only(bottom: 20), - ), - context.login().config.appTheme.inputs.textField( - title: context.translate( - 'forgot_password.input.email', - ), - validators: [ - EmailValidator( - errorMessage: context.translate( - 'forgot_password.error.invalid_email', - ), - ) - ], - onChange: (value, valid) { - setState(() { - showError = false; - }); - if (valid) { - email = value; - } - }, - ), - if (showError) ...[ - Text( - context.translate( - 'forgot_password.error.email_does_not_exist', - ), - style: Theme.of(context) - .textTheme - .bodyText2! - .copyWith( - color: Theme.of(context).errorColor, - ), - ), - ], - const Padding( - padding: EdgeInsets.only(bottom: 30), - ), - ], - ), - ), - ], - ), - ), - Container( - margin: const EdgeInsets.symmetric(horizontal: 30), - padding: const EdgeInsets.only(bottom: 40.0), - child: context - .login() - .config - .appTheme - .buttons - .primaryButton( - context: context, - child: Text( - context.translate('forgot_password.button.submit'), - style: Theme.of(context).textTheme.button, - ), - onPressed: () async { - if (email != null) { - setState(() { - showError = false; - }); - - var result = await context - .loginRepository() - .forgotPassword(email!); - - if (result) { - await context.login().dialogs.showDialog( - context: context, - builder: (ctx) => - AppShellAlertDialog.singleButtonIcon( - title: - 'forgot_password.dialog.text.title', - body: context.translate( - 'forgot_password.dialog.text.body', - arguments: [email!], - ), - icon: Icon( - context - .login() - .config - .appTheme - .icons - .forgotPasswordMail, - size: 70, - ), - buttonText: - 'forgot_password.dialog.text.button', - onPressed: () { - Navigator.of(ctx).pop(); - widget.onComplete.call(); - }, - ), - ); - } else { - setState(() { - showError = true; - }); - } - } - }, - ), - ), - ], - ), - ), - ), - ); - } -} diff --git a/lib/plugins/login/login_email_password.dart b/lib/plugins/login/login_email_password.dart index a778826..b9561e7 100644 --- a/lib/plugins/login/login_email_password.dart +++ b/lib/plugins/login/login_email_password.dart @@ -217,12 +217,13 @@ class EmailLoginState extends LoginState { style: Theme.of(context).textTheme.bodyText2, ), onPressed: widget.onPressedForgotPassword ?? - () { - navigateFadeTo( - context, - (ctx) => ForgotPassword(), - ); - }, + () => Navigator.push( + context, + MaterialPageRoute( + builder: (context) => + const ForgotPassword(), + ), + ), ), ), if (context.login().config.loginOptions.autoLoginMode != diff --git a/lib/plugins/login/login_registration_buttons.dart b/lib/plugins/login/login_registration_buttons.dart index 207371f..4278b4d 100644 --- a/lib/plugins/login/login_registration_buttons.dart +++ b/lib/plugins/login/login_registration_buttons.dart @@ -117,9 +117,10 @@ class LoginRegistrationButtons extends StatelessWidget navigateFadeTo( context, (ctx) => LoginPhoneNumber( - title: phoneText, - navRegistration: navRegistration, - navAfterLogin: navAfterLogin), + title: phoneText, + navRegistration: navRegistration, + navAfterLogin: navAfterLogin, + ), ); }, ),