1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-08 13:58:47 +00:00

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
This commit is contained in:
Brett Morgan
2021-10-09 08:30:28 +11:00
committed by GitHub
parent e160f5261c
commit e2e2713986
69 changed files with 174 additions and 114 deletions

View File

@@ -12,10 +12,8 @@ linter:
cancel_subscriptions: true
close_sinks: true
directives_ordering: true
file_names: false
package_api_docs: true
package_prefixed_library_names: true
test_types_in_equals: true
throw_in_finally: true
unnecessary_statements: true
use_key_in_widget_constructors: false

View File

@@ -12,7 +12,7 @@ void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
testWidgets('Finding an item in the list', (tester) async {
await tester.pumpWidget(TestingApp());
await tester.pumpWidget(const TestingApp());
// Create variables for finders that are used multiple times.
final itemFinder = find.byKey(const ValueKey('text_25'));
@@ -28,7 +28,7 @@ void main() {
});
testWidgets('Testing IconButtons', (tester) async {
await tester.pumpWidget(TestingApp());
await tester.pumpWidget(const TestingApp());
// Create a finder for the icon.
final iconFinder = find.byKey(const ValueKey('icon_0'));
@@ -51,7 +51,7 @@ void main() {
testWidgets('Verifying whether item gets added to favorites',
(tester) async {
await tester.pumpWidget(TestingApp());
await tester.pumpWidget(const TestingApp());
// Add item to favorites.
await tester.tap(find.byKey(const ValueKey('icon_5')));
@@ -71,7 +71,7 @@ void main() {
});
testWidgets('Testing remove button', (tester) async {
await tester.pumpWidget(TestingApp());
await tester.pumpWidget(const TestingApp());
// Add item to favorites.
await tester.tap(find.byKey(const ValueKey('icon_5')));

View File

@@ -17,7 +17,7 @@ void main() {
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.fullyLive;
testWidgets('Scrolling test', (tester) async {
await tester.pumpWidget(TestingApp());
await tester.pumpWidget(const TestingApp());
// Create variables for finders that are used multiple times.
final listFinder = find.byType(ListView);
@@ -49,7 +49,7 @@ void main() {
});
testWidgets('Favorites operations test', (tester) async {
await tester.pumpWidget(TestingApp());
await tester.pumpWidget(const TestingApp());
// Record the performance summary as operations are performed
// on the favorites list.

View File

@@ -16,7 +16,7 @@ Widget createFavoritesScreen() => ChangeNotifierProvider<Favorites>(
favoritesList = Favorites();
return favoritesList;
},
child: MaterialApp(
child: const MaterialApp(
home: FavoritesPage(),
),
);

View File

@@ -9,10 +9,12 @@ import 'package:testing_app/screens/favorites.dart';
import 'package:testing_app/screens/home.dart';
void main() {
runApp(TestingApp());
runApp(const TestingApp());
}
class TestingApp extends StatelessWidget {
const TestingApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider<Favorites>(
@@ -24,8 +26,8 @@ class TestingApp extends StatelessWidget {
visualDensity: VisualDensity.adaptivePlatformDensity,
),
routes: {
HomePage.routeName: (context) => HomePage(),
FavoritesPage.routeName: (context) => FavoritesPage(),
HomePage.routeName: (context) => const HomePage(),
FavoritesPage.routeName: (context) => const FavoritesPage(),
},
initialRoute: HomePage.routeName,
),

View File

@@ -9,6 +9,8 @@ import 'package:testing_app/models/favorites.dart';
class FavoritesPage extends StatelessWidget {
static String routeName = '/favorites_page';
const FavoritesPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
@@ -34,9 +36,7 @@ class FavoritesPage extends StatelessWidget {
class FavoriteItemTile extends StatelessWidget {
final int itemNo;
const FavoriteItemTile(
this.itemNo,
);
const FavoriteItemTile(this.itemNo, {Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {

View File

@@ -10,6 +10,8 @@ import 'package:testing_app/screens/favorites.dart';
class HomePage extends StatelessWidget {
static String routeName = '/';
const HomePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
@@ -40,9 +42,7 @@ class HomePage extends StatelessWidget {
class ItemTile extends StatelessWidget {
final int itemNo;
const ItemTile(
this.itemNo,
);
const ItemTile(this.itemNo, {Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {

View File

@@ -15,7 +15,7 @@ Widget createFavoritesScreen() => ChangeNotifierProvider<Favorites>(
favoritesList = Favorites();
return favoritesList;
},
child: MaterialApp(
child: const MaterialApp(
home: FavoritesPage(),
),
);

View File

@@ -10,7 +10,7 @@ import 'package:testing_app/screens/home.dart';
Widget createHomeScreen() => ChangeNotifierProvider<Favorites>(
create: (context) => Favorites(),
child: MaterialApp(
child: const MaterialApp(
home: HomePage(),
),
);