Skip to content

Commit e2e2713

Browse files
Enforce use_key_in_widget_constructors and file_names lints (#913)
* Start enforcing use_key_in_widget_constructors and file_names lints * dart format * analysis fixes * analysis fixes, pt2 * analysis fixes, part 3 * Revert platform_design (test failure) * More reverts * Notate why we aren't enforcing a lint
1 parent e160f52 commit e2e2713

File tree

69 files changed

+174
-114
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+174
-114
lines changed

add_to_app/android_view/flutter_module_using_plugin/test/widget_test.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
// tree, read text, and verify that the values of widget properties are correct.
77

88
import 'package:flutter/material.dart';
9-
import 'package:flutter_test/flutter_test.dart';
10-
119
import 'package:flutter_module_using_plugin/main.dart';
10+
import 'package:flutter_test/flutter_test.dart';
1211
import 'package:provider/provider.dart';
1312

1413
class MockCounterModel extends ChangeNotifier implements CounterModel {

add_to_app/books/flutter_module_books/lib/api.dart

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ abstract class FlutterBookApi {
9494
if (api == null) {
9595
channel.setMessageHandler(null);
9696
} else {
97+
// ignore: avoid_types_on_closure_parameters
9798
channel.setMessageHandler((Object? message) async {
9899
assert(message != null,
99100
'Argument for dev.flutter.pigeon.FlutterBookApi.displayBookDetails was null.');

experimental/federated_plugin/federated_plugin_platform_interface/pubspec.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
name: federated_plugin_platform_interface
22
description: A platform interface for federated_plugin.
33
version: 0.0.1
4-
author:
54
homepage:
65
publish_to: none
76

experimental/federated_plugin/federated_plugin_windows/pubspec.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
name: federated_plugin_windows
22
description: Windows implementation of federated_plugin to retrieve current battery level.
33
version: 0.0.1
4-
author:
54
homepage:
65
publish_to: none
76

experimental/linting_tool/analysis_options.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ linter:
1515
cancel_subscriptions: true
1616
close_sinks: true
1717
directives_ordering: true
18-
file_names: false
1918
package_api_docs: true
2019
package_prefixed_library_names: true
2120
test_types_in_equals: true
2221
throw_in_finally: true
2322
unnecessary_statements: true
24-
use_key_in_widget_constructors: false

experimental/web_dashboard/analysis_options.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,3 @@ linter:
1717
test_types_in_equals: true
1818
throw_in_finally: true
1919
unnecessary_statements: true
20-
use_key_in_widget_constructors: false

experimental/web_dashboard/lib/src/app.dart

+8-5
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,16 @@ class DashboardApp extends StatefulWidget {
3939
final ApiBuilder apiBuilder;
4040

4141
/// Runs the app using Firebase
42-
DashboardApp.firebase()
42+
DashboardApp.firebase({Key key})
4343
: auth = FirebaseAuthService(),
44-
apiBuilder = _apiBuilder;
44+
apiBuilder = _apiBuilder,
45+
super(key: key);
4546

4647
/// Runs the app using mock data
47-
DashboardApp.mock()
48+
DashboardApp.mock({Key key})
4849
: auth = MockAuthService(),
49-
apiBuilder = _mockApiBuilder;
50+
apiBuilder = _mockApiBuilder,
51+
super(key: key);
5052

5153
@override
5254
_DashboardAppState createState() => _DashboardAppState();
@@ -84,7 +86,8 @@ class SignInSwitcher extends StatefulWidget {
8486
const SignInSwitcher({
8587
this.appState,
8688
this.apiBuilder,
87-
});
89+
Key key,
90+
}) : super(key: key);
8891

8992
@override
9093
_SignInSwitcherState createState() => _SignInSwitcherState();

experimental/web_dashboard/lib/src/pages/dashboard.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import '../app.dart';
1010
import '../widgets/category_chart.dart';
1111

1212
class DashboardPage extends StatelessWidget {
13+
const DashboardPage({Key key}) : super(key: key);
14+
1315
@override
1416
Widget build(BuildContext context) {
1517
var appState = Provider.of<AppState>(context);
@@ -41,7 +43,7 @@ class DashboardPage extends StatelessWidget {
4143
class Dashboard extends StatelessWidget {
4244
final List<Category> categories;
4345

44-
const Dashboard(this.categories);
46+
const Dashboard(this.categories, {Key key}) : super(key: key);
4547

4648
@override
4749
Widget build(BuildContext context) {

experimental/web_dashboard/lib/src/pages/entries.dart

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import '../widgets/categories_dropdown.dart';
1212
import '../widgets/dialogs.dart';
1313

1414
class EntriesPage extends StatefulWidget {
15+
const EntriesPage({Key key}) : super(key: key);
16+
1517
@override
1618
_EntriesPageState createState() => _EntriesPageState();
1719
}
@@ -100,7 +102,8 @@ class EntryTile extends StatelessWidget {
100102
const EntryTile({
101103
this.category,
102104
this.entry,
103-
});
105+
Key key,
106+
}) : super(key: key);
104107

105108
@override
106109
Widget build(BuildContext context) {

experimental/web_dashboard/lib/src/pages/home.dart

+6-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ class HomePage extends StatefulWidget {
1414

1515
const HomePage({
1616
@required this.onSignOut,
17-
});
17+
Key key,
18+
}) : super(key: key);
1819

1920
@override
2021
_HomePageState createState() => _HomePageState();
@@ -70,15 +71,15 @@ class _HomePageState extends State<HomePage> {
7071
if (_pageIndex == 0) {
7172
showDialog<NewCategoryDialog>(
7273
context: context,
73-
builder: (context) => NewCategoryDialog(),
74+
builder: (context) => const NewCategoryDialog(),
7475
);
7576
return;
7677
}
7778

7879
if (_pageIndex == 1) {
7980
showDialog<NewEntryDialog>(
8081
context: context,
81-
builder: (context) => NewEntryDialog(),
82+
builder: (context) => const NewEntryDialog(),
8283
);
8384
return;
8485
}
@@ -115,11 +116,11 @@ class _HomePageState extends State<HomePage> {
115116

116117
static Widget _pageAtIndex(int index) {
117118
if (index == 0) {
118-
return DashboardPage();
119+
return const DashboardPage();
119120
}
120121

121122
if (index == 1) {
122-
return EntriesPage();
123+
return const EntriesPage();
123124
}
124125

125126
return const Center(child: Text('Settings page'));

experimental/web_dashboard/lib/src/pages/sign_in.dart

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ class SignInPage extends StatelessWidget {
1313
const SignInPage({
1414
@required this.auth,
1515
@required this.onSuccess,
16-
});
16+
Key key,
17+
}) : super(key: key);
1718

1819
@override
1920
Widget build(BuildContext context) {
@@ -32,7 +33,8 @@ class SignInButton extends StatefulWidget {
3233
const SignInButton({
3334
@required this.auth,
3435
@required this.onSuccess,
35-
});
36+
Key key,
37+
}) : super(key: key);
3638

3739
@override
3840
_SignInButtonState createState() => _SignInButtonState();

experimental/web_dashboard/lib/src/widgets/categories_dropdown.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ class CategoryDropdown extends StatefulWidget {
1616
const CategoryDropdown({
1717
@required this.api,
1818
@required this.onSelected,
19-
});
19+
Key key,
20+
}) : super(key: key);
2021

2122
@override
2223
_CategoryDropdownState createState() => _CategoryDropdownState();

experimental/web_dashboard/lib/src/widgets/category_chart.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ class CategoryChart extends StatelessWidget {
2020
const CategoryChart({
2121
@required this.category,
2222
@required this.api,
23-
});
23+
Key key,
24+
}) : super(key: key);
2425

2526
@override
2627
Widget build(BuildContext context) {

experimental/web_dashboard/lib/src/widgets/category_forms.dart

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import 'package:web_dashboard/src/api/api.dart';
88
import 'package:web_dashboard/src/app.dart';
99

1010
class NewCategoryForm extends StatefulWidget {
11+
const NewCategoryForm({Key key}) : super(key: key);
12+
1113
@override
1214
_NewCategoryFormState createState() => _NewCategoryFormState();
1315
}
@@ -37,7 +39,8 @@ class EditCategoryForm extends StatefulWidget {
3739
const EditCategoryForm({
3840
@required this.category,
3941
@required this.onDone,
40-
});
42+
Key key,
43+
}) : super(key: key);
4144

4245
@override
4346
_EditCategoryFormState createState() => _EditCategoryFormState();

experimental/web_dashboard/lib/src/widgets/dialogs.dart

+12-6
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ import '../app.dart';
1111
import 'edit_entry.dart';
1212

1313
class NewCategoryDialog extends StatelessWidget {
14+
const NewCategoryDialog({Key key}) : super(key: key);
15+
1416
@override
1517
Widget build(BuildContext context) {
16-
return SimpleDialog(
17-
title: const Text('New Category'),
18+
return const SimpleDialog(
19+
title: Text('New Category'),
1820
children: <Widget>[
1921
NewCategoryForm(),
2022
],
@@ -27,7 +29,8 @@ class EditCategoryDialog extends StatelessWidget {
2729

2830
const EditCategoryDialog({
2931
@required this.category,
30-
});
32+
Key key,
33+
}) : super(key: key);
3134

3235
@override
3336
Widget build(BuildContext context) {
@@ -51,15 +54,17 @@ class EditCategoryDialog extends StatelessWidget {
5154
}
5255

5356
class NewEntryDialog extends StatefulWidget {
57+
const NewEntryDialog({Key key}) : super(key: key);
58+
5459
@override
5560
_NewEntryDialogState createState() => _NewEntryDialogState();
5661
}
5762

5863
class _NewEntryDialogState extends State<NewEntryDialog> {
5964
@override
6065
Widget build(BuildContext context) {
61-
return SimpleDialog(
62-
title: const Text('New Entry'),
66+
return const SimpleDialog(
67+
title: Text('New Entry'),
6368
children: [
6469
NewEntryForm(),
6570
],
@@ -74,7 +79,8 @@ class EditEntryDialog extends StatelessWidget {
7479
const EditEntryDialog({
7580
this.category,
7681
this.entry,
77-
});
82+
Key key,
83+
}) : super(key: key);
7884

7985
@override
8086
Widget build(BuildContext context) {

experimental/web_dashboard/lib/src/widgets/edit_entry.dart

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import '../app.dart';
1111
import 'categories_dropdown.dart';
1212

1313
class NewEntryForm extends StatefulWidget {
14+
const NewEntryForm({Key key}) : super(key: key);
15+
1416
@override
1517
_NewEntryFormState createState() => _NewEntryFormState();
1618
}
@@ -58,7 +60,8 @@ class EditEntryForm extends StatefulWidget {
5860
const EditEntryForm({
5961
@required this.entry,
6062
@required this.onDone,
61-
});
63+
Key key,
64+
}) : super(key: key);
6265

6366
@override
6467
_EditEntryFormState createState() => _EditEntryFormState();

experimental/web_dashboard/lib/src/widgets/third_party/adaptive_scaffold.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ class AdaptiveScaffold extends StatefulWidget {
4343
@required this.destinations,
4444
this.onNavigationIndexChange,
4545
this.floatingActionButton,
46-
});
46+
Key key,
47+
}) : super(key: key);
4748

4849
@override
4950
_AdaptiveScaffoldState createState() => _AdaptiveScaffoldState();

platform_channels/analysis_options.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ linter:
1212
cancel_subscriptions: true
1313
close_sinks: true
1414
directives_ordering: true
15-
file_names: false
1615
package_api_docs: true
1716
package_prefixed_library_names: true
1817
test_types_in_equals: true
1918
throw_in_finally: true
2019
unnecessary_statements: true
21-
use_key_in_widget_constructors: false

platform_channels/lib/main.dart

+12-8
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,29 @@ import 'package:platform_channels/src/pet_list_screen.dart';
1010
import 'package:platform_channels/src/platform_image_demo.dart';
1111

1212
void main() {
13-
runApp(PlatformChannelSample());
13+
runApp(const PlatformChannelSample());
1414
}
1515

1616
class PlatformChannelSample extends StatelessWidget {
17+
const PlatformChannelSample({Key? key}) : super(key: key);
18+
1719
@override
1820
Widget build(BuildContext context) {
1921
return MaterialApp(
2022
routes: {
21-
'/methodChannelDemo': (context) => MethodChannelDemo(),
22-
'/eventChannelDemo': (context) => EventChannelDemo(),
23-
'/platformImageDemo': (context) => PlatformImageDemo(),
24-
'/petListScreen': (context) => PetListScreen(),
25-
'/addPetDetails': (context) => AddPetDetails(),
23+
'/methodChannelDemo': (context) => const MethodChannelDemo(),
24+
'/eventChannelDemo': (context) => const EventChannelDemo(),
25+
'/platformImageDemo': (context) => const PlatformImageDemo(),
26+
'/petListScreen': (context) => const PetListScreen(),
27+
'/addPetDetails': (context) => const AddPetDetails(),
2628
},
2729
title: 'Platform Channel Sample',
2830
theme: ThemeData(
2931
snackBarTheme: SnackBarThemeData(
3032
backgroundColor: Colors.blue[500],
3133
),
3234
),
33-
home: HomePage(),
35+
home: const HomePage(),
3436
);
3537
}
3638
}
@@ -62,6 +64,8 @@ List<DemoInfo> demoList = [
6264
];
6365

6466
class HomePage extends StatelessWidget {
67+
const HomePage({Key? key}) : super(key: key);
68+
6569
@override
6670
Widget build(BuildContext context) {
6771
return Scaffold(
@@ -79,7 +83,7 @@ class HomePage extends StatelessWidget {
7983
class DemoTile extends StatelessWidget {
8084
final DemoInfo demoInfo;
8185

82-
const DemoTile(this.demoInfo);
86+
const DemoTile(this.demoInfo, {Key? key}) : super(key: key);
8387

8488
@override
8589
Widget build(BuildContext context) {

platform_channels/lib/src/add_pet_details.dart

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import 'package:platform_channels/src/pet_list_message_channel.dart';
1010
/// The widget uses [TextField] and [RadioListTile] to take the [PetDetails.breed] and
1111
/// [PetDetails.petType] from the user respectively.
1212
class AddPetDetails extends StatefulWidget {
13+
const AddPetDetails({Key? key}) : super(key: key);
14+
1315
@override
1416
_AddPetDetailsState createState() => _AddPetDetailsState();
1517
}

platform_channels/lib/src/event_channel_demo.dart

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import 'package:platform_channels/src/accelerometer_event_channel.dart';
1414
/// [Text] widgets to display the value of [AccelerometerReadings.x],
1515
/// [AccelerometerReadings.y], and [AccelerometerReadings.z] respectively.
1616
class EventChannelDemo extends StatelessWidget {
17+
const EventChannelDemo({Key? key}) : super(key: key);
18+
1719
@override
1820
Widget build(BuildContext context) {
1921
final textStyle = Theme.of(context).textTheme.headline5;

platform_channels/lib/src/method_channel_demo.dart

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import 'package:platform_channels/src/counter_method_channel.dart';
1010
/// It has two [ElevatedButton]s to increment and decrement the value of
1111
/// [count], and a [Text] widget to display its value.
1212
class MethodChannelDemo extends StatefulWidget {
13+
const MethodChannelDemo({Key? key}) : super(key: key);
14+
1315
@override
1416
_MethodChannelDemoState createState() => _MethodChannelDemoState();
1517
}

0 commit comments

Comments
 (0)