Skip to content

Commit 0c7df18

Browse files
committed
Enable VS code format-on-save
1 parent 980581a commit 0c7df18

File tree

5 files changed

+86
-86
lines changed

5 files changed

+86
-86
lines changed

lib/auth.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,18 @@ abstract class BaseAuth {
1111
class Auth implements BaseAuth {
1212
final FirebaseAuth _firebaseAuth = FirebaseAuth.instance;
1313

14-
Future<String> signInWithEmailAndPassword(String email, String password) async {
15-
FirebaseUser user = await _firebaseAuth.signInWithEmailAndPassword(email: email, password: password);
14+
Future<String> signInWithEmailAndPassword(
15+
String email, String password) async {
16+
FirebaseUser user = await _firebaseAuth.signInWithEmailAndPassword(
17+
email: email, password: password);
18+
user.email;
1619
return user.uid;
1720
}
1821

19-
Future<String> createUserWithEmailAndPassword(String email, String password) async {
20-
FirebaseUser user = await _firebaseAuth.createUserWithEmailAndPassword(email: email, password: password);
22+
Future<String> createUserWithEmailAndPassword(
23+
String email, String password) async {
24+
FirebaseUser user = await _firebaseAuth.createUserWithEmailAndPassword(
25+
email: email, password: password);
2126
return user.uid;
2227
}
2328

@@ -29,4 +34,4 @@ class Auth implements BaseAuth {
2934
Future<void> signOut() async {
3035
return _firebaseAuth.signOut();
3136
}
32-
}
37+
}

lib/home_page.dart

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter/material.dart';
22
import 'auth.dart';
3+
34
class HomePage extends StatelessWidget {
45
HomePage({this.auth, this.onSignedOut});
56
final BaseAuth auth;
@@ -15,22 +16,20 @@ class HomePage extends StatelessWidget {
1516
}
1617

1718
@override
18-
Widget build(BuildContext context) {
19-
return new Scaffold(
19+
Widget build(BuildContext context) {
20+
return new Scaffold(
2021
appBar: new AppBar(
2122
title: new Text('Welcome'),
2223
actions: <Widget>[
2324
new FlatButton(
24-
child: new Text('Logout', style: new TextStyle(fontSize: 17.0, color: Colors.white)),
25-
onPressed: _signOut
26-
)
25+
child: new Text('Logout',
26+
style: new TextStyle(fontSize: 17.0, color: Colors.white)),
27+
onPressed: _signOut)
2728
],
2829
),
2930
body: new Container(
3031
child: new Center(
31-
child: new Text('Welcome', style: new TextStyle(fontSize: 32.0))
32-
),
33-
)
34-
);
35-
}
32+
child: new Text('Welcome', style: new TextStyle(fontSize: 32.0))),
33+
));
34+
}
3635
}

lib/login_page.dart

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
import 'package:flutter/material.dart';
2-
import 'package:firebase_auth/firebase_auth.dart';
32
import 'auth.dart';
43

54
class LoginPage extends StatefulWidget {
65
LoginPage({this.auth, this.onSignedIn});
76
final BaseAuth auth;
87
final VoidCallback onSignedIn;
9-
8+
109
@override
1110
State<StatefulWidget> createState() => new _LoginPageState();
1211
}
1312

1413
enum FormType {
1514
login,
16-
register
15+
register,
1716
}
1817

