Skip to content

Commit 8fb1fd5

Browse files
committed
Update all code to follow linting rules in analysis options
1 parent 5b5b36c commit 8fb1fd5

File tree

6 files changed

+62
-68
lines changed

6 files changed

+62
-68
lines changed

lib/auth.dart

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

14-
Future<String> signInWithEmailAndPassword(
15-
String email, String password) async {
16-
FirebaseUser user = await _firebaseAuth.signInWithEmailAndPassword(
17-
email: email, password: password);
18-
user.email;
14+
@override
15+
Future<String> signInWithEmailAndPassword(String email, String password) async {
16+
final FirebaseUser user = await _firebaseAuth.signInWithEmailAndPassword(email: email, password: password);
1917
return user?.uid;
2018
}
2119

22-
Future<String> createUserWithEmailAndPassword(
23-
String email, String password) async {
24-
FirebaseUser user = await _firebaseAuth.createUserWithEmailAndPassword(
25-
email: email, password: password);
20+
@override
21+
Future<String> createUserWithEmailAndPassword(String email, String password) async {
22+
final FirebaseUser user = await _firebaseAuth.createUserWithEmailAndPassword(email: email, password: password);
2623
return user?.uid;
2724
}
2825

26+
@override
2927
Future<String> currentUser() async {
30-
FirebaseUser user = await _firebaseAuth.currentUser();
28+
final FirebaseUser user = await _firebaseAuth.currentUser();
3129
return user?.uid;
3230
}
3331

32+
@override
3433
Future<void> signOut() async {
3534
return _firebaseAuth.signOut();
3635
}

lib/auth_provider.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import 'package:flutter/material.dart';
33
import 'package:login_demo/auth.dart';
44

55
class AuthProvider extends InheritedWidget {
6-
AuthProvider({Key key, Widget child, this.auth}) : super(key: key, child: child);
6+
const AuthProvider({Key key, Widget child, this.auth}) : super(key: key, child: child);
77
final BaseAuth auth;
88

99
@override
1010
bool updateShouldNotify(InheritedWidget oldWidget) => true;
1111

1212
static AuthProvider of(BuildContext context) {
13-
return (context.inheritFromWidgetOfExactType(AuthProvider) as AuthProvider);
13+
return context.inheritFromWidgetOfExactType(AuthProvider);
1414
}
1515
}

lib/home_page.dart

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import 'package:flutter/material.dart';
2+
import 'package:login_demo/auth.dart';
23
import 'package:login_demo/auth_provider.dart';
34

45
class HomePage extends StatelessWidget {
5-
HomePage({this.onSignedOut});
6+
const HomePage({this.onSignedOut});
67
final VoidCallback onSignedOut;
78

8-
void _signOut(BuildContext context) async {
9+
Future<void> _signOut(BuildContext context) async {
910
try {
10-
var auth = AuthProvider.of(context).auth;
11+
final BaseAuth auth = AuthProvider.of(context).auth;
1112
await auth.signOut();
1213
onSignedOut();
1314
} catch (e) {
@@ -18,18 +19,18 @@ class HomePage extends StatelessWidget {
1819
@override
1920
Widget build(BuildContext context) {
2021
return Scaffold(
21-
appBar: AppBar(
22-
title: Text('Welcome'),
23-
actions: <Widget>[
24-
FlatButton(
25-
child: Text('Logout',
26-
style: TextStyle(fontSize: 17.0, color: Colors.white)),
27-
onPressed: () => _signOut(context))
28-
],
29-
),
30-
body: Container(
31-
child: Center(
32-
child: Text('Welcome', style: TextStyle(fontSize: 32.0))),
33-
));
22+
appBar: AppBar(
23+
title: Text('Welcome'),
24+
actions: <Widget>[
25+
FlatButton(
26+
child: Text('Logout', style: TextStyle(fontSize: 17.0, color: Colors.white)),
27+
onPressed: () => _signOut(context),
28+
)
29+
],
30+
),
31+
body: Container(
32+
child: Center(child: Text('Welcome', style: TextStyle(fontSize: 32.0))),
33+
),
34+
);
3435
}
3536
}

lib/login_page.dart

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'package:flutter/material.dart';
2+
import 'package:login_demo/auth.dart';
23
import 'package:login_demo/auth_provider.dart';
34

4-
55
class EmailFieldValidator {
66
static String validate(String value) {
77
return value.isEmpty ? 'Email can\'t be empty' : null;
@@ -15,7 +15,7 @@ class PasswordFieldValidator {
1515
}
1616

1717
class LoginPage extends StatefulWidget {
18-
LoginPage({this.onSignedIn});
18+
const LoginPage({this.onSignedIn});
1919
final VoidCallback onSignedIn;
2020

2121
@override
@@ -28,32 +28,30 @@ enum FormType {
2828
}
2929

3030
class _LoginPageState extends State<LoginPage> {
31-
final formKey = GlobalKey<FormState>();
31+
final GlobalKey<FormState> formKey = GlobalKey<FormState>();
3232

3333
String _email;
3434
String _password;
3535
FormType _formType = FormType.login;
3636

3737
bool validateAndSave() {
38-
final form = formKey.currentState;
38+
final FormState form = formKey.currentState;
3939
if (form.validate()) {
4040
form.save();
4141
return true;
4242
}
4343
return false;
4444
}
4545

46-
void validateAndSubmit() async {
46+
Future<void> validateAndSubmit() async {
4747
if (validateAndSave()) {
4848
try {
49-
var auth = AuthProvider.of(context).auth;
49+
final BaseAuth auth = AuthProvider.of(context).auth;
5050
if (_formType == FormType.login) {
51-
String userId =
52-
await auth.signInWithEmailAndPassword(_email, _password);
51+
final String userId = await auth.signInWithEmailAndPassword(_email, _password);
5352
print('Signed in: $userId');
5453
} else {
55-
String userId = await auth
56-
.createUserWithEmailAndPassword(_email, _password);
54+
final String userId = await auth.createUserWithEmailAndPassword(_email, _password);
5755
print('Registered user: $userId');
5856
}
5957
widget.onSignedIn();
@@ -80,62 +78,61 @@ class _LoginPageState extends State<LoginPage> {
8078
@override
8179
Widget build(BuildContext context) {
8280
return Scaffold(
83-
appBar: AppBar(
84-
title: Text('Flutter login demo'),
81+
appBar: AppBar(
82+
title: Text('Flutter login demo'),
83+
),
84+
body: Container(
85+
padding: EdgeInsets.all(16.0),
86+
child: Form(
87+
key: formKey,
88+
child: Column(
89+
crossAxisAlignment: CrossAxisAlignment.stretch,
90+
children: buildInputs() + buildSubmitButtons(),
91+
),
8592
),
86-
body: Container(
87-
padding: EdgeInsets.all(16.0),
88-
child: Form(
89-
key: formKey,
90-
child: Column(
91-
crossAxisAlignment: CrossAxisAlignment.stretch,
92-
children: buildInputs() + buildSubmitButtons(),
93-
),
94-
)));
93+
),
94+
);
9595
}
9696

9797
List<Widget> buildInputs() {
98-
return [
98+
return <Widget>[
9999
TextFormField(
100100
key: Key('email'),
101101
decoration: InputDecoration(labelText: 'Email'),
102102
validator: EmailFieldValidator.validate,
103-
onSaved: (value) => _email = value,
103+
onSaved: (String value) => _email = value,
104104
),
105105
TextFormField(
106106
key: Key('password'),
107107
decoration: InputDecoration(labelText: 'Password'),
108108
obscureText: true,
109109
validator: PasswordFieldValidator.validate,
110-
onSaved: (value) => _password = value,
110+
onSaved: (String value) => _password = value,
111111
),
112112
];
113113
}
114114

115115
List<Widget> buildSubmitButtons() {
116116
if (_formType == FormType.login) {
117-
return [
117+
return <Widget>[
118118
RaisedButton(
119119
key: Key('signIn'),
120120
child: Text('Login', style: TextStyle(fontSize: 20.0)),
121121
onPressed: validateAndSubmit,
122122
),
123123
FlatButton(
124-
child: Text('Create an account',
125-
style: TextStyle(fontSize: 20.0)),
124+
child: Text('Create an account', style: TextStyle(fontSize: 20.0)),
126125
onPressed: moveToRegister,
127126
),
128127
];
129128
} else {
130-
return [
129+
return <Widget>[
131130
RaisedButton(
132-
child: Text('Create an account',
133-
style: TextStyle(fontSize: 20.0)),
131+
child: Text('Create an account', style: TextStyle(fontSize: 20.0)),
134132
onPressed: validateAndSubmit,
135133
),
136134
FlatButton(
137-
child: Text('Have an account? Login',
138-
style: TextStyle(fontSize: 20.0)),
135+
child: Text('Have an account? Login', style: TextStyle(fontSize: 20.0)),
139136
onPressed: moveToLogin,
140137
),
141138
];

lib/main.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import 'package:login_demo/auth.dart';
33
import 'package:login_demo/auth_provider.dart';
44
import 'package:login_demo/root_page.dart';
55

6-
void main() {
7-
runApp(MyApp());
8-
}
6+
void main() => runApp(MyApp());
97

108
class MyApp extends StatelessWidget {
119
@override

lib/root_page.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import 'package:flutter/material.dart';
2+
import 'package:login_demo/auth.dart';
23
import 'package:login_demo/home_page.dart';
34
import 'package:login_demo/login_page.dart';
45
import 'package:login_demo/auth_provider.dart';
56

67
class RootPage extends StatefulWidget {
7-
88
@override
99
State<StatefulWidget> createState() => _RootPageState();
1010
}
@@ -21,11 +21,10 @@ class _RootPageState extends State<RootPage> {
2121
@override
2222
void didChangeDependencies() {
2323
super.didChangeDependencies();
24-
var auth = AuthProvider.of(context).auth;
25-
auth.currentUser().then((userId) {
24+
final BaseAuth auth = AuthProvider.of(context).auth;
25+
auth.currentUser().then((String userId) {
2626
setState(() {
27-
authStatus =
28-
userId == null ? AuthStatus.notSignedIn : AuthStatus.signedIn;
27+
authStatus = userId == null ? AuthStatus.notSignedIn : AuthStatus.signedIn;
2928
});
3029
});
3130
}

0 commit comments

Comments
 (0)