-
Notifications
You must be signed in to change notification settings - Fork 1
/
forgot_password.dart
170 lines (163 loc) · 6.57 KB
/
forgot_password.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import 'signup.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
class ForgotPassword extends StatefulWidget {
const ForgotPassword({super.key});
@override
State<ForgotPassword> createState() => _ForgotPasswordState();
}
class _ForgotPasswordState extends State<ForgotPassword> {
String email = "";
TextEditingController mailcontroller = new TextEditingController();
final _formkey = GlobalKey<FormState>();
resetPassword() async {
try {
await FirebaseAuth.instance.sendPasswordResetEmail(email: email);
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
"Password Reset Email has been sent !",
style: TextStyle(fontSize: 20.0),
)));
} on FirebaseAuthException catch (e) {
if (e.code == "user-not-found") {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
"No user found for that email.",
style: TextStyle(fontSize: 20.0),
)));
}
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xff9ea2a2), body: Container(
child: Column(
children: [
SizedBox(
height: 70.0,
),
Container(
alignment: Alignment.topCenter,
child: Text(
"Password Recovery",
style: TextStyle(
color: Colors.white,
fontSize: 30.0,
fontWeight: FontWeight.bold),
),
),
SizedBox(
height: 10.0,
),
Text(
"Enter your mail",
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
fontWeight: FontWeight.bold),
),
Expanded(
child: Form(
key: _formkey,
child: Padding(
padding: EdgeInsets.only(left: 10.0),
child: ListView(
children: [
Container(
padding: EdgeInsets.only(left: 10.0),
decoration: BoxDecoration(
border:
Border.all(color: Colors.white70, width: 2.0),
borderRadius: BorderRadius.circular(30),
),
child: TextFormField(
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please Enter Email';
}
return null;
},
controller: mailcontroller,
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
hintText: "Email",
hintStyle: TextStyle(
fontSize: 18.0, color: Colors.white),
prefixIcon: Icon(
Icons.person,
color: Colors.white70,
size: 30.0,
),
border: InputBorder.none),
),
),
SizedBox(
height: 40.0,
),
GestureDetector(
onTap: () {
if(_formkey.currentState!.validate()){
setState(() {
email=mailcontroller.text;
});
resetPassword();
}
},
child: Container(
width: 140,
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10)),
child: Center(
child: Text(
"Send Email",
style: TextStyle(
color: Colors.black,
fontSize: 18.0,
fontWeight: FontWeight.bold),
),
),
),
),
SizedBox(
height: 50.0,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Don't have an account?",
style: TextStyle(
fontSize: 18.0, color: Colors.white),
),
SizedBox(
width: 5.0,
),
GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SignUp()));
},
child: Text(
"Create",
style: TextStyle(
color: const Color(0xffabc4aa),
fontSize: 20.0,
fontWeight: FontWeight.w500),
),
)
],
)
],
),
))),
],
),
),
);
}
}