mirror of
https://github.com/Iconica-Development/flutter_login_widget.git
synced 2025-05-19 13:43:44 +02:00
feat: showDialog in password reset view
This commit is contained in:
parent
f1c4416ad5
commit
05686dc21d
5 changed files with 182 additions and 372 deletions
|
@ -9,7 +9,6 @@ import 'plugins/login/choose_login.dart';
|
||||||
import 'widgets/custom_navigator.dart';
|
import 'widgets/custom_navigator.dart';
|
||||||
export '../plugins/form/form.dart';
|
export '../plugins/form/form.dart';
|
||||||
export '../plugins/login/email_password_form.dart';
|
export '../plugins/login/email_password_form.dart';
|
||||||
export '../plugins/login/forgot_password_form.dart';
|
|
||||||
export '../plugins/login/login_email_password.dart';
|
export '../plugins/login/login_email_password.dart';
|
||||||
export 'buttons.dart';
|
export 'buttons.dart';
|
||||||
export 'login_config.dart';
|
export 'login_config.dart';
|
||||||
|
|
|
@ -1,23 +1,52 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_login/flutter_login_view.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';
|
import '../form/inputs/validators/email_validator.dart';
|
||||||
|
|
||||||
class ForgotPassword extends StatefulWidget {
|
class ForgotPassword extends StatefulWidget {
|
||||||
|
const ForgotPassword({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_ForgotPasswordState createState() => _ForgotPasswordState();
|
ForgotPasswordState createState() => ForgotPasswordState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _ForgotPasswordState extends State<ForgotPassword>
|
class ForgotPasswordState extends State<ForgotPassword> {
|
||||||
with NavigateWidgetMixin {
|
|
||||||
String? email;
|
String? email;
|
||||||
bool showError = false;
|
bool showError = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) => Material(
|
Widget build(BuildContext context) {
|
||||||
|
void showAlert({
|
||||||
|
required String title,
|
||||||
|
required String text,
|
||||||
|
required String buttonTitle,
|
||||||
|
VoidCallback? buttonAction,
|
||||||
|
}) =>
|
||||||
|
showDialog<String>(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) => AlertDialog(
|
||||||
|
title: Text(title),
|
||||||
|
content: Text(text),
|
||||||
|
actions: <Widget>[
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
if (buttonAction != null) {
|
||||||
|
buttonAction();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: Text(buttonTitle),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
return Material(
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: Text(
|
||||||
|
context.translate('forgot_password.text.title'),
|
||||||
|
),
|
||||||
|
),
|
||||||
body: context.login().screens.getAppshellScreenWrapper(
|
body: context.login().screens.getAppshellScreenWrapper(
|
||||||
context,
|
context,
|
||||||
backgroundImg:
|
backgroundImg:
|
||||||
|
@ -42,28 +71,14 @@ class _ForgotPasswordState extends State<ForgotPassword>
|
||||||
context: context,
|
context: context,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Container(
|
|
||||||
alignment: Alignment.topCenter,
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
context
|
|
||||||
.translate('forgot_password.text.title'),
|
|
||||||
style: Theme.of(context).textTheme.headline6,
|
|
||||||
),
|
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.all(30.0),
|
padding: const EdgeInsets.all(30.0),
|
||||||
child: Text(
|
child: Text(
|
||||||
context
|
context.translate('forgot_password.text.body'),
|
||||||
.translate('forgot_password.text.body'),
|
style: Theme.of(context).textTheme.subtitle1,
|
||||||
style:
|
|
||||||
Theme.of(context).textTheme.subtitle1,
|
|
||||||
textAlign: TextAlign.left,
|
textAlign: TextAlign.left,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(left: 30, right: 30),
|
padding: const EdgeInsets.only(left: 30, right: 30),
|
||||||
child: Column(
|
child: Column(
|
||||||
|
@ -71,12 +86,7 @@ class _ForgotPasswordState extends State<ForgotPassword>
|
||||||
const Padding(
|
const Padding(
|
||||||
padding: EdgeInsets.only(bottom: 20),
|
padding: EdgeInsets.only(bottom: 20),
|
||||||
),
|
),
|
||||||
context
|
context.login().config.appTheme.inputs.textField(
|
||||||
.login()
|
|
||||||
.config
|
|
||||||
.appTheme
|
|
||||||
.inputs
|
|
||||||
.textField(
|
|
||||||
title: context.translate(
|
title: context.translate(
|
||||||
'forgot_password.input.email',
|
'forgot_password.input.email',
|
||||||
),
|
),
|
||||||
|
@ -91,7 +101,9 @@ class _ForgotPasswordState extends State<ForgotPassword>
|
||||||
setState(() {
|
setState(() {
|
||||||
showError = false;
|
showError = false;
|
||||||
});
|
});
|
||||||
if (valid) email = value;
|
if (valid) {
|
||||||
|
email = value;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
if (showError) ...[
|
if (showError) ...[
|
||||||
|
@ -127,8 +139,7 @@ class _ForgotPasswordState extends State<ForgotPassword>
|
||||||
.primaryButton(
|
.primaryButton(
|
||||||
context: context,
|
context: context,
|
||||||
child: Text(
|
child: Text(
|
||||||
context
|
context.translate('forgot_password.button.submit'),
|
||||||
.translate('forgot_password.button.submit'),
|
|
||||||
style: Theme.of(context).textTheme.button,
|
style: Theme.of(context).textTheme.button,
|
||||||
),
|
),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
|
@ -142,35 +153,20 @@ class _ForgotPasswordState extends State<ForgotPassword>
|
||||||
.forgotPassword(email!);
|
.forgotPassword(email!);
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
await context.login().dialogs.showDialog(
|
showAlert(
|
||||||
context: context,
|
title: context.translate(
|
||||||
builder: (ctx) => AppShellAlertDialog
|
|
||||||
.singleButtonIcon(
|
|
||||||
title:
|
|
||||||
'forgot_password.dialog.text.title',
|
'forgot_password.dialog.text.title',
|
||||||
body: context.translate(
|
),
|
||||||
|
text: context.translate(
|
||||||
'forgot_password.dialog.text.body',
|
'forgot_password.dialog.text.body',
|
||||||
arguments: [email!],
|
arguments: [email],
|
||||||
),
|
),
|
||||||
icon: Icon(
|
buttonTitle: context.translate(
|
||||||
context
|
|
||||||
.login()
|
|
||||||
.config
|
|
||||||
.appTheme
|
|
||||||
.icons
|
|
||||||
.forgotPasswordMail,
|
|
||||||
size: 70,
|
|
||||||
),
|
|
||||||
buttonText:
|
|
||||||
'forgot_password.dialog.text.button',
|
'forgot_password.dialog.text.button',
|
||||||
onPressed: () {
|
|
||||||
Navigator.of(ctx).pop();
|
|
||||||
context
|
|
||||||
.login()
|
|
||||||
.screens
|
|
||||||
.openLoginScreen(context);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
|
buttonAction: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
setState(() {
|
setState(() {
|
||||||
|
@ -187,3 +183,4 @@ class _ForgotPasswordState extends State<ForgotPassword>
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -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<ForgotPasswordForm>
|
|
||||||
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;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -217,12 +217,13 @@ class EmailLoginState extends LoginState<EmailPasswordLogin> {
|
||||||
style: Theme.of(context).textTheme.bodyText2,
|
style: Theme.of(context).textTheme.bodyText2,
|
||||||
),
|
),
|
||||||
onPressed: widget.onPressedForgotPassword ??
|
onPressed: widget.onPressedForgotPassword ??
|
||||||
() {
|
() => Navigator.push(
|
||||||
navigateFadeTo(
|
|
||||||
context,
|
context,
|
||||||
(ctx) => ForgotPassword(),
|
MaterialPageRoute(
|
||||||
);
|
builder: (context) =>
|
||||||
},
|
const ForgotPassword(),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (context.login().config.loginOptions.autoLoginMode !=
|
if (context.login().config.loginOptions.autoLoginMode !=
|
||||||
|
|
|
@ -119,7 +119,8 @@ class LoginRegistrationButtons extends StatelessWidget
|
||||||
(ctx) => LoginPhoneNumber(
|
(ctx) => LoginPhoneNumber(
|
||||||
title: phoneText,
|
title: phoneText,
|
||||||
navRegistration: navRegistration,
|
navRegistration: navRegistration,
|
||||||
navAfterLogin: navAfterLogin),
|
navAfterLogin: navAfterLogin,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in a new issue