-
Notifications
You must be signed in to change notification settings - Fork 1
/
signin.dart
173 lines (167 loc) · 6.67 KB
/
signin.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
171
172
173
import 'package:flutter/material.dart';
import 'package:quizbuilder/helper/functions.dart';
import 'package:quizbuilder/services/Auth.dart';
import 'package:quizbuilder/view/signup.dart';
import 'package:quizbuilder/widgets/widgets.dart';
import 'home.dart';
class SignIn extends StatefulWidget {
@override
_SignInState createState() => _SignInState();
}
bool _isLoading = false;
class _SignInState extends State<SignIn> {
final _formkey = GlobalKey<FormState>();
String email, password; // for validation
AuthService authService = new AuthService();
signIn() async {
if (_formkey.currentState.validate()) {
setState(() {
_isLoading = true;
});
await authService.signInEmailAndPass(email, password).then((val) {
if (val != null) {
setState(() {
_isLoading = false;
});
HelperFunctions.saveUserLoggedInDetails(isLoggedin: true);
Navigator.pushReplacement(
// off sending to the home screen after authentication
context,
MaterialPageRoute(builder: (context) => Home()));
//navigate the user to the home screen
}
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: appBar(context),
centerTitle: true,
backgroundColor: Colors.transparent,
elevation: 0.0,
brightness: Brightness.light,
),
body: _isLoading
? Container(
child: Center(
child: CircularProgressIndicator(),
))
: Form(
// is it is correct
key: _formkey,
child: Container(
padding: EdgeInsets.symmetric(horizontal: 40),
color: Colors.transparent,
child: SingleChildScrollView(
child: Column(
children: [
SizedBox(
height: 160,
),
TextFormField(
validator: (val) {
return val.isEmpty
? "Enter correct Email id"
: null;
},
decoration: InputDecoration(
hintText: "Email",
hintStyle: TextStyle(
color: Colors.black87,
fontWeight: FontWeight.bold),
border: OutlineInputBorder(
borderSide: BorderSide(color: Colors.black87),
borderRadius: BorderRadius.circular(16)),
prefixIcon: const Icon(
Icons.email,
color: Colors.red,
),
),
onChanged: (val) {
email = val;
}),
SizedBox(
height: 20,
),
TextFormField(
validator: (val) {
return val.isEmpty ? "Enter Password" : null;
},
decoration: InputDecoration(
hintText: "Password",
hintStyle: TextStyle(
color: Colors.red,
fontWeight: FontWeight.bold),
border: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.black87,
),
borderRadius: BorderRadius.circular(16)),
prefixIcon: const Icon(
Icons.security,
color: Colors.black87,
)),
onChanged: (val) {
email = val;
}),
SizedBox(
height: 100,
),
GestureDetector(
onTap: () {
signIn();
},
child: Container(
padding: EdgeInsets.symmetric(vertical: 10),
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(30),
),
height: 55,
alignment: Alignment.center,
width: MediaQuery.of(context).size.width - 48,
child: Text(
"Sign in",
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black87,
fontSize: 16),
),
),
),
SizedBox(
height: 30,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("Don't have an account?",
style: TextStyle(
fontSize: 15.5, color: Colors.black87)),
GestureDetector(
onTap: () {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) =>
SignUp()) //navigate between differrent pages // push replacement pushes the screen in front to which screen we are
);
},
child: Text(" Sign Up",
style: TextStyle(
fontSize: 16.5,
color: Colors.red,
decoration: TextDecoration.underline)))
],
),
SizedBox(
height: 20,
),
],
)),
),
));
}
}