Skip to content

Commit b34cc56

Browse files
Add flutter_lints (#808)
1 parent 6acb879 commit b34cc56

File tree

6 files changed

+61
-27
lines changed

6 files changed

+61
-27
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
include: package:flutter_lints/flutter.yaml
2+
3+
analyzer:
4+
strong-mode:
5+
implicit-casts: false
6+
implicit-dynamic: false
7+
8+
linter:
9+
rules:
10+
avoid_types_on_closure_parameters: true
11+
avoid_void_async: true
12+
cancel_subscriptions: true
13+
close_sinks: true
14+
directives_ordering: true
15+
package_api_docs: true
16+
package_prefixed_library_names: true
17+
test_types_in_equals: true
18+
throw_in_finally: true
19+
unnecessary_statements: true

add_to_app/books/flutter_module_books/lib/api.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Book {
4141
}
4242

4343
abstract class FlutterBookApi {
44-
void displayBookDetails(Book arg);
44+
void displayBookDetails(Book book);
4545
static void setup(FlutterBookApi api) {
4646
{
4747
const BasicMessageChannel<Object> channel = BasicMessageChannel<Object>(
@@ -50,7 +50,7 @@ abstract class FlutterBookApi {
5050
if (api == null) {
5151
channel.setMessageHandler(null);
5252
} else {
53-
channel.setMessageHandler((Object message) async {
53+
channel.setMessageHandler((message) async {
5454
if (message == null) {
5555
return;
5656
}

add_to_app/books/flutter_module_books/lib/main.dart

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@
55
import 'package:flutter/material.dart';
66
import 'package:flutter_module_books/api.dart';
77

8-
void main() => runApp(MyApp());
8+
void main() => runApp(const MyApp());
99

1010
class MyApp extends StatelessWidget {
11+
const MyApp({Key key}) : super(key: key);
12+
1113
@override
1214
Widget build(BuildContext context) {
1315
return MaterialApp(
1416
theme: ThemeData(
1517
primaryColor: const Color(0xff6200ee),
1618
),
17-
home: BookDetail(),
19+
home: const BookDetail(),
1820
);
1921
}
2022
}
@@ -37,7 +39,7 @@ class FlutterBookApiHandler extends FlutterBookApi {
3739
}
3840

3941
class BookDetail extends StatefulWidget {
40-
const BookDetail({this.hostApi, this.flutterApi});
42+
const BookDetail({this.hostApi, this.flutterApi, Key key}) : super(key: key);
4143

4244
// These are the outgoing and incoming APIs that are here for injection for
4345
// tests.
@@ -73,7 +75,7 @@ class _BookDetailState extends State<BookDetail> {
7375
FlutterBookApi.setup(FlutterBookApiHandler(
7476
// The `FlutterBookApi` just has one method. Just give a closure for that
7577
// method to the handler class.
76-
(Book book) {
78+
(book) {
7779
setState(() {
7880
// This book model is what we're going to return to Kotlin eventually.
7981
// Keep it bound to the UI.
@@ -107,9 +109,9 @@ class _BookDetailState extends State<BookDetail> {
107109
Widget build(BuildContext context) {
108110
return Scaffold(
109111
appBar: AppBar(
110-
title: Text('Book Details'),
112+
title: const Text('Book Details'),
111113
leading: IconButton(
112-
icon: Icon(Icons.clear),
114+
icon: const Icon(Icons.clear),
113115
// Pressing clear cancels the edit and leaves the activity without
114116
// modification.
115117
onPressed: () {
@@ -119,7 +121,7 @@ class _BookDetailState extends State<BookDetail> {
119121
),
120122
actions: [
121123
IconButton(
122-
icon: Icon(Icons.check),
124+
icon: const Icon(Icons.check),
123125
// Pressing save sends the updated book to the platform.
124126
onPressed: () {
125127
hostApi.finishEditingBook(book);
@@ -131,54 +133,54 @@ class _BookDetailState extends State<BookDetail> {
131133
body: book == null
132134
// Draw a spinner until the platform gives us the book to show details
133135
// for.
134-
? Center(child: CircularProgressIndicator())
136+
? const Center(child: CircularProgressIndicator())
135137
: Focus(
136138
focusNode: textFocusNode,
137139
child: ListView(
138-
padding: EdgeInsets.all(24),
140+
padding: const EdgeInsets.all(24),
139141
children: [
140142
TextField(
141143
controller: titleTextController,
142-
decoration: InputDecoration(
144+
decoration: const InputDecoration(
143145
border: OutlineInputBorder(),
144146
filled: true,
145147
hintText: "Title",
146148
labelText: "Title",
147149
),
148150
),
149-
SizedBox(height: 24),
151+
const SizedBox(height: 24),
150152
TextField(
151153
controller: subtitleTextController,
152154
maxLines: 2,
153-
decoration: InputDecoration(
155+
decoration: const InputDecoration(
154156
border: OutlineInputBorder(),
155157
filled: true,
156158
hintText: "Subtitle",
157159
labelText: "Subtitle",
158160
),
159161
),
160-
SizedBox(height: 24),
162+
const SizedBox(height: 24),
161163
TextField(
162164
controller: authorTextController,
163-
decoration: InputDecoration(
165+
decoration: const InputDecoration(
164166
border: OutlineInputBorder(),
165167
filled: true,
166168
hintText: "Author",
167169
labelText: "Author",
168170
),
169171
),
170-
SizedBox(height: 32),
171-
Divider(),
172+
const SizedBox(height: 32),
173+
const Divider(),
172174
Center(
173175
child: Padding(
174176
padding: const EdgeInsets.all(8.0),
175177
child: Text(
176178
'${book.pageCount} pages ~ published ${book.publishDate}'),
177179
),
178180
),
179-
Divider(),
180-
SizedBox(height: 32),
181-
Center(
181+
const Divider(),
182+
const SizedBox(height: 32),
183+
const Center(
182184
child: Text(
183185
'BOOK DESCRIPTION',
184186
style: TextStyle(
@@ -188,7 +190,7 @@ class _BookDetailState extends State<BookDetail> {
188190
),
189191
),
190192
),
191-
SizedBox(height: 12),
193+
const SizedBox(height: 12),
192194
Text(
193195
book.summary,
194196
style: TextStyle(color: Colors.grey.shade600, height: 1.24),

add_to_app/books/flutter_module_books/pubspec.lock

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,25 @@ packages:
6262
description: flutter
6363
source: sdk
6464
version: "0.0.0"
65+
flutter_lints:
66+
dependency: "direct dev"
67+
description:
68+
name: flutter_lints
69+
url: "https://pub.dartlang.org"
70+
source: hosted
71+
version: "1.0.3"
6572
flutter_test:
6673
dependency: "direct dev"
6774
description: flutter
6875
source: sdk
6976
version: "0.0.0"
77+
lints:
78+
dependency: transitive
79+
description:
80+
name: lints
81+
url: "https://pub.dartlang.org"
82+
source: hosted
83+
version: "1.0.1"
7084
matcher:
7185
dependency: transitive
7286
description:

add_to_app/books/flutter_module_books/pubspec.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ dev_dependencies:
1717
mockito: ^4.1.1
1818
flutter_test:
1919
sdk: flutter
20+
flutter_lints: ^1.0.0
2021

2122
flutter:
2223
uses-material-design: true
@@ -30,4 +31,4 @@ flutter:
3031
module:
3132
androidX: true
3233
androidPackage: dev.flutter.example.flutter_module_books
33-
iosBundleIdentifier: dev.flutter.example.flutterModuleBooks
34+
iosBundleIdentifier: dev.flutter.example.flutterModuleBooks

add_to_app/books/flutter_module_books/test/widget_test.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import 'package:flutter_test/flutter_test.dart';
99
import 'package:mockito/mockito.dart';
1010

1111
void main() {
12-
testWidgets('Pressing clear calls the cancel API',
13-
(WidgetTester tester) async {
12+
testWidgets('Pressing clear calls the cancel API', (tester) async {
1413
MockHostBookApi mockHostApi = MockHostBookApi();
1514

1615
await tester.pumpWidget(
@@ -24,8 +23,7 @@ void main() {
2423
verify(mockHostApi.cancel());
2524
});
2625

27-
testWidgets('Pressing done calls the finish editing API',
28-
(WidgetTester tester) async {
26+
testWidgets('Pressing done calls the finish editing API', (tester) async {
2927
MockHostBookApi mockHostApi = MockHostBookApi();
3028

3129
await tester.pumpWidget(

0 commit comments

Comments
 (0)