Commit 97c87d3f authored by Budi Prasetyo's avatar Budi Prasetyo

reset password with firebase

parent 30a7d9c2
import 'dart:convert';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:form_field_validator/form_field_validator.dart';
import 'package:http/http.dart' as http;
import 'package:medapp_eksad/firebase/showSnackbar.dart';
import 'package:medapp_eksad/widget/button_color.dart';
class ForgotPassword extends StatefulWidget {
......@@ -13,12 +16,15 @@ class ForgotPassword extends StatefulWidget {
class _ForgotPasswordState extends State<ForgotPassword> {
final formKey = GlobalKey<FormState>();
final _formKey = GlobalKey<FormState>();
String email = '';
final nameController = TextEditingController();
final phoneController = TextEditingController();
final emailController = TextEditingController();
final messageController = TextEditingController();
@override
void dispose() {
emailController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Stack(
......@@ -39,12 +45,18 @@ class _ForgotPasswordState extends State<ForgotPassword> {
),
Center(
child: AlertDialog(
title: Text('Find your account'),
title: Text('Receive an email \nto reset your password.',textAlign: TextAlign.center,),
content: Form(
key: formKey,
child: TextFormField(
textAlign: TextAlign.start,
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(
labelText: "Enter your email address",
hintStyle: const TextStyle(),
......@@ -57,41 +69,31 @@ class _ForgotPasswordState extends State<ForgotPassword> {
actions: <Widget>[
TextButton(
onPressed: () {
Navigator.pushNamed(context, 'dashboard');
resetPassword();
//Navigator.pushNamed(context, 'dashboard');
},
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(
......
......@@ -97,7 +97,7 @@ class FirebaseAuthMethods {
Future<void> sendEmailVerification(BuildContext context) async {
try {
_auth.currentUser!.sendEmailVerification();
showSnackBar(context, 'Email verification sent!');
showSnackBar(context, 'Email verification sent! , Check your Inbox or Spam Email');
} on FirebaseAuthException catch (e) {
showSnackBar(context, e.message!); // Display error message
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment