-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoginPage.dart
140 lines (135 loc) · 5.79 KB
/
LoginPage.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
import 'package:flutter/material.dart';
import 'package:tiger_tracker_v2/auth.dart';
import 'package:tiger_tracker_v2/loading_animation.dart';
import 'package:tiger_tracker_v2/size_config.dart';
import 'package:flutter_signin_button/flutter_signin_button.dart';
class LoginPage extends StatefulWidget {
@override
State<StatefulWidget> createState() => _LoginPageState();
}
// underscore makes state private (cannot be seen from main)
class _LoginPageState extends State<LoginPage> {
final _formKey = new GlobalKey<FormState>();
final AuthService _auth = AuthService();
String _email = '';
String _password = '';
String error = '';
bool loading = false;
@override
Widget build(BuildContext context) {
return Scaffold(
extendBodyBehindAppBar: true,
appBar: AppBar(
title: Text("Log In"),
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'),
validator: (val) =>
val.isEmpty ? 'Enter a valid email' : null,
onChanged: (val) {
setState(() => _email = val.trim());
},
//onSaved: (val) => _email = val.trim(),
),
new TextFormField(
decoration: new InputDecoration(
labelText: 'Password',
),
validator: (val) =>
val.isEmpty ? 'Password can\'t be empty' : null,
onChanged: (val) {
setState(() => _password = val.trim());
},
obscureText: true,
//onSaved: (val) => _password = val.trim(),
),
Text(
error,
style: TextStyle(fontSize: 13.0, color: Colors.black),
textAlign: TextAlign.center,
),
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
.signInWithEmailAndPassword(
_email, _password)
.whenComplete(() =>
Navigator.of(context)
.pushNamed('/MyTrackPage'));
if (result == null) {
setState(() {
error =
'The email or password is incorrect. Please try again.';
loading = false;
});
}
}
},
child: new Text(
'Login',
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.of(context).pushNamed('/MyTrackPage')),
//darkMode: true,
//borderRadius: 10.0,
),
))
],
),
],
),
));
}
}