1918
class _LoginPageState extends State<LoginPage> {
20-
2119
final formKey = new GlobalKey<FormState>();
2220

2321
String _email;
@@ -35,17 +33,18 @@ class _LoginPageState extends State<LoginPage> {
3533

3634
void validateAndSubmit() async {
3735
if (validateAndSave()) {
38-
try {
36+
try {
3937
if (_formType == FormType.login) {
40-
String userId = await widget.auth.signInWithEmailAndPassword(_email, _password);
38+
String userId =
39+
await widget.auth.signInWithEmailAndPassword(_email, _password);
4140
print('Signed in: $userId');
4241
} else {
43-
String userId = await widget.auth.createUserWithEmailAndPassword(_email, _password);
42+
String userId = await widget.auth
43+
.createUserWithEmailAndPassword(_email, _password);
4444
print('Registered user: $userId');
4545
}
4646
widget.onSignedIn();
47-
}
48-
catch (e) {
47+
} catch (e) {
4948
print('Error: $e');
5049
}
5150
}
@@ -66,63 +65,64 @@ class _LoginPageState extends State<LoginPage> {
6665
}
6766

6867
@override
69-
Widget build(BuildContext context) {
70-
return new Scaffold(
68+
Widget build(BuildContext context) {
69+
return new Scaffold(
7170
appBar: new AppBar(
7271
title: new Text('Flutter login demo'),
7372
),
7473
body: new Container(
75-
padding: EdgeInsets.all(16.0),
76-
child: new Form(
77-
key: formKey,
78-
child: new Column(
79-
crossAxisAlignment: CrossAxisAlignment.stretch,
80-
children: buildInputs() + buildSubmitButtons(),
81-
),
82-
)
83-
)
84-
);
85-
}
74+
padding: EdgeInsets.all(16.0),
75+
child: new Form(
76+
key: formKey,
77+
child: new Column(
78+
crossAxisAlignment: CrossAxisAlignment.stretch,
79+
children: buildInputs() + buildSubmitButtons(),
80+
),
81+
)));
82+
}
83+
84+
List<Widget> buildInputs() {
85+
return [
86+
new TextFormField(
87+
decoration: new InputDecoration(labelText: 'Email'),
88+
validator: (value) => value.isEmpty ? 'Email can\'t be empty' : null,
89+
onSaved: (value) => _email = value,
90+
),
91+
new TextFormField(
92+
decoration: new InputDecoration(labelText: 'Password'),
93+
obscureText: true,
94+
validator: (value) => value.isEmpty ? 'Password can\'t be empty' : null,
95+
onSaved: (value) => _password = value,
96+
),
97+
];
98+
}
8699

87-
List<Widget> buildInputs() {
100+
List<Widget> buildSubmitButtons() {
101+
if (_formType == FormType.login) {
88102
return [
89-
new TextFormField(
90-
decoration: new InputDecoration(labelText: 'Email'),
91-
validator: (value) => value.isEmpty ? 'Email can\'t be empty' : null,
92-
onSaved: (value) => _email = value,
103+
new RaisedButton(
104+
child: new Text('Login', style: new TextStyle(fontSize: 20.0)),
105+
onPressed: validateAndSubmit,
93106
),
94-
new TextFormField(
95-
decoration: new InputDecoration(labelText: 'Password'),
96-
obscureText: true,
97-
validator: (value) => value.isEmpty ? 'Password can\'t be empty' : null,
98-
onSaved: (value) => _password = value,
107+
new FlatButton(
108+
child: new Text('Create an account',
109+
style: new TextStyle(fontSize: 20.0)),
110+
onPressed: moveToRegister,
111+
),
112+
];
113+
} else {
114+
return [
115+
new RaisedButton(
116+
child: new Text('Create an account',
117+
style: new TextStyle(fontSize: 20.0)),
118+
onPressed: validateAndSubmit,
119+
),
120+
new FlatButton(
121+
child: new Text('Have an account? Login',
122+
style: new TextStyle(fontSize: 20.0)),
123+
onPressed: moveToLogin,
99124
),
100125
];
101126
}
102-
103-
List<Widget> buildSubmitButtons() {
104-
if (_formType == FormType.login) {
105-
return [
106-
new RaisedButton(
107-
child: new Text('Login', style: new TextStyle(fontSize: 20.0)),
108-
onPressed: validateAndSubmit,
109-
),
110-
new FlatButton(
111-
child: new Text('Create an account', style: new TextStyle(fontSize: 20.0)),
112-
onPressed: moveToRegister,
113-
),
114-
];
115-
} else {
116-
return [
117-
new RaisedButton(
118-
child: new Text('Create an account', style: new TextStyle(fontSize: 20.0)),
119-
onPressed: validateAndSubmit,
120-
),
121-
new FlatButton(
122-
child: new Text('Have an account? Login', style: new TextStyle(fontSize: 20.0)),
123-
onPressed: moveToLogin,
124-
),
125-
];
126-
}
127-
}
128-
}
127+
}
128+
}

lib/main.dart

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'package:flutter/material.dart';
2-
import 'login_page.dart';
32
import 'auth.dart';
43
import 'root_page.dart';
54

@@ -8,16 +7,13 @@ void main() {
87
}
98

109
class MyApp extends StatelessWidget {
11-
1210
@override
13-
Widget build(BuildContext context) {
14-
15-
return new MaterialApp(
11+
Widget build(BuildContext context) {
12+
return new MaterialApp(
1613
title: 'Flutter login demo',
1714
theme: new ThemeData(
18-
primarySwatch: Colors.blue,
15+
primarySwatch: Colors.blue,
1916
),
20-
home: new RootPage(auth: new Auth())
21-
);
22-
}
17+
home: new RootPage(auth: new Auth()));
18+
}
2319
}

lib/root_page.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ enum AuthStatus {
1717
}
1818

1919
class _RootPageState extends State<RootPage> {
20-
2120
AuthStatus authStatus = AuthStatus.notSignedIn;
2221

2322
initState() {
2423
super.initState();
2524
widget.auth.currentUser().then((userId) {
2625
setState(() {
27-
authStatus = userId == null ? AuthStatus.notSignedIn : AuthStatus.signedIn;
26+
authStatus =
27+
userId == null ? AuthStatus.notSignedIn : AuthStatus.signedIn;
2828
});
2929
});
3030
}
@@ -56,4 +56,4 @@ class _RootPageState extends State<RootPage> {
5656
);
5757
}
5858
}
59-
}
59+
}

0 commit comments

Comments
 (0)