Skip to content

Commit ca305df

Browse files
committed
forgot password page added
1 parent 9e8eea8 commit ca305df

File tree

4 files changed

+245
-50
lines changed

4 files changed

+245
-50
lines changed

lib/NetworkHandler.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,21 @@ class NetworkHandler {
4141
return response;
4242
}
4343

44+
Future<http.Response> patch(String url, Map<String, String> body) async {
45+
String token = await storage.read(key: "token");
46+
url = formater(url);
47+
log.d(body);
48+
var response = await http.patch(
49+
url,
50+
headers: {
51+
"Content-type": "application/json",
52+
"Authorization": "Bearer $token"
53+
},
54+
body: json.encode(body),
55+
);
56+
return response;
57+
}
58+
4459
Future<http.Response> post1(String url, var body) async {
4560
String token = await storage.read(key: "token");
4661
url = formater(url);

lib/Pages/ForgetPassword.dart

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
import 'dart:convert';
2+
3+
import 'package:blogapp/Pages/HomePage.dart';
4+
import 'package:blogapp/Pages/SignUpPage.dart';
5+
import 'package:blogapp/Pages/WelcomePage.dart';
6+
import "package:flutter/material.dart";
7+
8+
import '../NetworkHandler.dart';
9+
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
10+
11+
class ForgotPasswordPage extends StatefulWidget {
12+
ForgotPasswordPage({Key key}) : super(key: key);
13+
14+
@override
15+
_ForgotPasswordPageState createState() => _ForgotPasswordPageState();
16+
}
17+
18+
class _ForgotPasswordPageState extends State<ForgotPasswordPage> {
19+
bool vis = true;
20+
final _globalkey = GlobalKey<FormState>();
21+
NetworkHandler networkHandler = NetworkHandler();
22+
TextEditingController _usernameController = TextEditingController();
23+
TextEditingController _passwordController = TextEditingController();
24+
String errorText;
25+
bool validate = false;
26+
bool circular = false;
27+
final storage = new FlutterSecureStorage();
28+
@override
29+
Widget build(BuildContext context) {
30+
return Scaffold(
31+
body: Container(
32+
// height: MediaQuery.of(context).size.height,
33+
// width: MediaQuery.of(context).size.width,
34+
decoration: BoxDecoration(
35+
gradient: LinearGradient(
36+
colors: [Colors.white, Colors.green[200]],
37+
begin: const FractionalOffset(0.0, 1.0),
38+
end: const FractionalOffset(0.0, 1.0),
39+
stops: [0.0, 1.0],
40+
tileMode: TileMode.repeated,
41+
),
42+
),
43+
child: Form(
44+
key: _globalkey,
45+
child: Padding(
46+
padding: const EdgeInsets.symmetric(horizontal: 40, vertical: 10.0),
47+
child: Column(
48+
mainAxisAlignment: MainAxisAlignment.center,
49+
children: [
50+
Text(
51+
"Forgot Password",
52+
style: TextStyle(
53+
fontSize: 30,
54+
fontWeight: FontWeight.bold,
55+
letterSpacing: 2,
56+
),
57+
),
58+
SizedBox(
59+
height: 20,
60+
),
61+
usernameTextField(),
62+
SizedBox(
63+
height: 15,
64+
),
65+
passwordTextField(),
66+
SizedBox(
67+
height: 20,
68+
),
69+
70+
SizedBox(
71+
height: 30,
72+
),
73+
InkWell(
74+
onTap: () async {
75+
Map<String, String> data = {
76+
"password": _passwordController.text
77+
};
78+
print("/user/update/${_usernameController.text}");
79+
var response = await networkHandler.patch(
80+
"/user/update/${_usernameController.text}", data);
81+
82+
if (response.statusCode == 200 ||
83+
response.statusCode == 201) {
84+
print("/user/update/${_usernameController.text}");
85+
Navigator.pushAndRemoveUntil(
86+
context,
87+
MaterialPageRoute(
88+
builder: (context) => WelcomePage()),
89+
(route) => false);
90+
}
91+
92+
// login logic End here
93+
},
94+
child: Container(
95+
width: 150,
96+
height: 50,
97+
decoration: BoxDecoration(
98+
borderRadius: BorderRadius.circular(10),
99+
color: Color(0xff00A86B),
100+
),
101+
child: Center(
102+
child: circular
103+
? CircularProgressIndicator()
104+
: Text(
105+
"Update Password",
106+
style: TextStyle(
107+
color: Colors.white,
108+
fontSize: 15,
109+
fontWeight: FontWeight.bold,
110+
),
111+
),
112+
),
113+
),
114+
),
115+
// Divider(
116+
// height: 50,
117+
// thickness: 1.5,
118+
// ),
119+
],
120+
),
121+
),
122+
),
123+
),
124+
);
125+
}
126+
127+
Widget usernameTextField() {
128+
return Column(
129+
children: [
130+
Text("Username"),
131+
TextFormField(
132+
controller: _usernameController,
133+
decoration: InputDecoration(
134+
errorText: validate ? null : errorText,
135+
focusedBorder: UnderlineInputBorder(
136+
borderSide: BorderSide(
137+
color: Colors.black,
138+
width: 2,
139+
),
140+
),
141+
),
142+
)
143+
],
144+
);
145+
}
146+
147+
Widget passwordTextField() {
148+
return Column(
149+
children: [
150+
Text("Password"),
151+
TextFormField(
152+
controller: _passwordController,
153+
obscureText: vis,
154+
decoration: InputDecoration(
155+
errorText: validate ? null : errorText,
156+
suffixIcon: IconButton(
157+
icon: Icon(vis ? Icons.visibility_off : Icons.visibility),
158+
onPressed: () {
159+
setState(() {
160+
vis = !vis;
161+
});
162+
},
163+
),
164+
helperStyle: TextStyle(
165+
fontSize: 14,
166+
),
167+
focusedBorder: UnderlineInputBorder(
168+
borderSide: BorderSide(
169+
color: Colors.black,
170+
width: 2,
171+
),
172+
),
173+
),
174+
)
175+
],
176+
);
177+
}
178+
}

lib/Pages/SinInPage.dart

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'dart:convert';
22

3+
import 'package:blogapp/Pages/ForgetPassword.dart';
34
import 'package:blogapp/Pages/HomePage.dart';
45
import 'package:blogapp/Pages/SignUpPage.dart';
56
import "package:flutter/material.dart";
@@ -68,12 +69,20 @@ class _SignInPageState extends State<SignInPage> {
6869
Row(
6970
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
7071
children: [
71-
Text(
72-
"Forgot Password ?",
73-
style: TextStyle(
74-
color: Colors.blue,
75-
fontSize: 15,
76-
fontWeight: FontWeight.bold,
72+
InkWell(
73+
onTap: () {
74+
Navigator.push(
75+
context,
76+
MaterialPageRoute(
77+
builder: (context) => ForgotPasswordPage()));
78+
},
79+
child: Text(
80+
"Forgot Password ?",
81+
style: TextStyle(
82+
color: Colors.blue,
83+
fontSize: 15,
84+
fontWeight: FontWeight.bold,
85+
),
7786
),
7887
),
7988
SizedBox(width: 20),

0 commit comments

Comments
 (0)