1
+ import 'dart:convert' ;
2
+
1
3
import 'package:blogapp/Pages/SignUpPage.dart' ;
2
4
import "package:flutter/material.dart" ;
3
5
@@ -15,7 +17,6 @@ class _SignInPageState extends State<SignInPage> {
15
17
final _globalkey = GlobalKey <FormState >();
16
18
NetworkHandler networkHandler = NetworkHandler ();
17
19
TextEditingController _usernameController = TextEditingController ();
18
- TextEditingController _emailController = TextEditingController ();
19
20
TextEditingController _passwordController = TextEditingController ();
20
21
String errorText;
21
22
bool validate = false ;
@@ -95,27 +96,54 @@ class _SignInPageState extends State<SignInPage> {
95
96
height: 30 ,
96
97
),
97
98
InkWell (
98
- onTap: () async {},
99
- child: circular
100
- ? CircularProgressIndicator ()
101
- : Container (
102
- width: 150 ,
103
- height: 50 ,
104
- decoration: BoxDecoration (
105
- borderRadius: BorderRadius .circular (10 ),
106
- color: Color (0xff00A86B ),
107
- ),
108
- child: Center (
109
- child: Text (
99
+ onTap: () async {
100
+ setState (() {
101
+ circular = true ;
102
+ });
103
+ Map <String , String > data = {
104
+ "username" : _usernameController.text,
105
+ "password" : _passwordController.text,
106
+ };
107
+ var response =
108
+ await networkHandler.post ("/user/login" , data);
109
+
110
+ if (response.statusCode == 200 ||
111
+ response.statusCode == 201 ) {
112
+ Map <String , dynamic > output = json.decode (response.body);
113
+ print (output["token" ]);
114
+ setState (() {
115
+ validate = true ;
116
+ circular = false ;
117
+ });
118
+ } else {
119
+ String output = json.decode (response.body);
120
+ setState (() {
121
+ validate = false ;
122
+ errorText = output;
123
+ circular = false ;
124
+ });
125
+ }
126
+ },
127
+ child: Container (
128
+ width: 150 ,
129
+ height: 50 ,
130
+ decoration: BoxDecoration (
131
+ borderRadius: BorderRadius .circular (10 ),
132
+ color: Color (0xff00A86B ),
133
+ ),
134
+ child: Center (
135
+ child: circular
136
+ ? CircularProgressIndicator ()
137
+ : Text (
110
138
"Sign In" ,
111
139
style: TextStyle (
112
140
color: Colors .white,
113
141
fontSize: 18 ,
114
142
fontWeight: FontWeight .bold,
115
143
),
116
144
),
117
- ),
118
- ),
145
+ ),
146
+ ),
119
147
),
120
148
// Divider(
121
149
// height: 50,
@@ -155,13 +183,9 @@ class _SignInPageState extends State<SignInPage> {
155
183
Text ("Password" ),
156
184
TextFormField (
157
185
controller: _passwordController,
158
- validator: (value) {
159
- if (value.isEmpty) return "Password can't be empty" ;
160
- if (value.length < 8 ) return "Password lenght must have >=8" ;
161
- return null ;
162
- },
163
186
obscureText: vis,
164
187
decoration: InputDecoration (
188
+ errorText: validate ? null : errorText,
165
189
suffixIcon: IconButton (
166
190
icon: Icon (vis ? Icons .visibility_off : Icons .visibility),
167
191
onPressed: () {
0 commit comments