-
Notifications
You must be signed in to change notification settings - Fork 2
/
signUpScreen.dart
392 lines (372 loc) · 14.5 KB
/
signUpScreen.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:rescue_code/profilePage.dart';
import 'package:rescue_code/style/theme.dart' as Theme;
import 'package:shared_preferences/shared_preferences.dart';
class SignUpPage extends StatefulWidget {
SignUpPage({Key key}) : super(key: key);
@override
_SignUpPageState createState() => new _SignUpPageState();
}
class _SignUpPageState extends State<SignUpPage>
with SingleTickerProviderStateMixin {
// Scaffold Keys
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
// FocusNodes
final FocusNode myFocusNodeEmailLogin = FocusNode();
final FocusNode myFocusNodePasswordLogin = FocusNode();
final FocusNode myFocusNodePassword = FocusNode();
final FocusNode myFocusNodeEmail = FocusNode();
final FocusNode myFocusNodeName = FocusNode();
bool _obscureTextSignup = true;
// TextFields Controllers
TextEditingController signupEmailController = new TextEditingController();
TextEditingController signupNameController = new TextEditingController();
TextEditingController signupPasswordController = new TextEditingController();
TextEditingController signupConfirmPasswordController =
new TextEditingController();
// Page Controller
PageController _pageController;
Color left = Colors.black;
Color right = Colors.white;
// Firebase Instances
var databaseInstance = Firestore.instance;
var authInstance = FirebaseAuth.instance;
createUser() async {
SharedPreferences _prefs = await SharedPreferences.getInstance();
await authInstance
.createUserWithEmailAndPassword(
email: signupEmailController.text,
password: signupPasswordController.text,
)
.then((currentUser) async {
var allUsers = await databaseInstance.collection('users').getDocuments();
var newID = allUsers.documents.length + 1;
databaseInstance
.collection("users")
.document(currentUser.user.uid)
.setData({
"token": currentUser.user.uid,
"id": newID.toString(),
"type": "user",
"name": signupNameController.text,
"email": signupEmailController.text
});
// Save USER ID from Firebase in SharedPreferences
await _prefs.setString("uid", currentUser.user.uid);
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => ProfilePage(uid: currentUser.user.uid)));
});
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: Text(
"Sign Up",
style: TextStyle(
fontFamily: "customFont",
fontSize: 30,
fontWeight: FontWeight.w900),
),
centerTitle: true,
backgroundColor: Colors.pinkAccent.shade200,
),
key: _scaffoldKey,
body: NotificationListener<OverscrollIndicatorNotification>(
onNotification: (overscroll) {
overscroll.disallowGlow();
return null;
},
child: SingleChildScrollView(
child: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height >= 775.0
? MediaQuery.of(context).size.height
: 775.0,
decoration: new BoxDecoration(
gradient: new LinearGradient(
colors: [
Theme.Colors.loginGradientStart,
Theme.Colors.loginGradientEnd
],
begin: const FractionalOffset(0.0, 0.0),
end: const FractionalOffset(1.0, 1.0),
stops: [0.0, 1.0],
tileMode: TileMode.clamp),
),
child: Column(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 75.0),
child: new Image(
width: 250.0,
height: 191.0,
fit: BoxFit.fill,
image: new AssetImage('assets/login_logo.png')),
),
Expanded(
flex: 2,
child: ConstrainedBox(
constraints: const BoxConstraints.expand(),
child: _buildSignUp(context),
),
),
],
),
),
),
),
);
}
@override
void dispose() {
myFocusNodePassword.dispose();
myFocusNodeEmail.dispose();
myFocusNodeName.dispose();
_pageController?.dispose();
super.dispose();
}
@override
void initState() {
super.initState();
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
_pageController = PageController();
}
void showInSnackBar(String value) {
FocusScope.of(context).requestFocus(new FocusNode());
_scaffoldKey.currentState?.removeCurrentSnackBar();
_scaffoldKey.currentState.showSnackBar(new SnackBar(
content: new Text(
value,
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 16.0,
fontFamily: "WorkSansSemiBold"),
),
backgroundColor: Colors.blue,
duration: Duration(seconds: 3),
));
}
Widget _buildSignUp(BuildContext context) {
return Container(
padding: EdgeInsets.only(top: 23.0),
child: Column(
children: <Widget>[
Stack(
alignment: Alignment.topCenter,
overflow: Overflow.visible,
children: <Widget>[
Card(
elevation: 2.0,
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
child: Container(
width: 370.0,
height: 260.0,
child: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.only(
top: 20.0, bottom: 20.0, left: 25.0, right: 25.0),
child: TextField(
focusNode: myFocusNodeName,
controller: signupNameController,
keyboardType: TextInputType.text,
textCapitalization: TextCapitalization.words,
style: TextStyle(
fontFamily: "WorkSansSemiBold",
fontSize: 16.0,
color: Colors.black),
decoration: InputDecoration(
border: InputBorder.none,
icon: Icon(
FontAwesomeIcons.user,
color: Colors.black,
),
hintText: "Name",
hintStyle: TextStyle(
fontFamily: "WorkSansSemiBold", fontSize: 16.0),
),
),
),
Container(
width: 250.0,
height: 1.0,
color: Colors.grey[400],
),
Padding(
padding: EdgeInsets.only(
top: 20.0, bottom: 20.0, left: 25.0, right: 25.0),
child: TextField(
focusNode: myFocusNodeEmail,
controller: signupEmailController,
keyboardType: TextInputType.emailAddress,
style: TextStyle(
fontFamily: "WorkSansSemiBold",
fontSize: 16.0,
color: Colors.black),
decoration: InputDecoration(
border: InputBorder.none,
icon: Icon(
FontAwesomeIcons.envelope,
color: Colors.black,
),
hintText: "Email Address",
hintStyle: TextStyle(
fontFamily: "WorkSansSemiBold", fontSize: 16.0),
),
),
),
Container(
width: 250.0,
height: 1.0,
color: Colors.grey[400],
),
Padding(
padding: EdgeInsets.only(
top: 20.0, bottom: 20.0, left: 25.0, right: 25.0),
child: TextField(
focusNode: myFocusNodePassword,
controller: signupPasswordController,
obscureText: _obscureTextSignup,
style: TextStyle(
fontFamily: "WorkSansSemiBold",
fontSize: 16.0,
color: Colors.black),
decoration: InputDecoration(
border: InputBorder.none,
icon: Icon(
FontAwesomeIcons.lock,
color: Colors.black,
),
hintText: "Password",
hintStyle: TextStyle(
fontFamily: "WorkSansSemiBold", fontSize: 16.0),
suffixIcon: GestureDetector(
onTap: _toggleSignup,
child: Icon(
_obscureTextSignup
? FontAwesomeIcons.eye
: FontAwesomeIcons.eyeSlash,
size: 15.0,
color: Colors.black,
),
),
),
),
),
Container(
width: 250.0,
height: 1.0,
color: Colors.grey[400],
),
],
),
),
),
Container(
margin: EdgeInsets.only(top: 300.0),
decoration: new BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(5.0)),
boxShadow: <BoxShadow>[
BoxShadow(
color: Theme.Colors.loginGradientStart,
offset: Offset(1.0, 6.0),
blurRadius: 20.0,
),
BoxShadow(
color: Theme.Colors.loginGradientEnd,
offset: Offset(1.0, 6.0),
blurRadius: 20.0,
),
],
gradient: new LinearGradient(
colors: [
Theme.Colors.loginGradientEnd,
Theme.Colors.loginGradientStart
],
begin: const FractionalOffset(0.2, 0.2),
end: const FractionalOffset(1.0, 1.0),
stops: [0.0, 1.0],
tileMode: TileMode.clamp),
),
child: MaterialButton(
highlightColor: Colors.transparent,
splashColor: Theme.Colors.loginGradientEnd,
//shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(5.0))),
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 10.0, horizontal: 42.0),
child: Text(
"SIGN UP",
style: TextStyle(
color: Colors.white,
fontSize: 25.0,
fontFamily: "WorkSansBold"),
),
),
onPressed: () {
_scaffoldKey.currentState.showSnackBar(new SnackBar(
duration: new Duration(seconds: 8),
content: new Row(
children: <Widget>[
new CircularProgressIndicator(),
new Text(
" Signing-Up...",
style: TextStyle(color: Colors.white),
)
],
),
));
createUser().whenComplete(() {
_scaffoldKey.currentState.showSnackBar(new SnackBar(
backgroundColor: Colors.red,
duration: new Duration(seconds: 3),
content: new Row(
children: <Widget>[
new Icon(
Icons.error,
size: 40,
),
Container(
width: MediaQuery.of(context).size.width -
MediaQuery.of(context).size.width / 3,
child: new Text(
"Erorr check your input or the internet connection and try again!",
style: TextStyle(
color: Colors.white, fontSize: 16),
overflow: TextOverflow.ellipsis,
maxLines: 20,
),
)
],
),
));
});
}),
),
],
),
],
),
);
}
void _toggleSignup() {
setState(() {
_obscureTextSignup = !_obscureTextSignup;
});
}
}