-
Notifications
You must be signed in to change notification settings - Fork 0
/
SignupPage.dart
132 lines (128 loc) · 5.36 KB
/
SignupPage.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
import 'package:flutter/material.dart';
import 'package:flutter_signin_button/flutter_signin_button.dart';
import 'package:tiger_tracker_v2/loading_animation.dart';
import 'package:tiger_tracker_v2/size_config.dart';
import 'package:tiger_tracker_v2/auth.dart';
class SignupPage extends StatefulWidget {
@override
State<StatefulWidget> createState() => _SignupPage();
}
class _SignupPage extends State<SignupPage> {
//final FirebaseAuth _auth = FirebaseAuth.instance;
final AuthService _auth = AuthService();
final _formKey =
new GlobalKey<FormState>(); //performs validation & creates a form
bool loading = false;
String _email = '';
String _password = '';
String error = '';
@override
Widget build(BuildContext context) {
return Scaffold(
extendBodyBehindAppBar: true,
appBar: AppBar(
title: Text("Sign Up"),
backgroundColor: Colors.transparent,
elevation: 0),
body: Container(
padding: EdgeInsets.fromLTRB(16, 0, 16, 0),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
stops: [0.2, 1],
colors: [Colors.red, Colors.white],
)),
child: ListView(
children: <Widget>[
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
),
Image.asset(
'stemlogo.png',
alignment: Alignment.topCenter,
height: SizeConfig.blockSizeVertical * 45,
),
new Form(
key: _formKey,
child: new Column(children: <Widget>[
Padding(padding: EdgeInsets.only(bottom: 10)),
TextFormField(
decoration: new InputDecoration(labelText: 'Email'),
onChanged: (val) {
setState(() => _email = val);
},
validator: (val) =>
val.isEmpty ? 'Email can\'t be empty' : null,
onSaved: (val) => _email = val.trim(),
),
new TextFormField(
decoration: new InputDecoration(
labelText: 'Password',
),
onChanged: (val) {
setState(() => _password = val);
},
validator: (val) =>
val.isEmpty ? 'Password can\'t be empty' : null,
obscureText: true,
onSaved: (val) => _password = val.trim(),
),
loading
? Loading()
: new ButtonTheme(
minWidth: SizeConfig.blockSizeHorizontal * 75,
//padding: EdgeInsets.only(bottom: 10.0),
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
color: Colors.red,
onPressed: () async {
if (_formKey.currentState.validate()) {
setState(() {
loading = true;
});
dynamic result = await _auth
.registerWithEmailAndPassword(
_email, _password);
if (result == null) {
setState(() {
error = 'Unable to Register.';
loading = false;
});
}
}
},
child: new Text(
'Sign Up',
style: TextStyle(
fontSize: 18.0, color: Colors.white),
))),
])),
new Column(
children: <Widget>[
new Container(
padding: EdgeInsets.fromLTRB(0, 10, 0, 10),
child: Text('- OR -')),
new Container(
child: ButtonTheme(
minWidth: SizeConfig.blockSizeHorizontal * 75,
child: SignInButton(
Buttons.Google,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
onPressed: () => _auth.googleSignIn().whenComplete(
() => Navigator.pushNamed(context, '/Login')),
//darkMode: true,
//borderRadius: 10.0,
),
))
],
),
],
),
));
}
}