Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
medapp_eksad
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
qorri_di
medapp_eksad
Commits
97c87d3f
Commit
97c87d3f
authored
Sep 20, 2022
by
Budi Prasetyo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reset password with firebase
parent
30a7d9c2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
32 deletions
+34
-32
forget_password.dart
lib/auth/forget_password.dart
+33
-31
firebase_auth_methods.dart
lib/firebase/firebase_auth_methods.dart
+1
-1
No files found.
lib/auth/forget_password.dart
View file @
97c87d3f
import
'dart:convert'
;
import
'dart:convert'
;
import
'package:firebase_auth/firebase_auth.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:form_field_validator/form_field_validator.dart'
;
import
'package:http/http.dart'
as
http
;
import
'package:http/http.dart'
as
http
;
import
'package:medapp_eksad/firebase/showSnackbar.dart'
;
import
'package:medapp_eksad/widget/button_color.dart'
;
import
'package:medapp_eksad/widget/button_color.dart'
;
class
ForgotPassword
extends
StatefulWidget
{
class
ForgotPassword
extends
StatefulWidget
{
...
@@ -13,12 +16,15 @@ class ForgotPassword extends StatefulWidget {
...
@@ -13,12 +16,15 @@ class ForgotPassword extends StatefulWidget {
class
_ForgotPasswordState
extends
State
<
ForgotPassword
>
{
class
_ForgotPasswordState
extends
State
<
ForgotPassword
>
{
final
formKey
=
GlobalKey
<
FormState
>();
final
formKey
=
GlobalKey
<
FormState
>();
final
_formKey
=
GlobalKey
<
FormState
>();
String
email
=
''
;
String
email
=
''
;
final
nameController
=
TextEditingController
();
final
phoneController
=
TextEditingController
();
final
emailController
=
TextEditingController
();
final
emailController
=
TextEditingController
();
final
messageController
=
TextEditingController
();
@override
void
dispose
()
{
emailController
.
dispose
();
super
.
dispose
();
}
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
return
Stack
(
return
Stack
(
...
@@ -39,12 +45,18 @@ class _ForgotPasswordState extends State<ForgotPassword> {
...
@@ -39,12 +45,18 @@ class _ForgotPasswordState extends State<ForgotPassword> {
),
),
Center
(
Center
(
child:
AlertDialog
(
child:
AlertDialog
(
title:
Text
(
'
Find your account'
),
title:
Text
(
'
Receive an email
\n
to reset your password.'
,
textAlign:
TextAlign
.
center
,
),
content:
Form
(
content:
Form
(
key:
formKey
,
key:
formKey
,
child:
TextFormField
(
child:
TextFormField
(
textAlign:
TextAlign
.
start
,
textAlign:
TextAlign
.
start
,
controller:
emailController
,
controller:
emailController
,
textInputAction:
TextInputAction
.
done
,
autovalidateMode:
AutovalidateMode
.
onUserInteraction
,
validator:
(
email
)
=>
email
!=
null
&&
EmailValidator
(
errorText:
'Enter a valid email'
).
isValid
(
email
)
?
"Enter a valid email"
:
null
,
decoration:
InputDecoration
(
decoration:
InputDecoration
(
labelText:
"Enter your email address"
,
labelText:
"Enter your email address"
,
hintStyle:
const
TextStyle
(),
hintStyle:
const
TextStyle
(),
...
@@ -57,41 +69,31 @@ class _ForgotPasswordState extends State<ForgotPassword> {
...
@@ -57,41 +69,31 @@ class _ForgotPasswordState extends State<ForgotPassword> {
actions:
<
Widget
>[
actions:
<
Widget
>[
TextButton
(
TextButton
(
onPressed:
()
{
onPressed:
()
{
Navigator
.
pushNamed
(
context
,
'dashboard'
);
resetPassword
();
//Navigator.pushNamed(context, 'dashboard');
},
},
child:
const
Text
(
'Send'
),
child:
const
Text
(
'Send'
),
// onPressed: () async {
// if (_formKey.currentState!.validate()) {
// final response = await SendEmail(
// nameController.value.text,
// phoneController.value.text,
// emailController.value.text,
// messageController.value.text);
// ScaffoldMessenger.of(context).showSnackBar(
// response == 200
// ? const SnackBar(
// content: Text('Message Sent!'),
// backgroundColor: Colors.green)
// : const SnackBar(
// content: Text('Failed to send message!'),
// backgroundColor: Colors.red),
// );
// nameController.clear();
// phoneController.clear();
// emailController.clear();
// messageController.clear();
// }
// },
// child: const Text('Send'),
),
),
],
],
)),
)),
],
],
);
);
}
}
Future
resetPassword
()
async
{
showDialog
(
context:
context
,
builder:
(
context
)=>
Center
(
child:
CircularProgressIndicator
(),));
try
{
await
FirebaseAuth
.
instance
.
sendPasswordResetEmail
(
email:
emailController
.
text
.
trim
());
showSnackBar
(
context
,
'Reset Password Sent, Check your email inbox or spam'
);
Navigator
.
of
(
context
).
popUntil
((
route
)
=>
route
.
isActive
);
}
on
FirebaseAuthException
catch
(
e
){
print
(
e
);
showSnackBar
(
context
,
e
.
message
.
toString
());
Navigator
.
of
(
context
).
pop
();
}
}
}
}
// Future SendEmail(
// Future SendEmail(
...
...
lib/firebase/firebase_auth_methods.dart
View file @
97c87d3f
...
@@ -97,7 +97,7 @@ class FirebaseAuthMethods {
...
@@ -97,7 +97,7 @@ class FirebaseAuthMethods {
Future
<
void
>
sendEmailVerification
(
BuildContext
context
)
async
{
Future
<
void
>
sendEmailVerification
(
BuildContext
context
)
async
{
try
{
try
{
_auth
.
currentUser
!.
sendEmailVerification
();
_auth
.
currentUser
!.
sendEmailVerification
();
showSnackBar
(
context
,
'Email verification sent!'
);
showSnackBar
(
context
,
'Email verification sent!
, Check your Inbox or Spam Email
'
);
}
on
FirebaseAuthException
catch
(
e
)
{
}
on
FirebaseAuthException
catch
(
e
)
{
showSnackBar
(
context
,
e
.
message
!);
// Display error message
showSnackBar
(
context
,
e
.
message
!);
// Display error message
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment