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
pull/925/head
Brett Morgan 3 years ago committed by GitHub
parent e160f5261c
commit e2e2713986
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -6,9 +6,8 @@
// tree, read text, and verify that the values of widget properties are correct. // tree, read text, and verify that the values of widget properties are correct.
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_module_using_plugin/main.dart'; import 'package:flutter_module_using_plugin/main.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
class MockCounterModel extends ChangeNotifier implements CounterModel { class MockCounterModel extends ChangeNotifier implements CounterModel {

@ -94,6 +94,7 @@ abstract class FlutterBookApi {
if (api == null) { if (api == null) {
channel.setMessageHandler(null); channel.setMessageHandler(null);
} else { } else {
// ignore: avoid_types_on_closure_parameters
channel.setMessageHandler((Object? message) async { channel.setMessageHandler((Object? message) async {
assert(message != null, assert(message != null,
'Argument for dev.flutter.pigeon.FlutterBookApi.displayBookDetails was null.'); 'Argument for dev.flutter.pigeon.FlutterBookApi.displayBookDetails was null.');

@ -1,7 +1,6 @@
name: federated_plugin_platform_interface name: federated_plugin_platform_interface
description: A platform interface for federated_plugin. description: A platform interface for federated_plugin.
version: 0.0.1 version: 0.0.1
author:
homepage: homepage:
publish_to: none publish_to: none

@ -1,7 +1,6 @@
name: federated_plugin_windows name: federated_plugin_windows
description: Windows implementation of federated_plugin to retrieve current battery level. description: Windows implementation of federated_plugin to retrieve current battery level.
version: 0.0.1 version: 0.0.1
author:
homepage: homepage:
publish_to: none publish_to: none

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

@ -17,4 +17,3 @@ linter:
test_types_in_equals: true test_types_in_equals: true
throw_in_finally: true throw_in_finally: true
unnecessary_statements: true unnecessary_statements: true
use_key_in_widget_constructors: false

@ -39,14 +39,16 @@ class DashboardApp extends StatefulWidget {
final ApiBuilder apiBuilder; final ApiBuilder apiBuilder;
/// Runs the app using Firebase /// Runs the app using Firebase
DashboardApp.firebase() DashboardApp.firebase({Key key})
: auth = FirebaseAuthService(), : auth = FirebaseAuthService(),
apiBuilder = _apiBuilder; apiBuilder = _apiBuilder,
super(key: key);
/// Runs the app using mock data /// Runs the app using mock data
DashboardApp.mock() DashboardApp.mock({Key key})
: auth = MockAuthService(), : auth = MockAuthService(),
apiBuilder = _mockApiBuilder; apiBuilder = _mockApiBuilder,
super(key: key);
@override @override
_DashboardAppState createState() => _DashboardAppState(); _DashboardAppState createState() => _DashboardAppState();
@ -84,7 +86,8 @@ class SignInSwitcher extends StatefulWidget {
const SignInSwitcher({ const SignInSwitcher({
this.appState, this.appState,
this.apiBuilder, this.apiBuilder,
}); Key key,
}) : super(key: key);
@override @override
_SignInSwitcherState createState() => _SignInSwitcherState(); _SignInSwitcherState createState() => _SignInSwitcherState();

@ -10,6 +10,8 @@ import '../app.dart';
import '../widgets/category_chart.dart'; import '../widgets/category_chart.dart';
class DashboardPage extends StatelessWidget { class DashboardPage extends StatelessWidget {
const DashboardPage({Key key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var appState = Provider.of<AppState>(context); var appState = Provider.of<AppState>(context);
@ -41,7 +43,7 @@ class DashboardPage extends StatelessWidget {
class Dashboard extends StatelessWidget { class Dashboard extends StatelessWidget {
final List<Category> categories; final List<Category> categories;
const Dashboard(this.categories); const Dashboard(this.categories, {Key key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

@ -12,6 +12,8 @@ import '../widgets/categories_dropdown.dart';
import '../widgets/dialogs.dart'; import '../widgets/dialogs.dart';
class EntriesPage extends StatefulWidget { class EntriesPage extends StatefulWidget {
const EntriesPage({Key key}) : super(key: key);
@override @override
_EntriesPageState createState() => _EntriesPageState(); _EntriesPageState createState() => _EntriesPageState();
} }
@ -100,7 +102,8 @@ class EntryTile extends StatelessWidget {
const EntryTile({ const EntryTile({
this.category, this.category,
this.entry, this.entry,
}); Key key,
}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

@ -14,7 +14,8 @@ class HomePage extends StatefulWidget {
const HomePage({ const HomePage({
@required this.onSignOut, @required this.onSignOut,
}); Key key,
}) : super(key: key);
@override @override
_HomePageState createState() => _HomePageState(); _HomePageState createState() => _HomePageState();
@ -70,7 +71,7 @@ class _HomePageState extends State<HomePage> {
if (_pageIndex == 0) { if (_pageIndex == 0) {
showDialog<NewCategoryDialog>( showDialog<NewCategoryDialog>(
context: context, context: context,
builder: (context) => NewCategoryDialog(), builder: (context) => const NewCategoryDialog(),
); );
return; return;
} }
@ -78,7 +79,7 @@ class _HomePageState extends State<HomePage> {
if (_pageIndex == 1) { if (_pageIndex == 1) {
showDialog<NewEntryDialog>( showDialog<NewEntryDialog>(
context: context, context: context,
builder: (context) => NewEntryDialog(), builder: (context) => const NewEntryDialog(),
); );
return; return;
} }
@ -115,11 +116,11 @@ class _HomePageState extends State<HomePage> {
static Widget _pageAtIndex(int index) { static Widget _pageAtIndex(int index) {
if (index == 0) { if (index == 0) {
return DashboardPage(); return const DashboardPage();
} }
if (index == 1) { if (index == 1) {
return EntriesPage(); return const EntriesPage();
} }
return const Center(child: Text('Settings page')); return const Center(child: Text('Settings page'));

@ -13,7 +13,8 @@ class SignInPage extends StatelessWidget {
const SignInPage({ const SignInPage({
@required this.auth, @required this.auth,
@required this.onSuccess, @required this.onSuccess,
}); Key key,
}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -32,7 +33,8 @@ class SignInButton extends StatefulWidget {
const SignInButton({ const SignInButton({
@required this.auth, @required this.auth,
@required this.onSuccess, @required this.onSuccess,
}); Key key,
}) : super(key: key);
@override @override
_SignInButtonState createState() => _SignInButtonState(); _SignInButtonState createState() => _SignInButtonState();

@ -16,7 +16,8 @@ class CategoryDropdown extends StatefulWidget {
const CategoryDropdown({ const CategoryDropdown({
@required this.api, @required this.api,
@required this.onSelected, @required this.onSelected,
}); Key key,
}) : super(key: key);
@override @override
_CategoryDropdownState createState() => _CategoryDropdownState(); _CategoryDropdownState createState() => _CategoryDropdownState();

@ -20,7 +20,8 @@ class CategoryChart extends StatelessWidget {
const CategoryChart({ const CategoryChart({
@required this.category, @required this.category,
@required this.api, @required this.api,
}); Key key,
}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

@ -8,6 +8,8 @@ import 'package:web_dashboard/src/api/api.dart';
import 'package:web_dashboard/src/app.dart'; import 'package:web_dashboard/src/app.dart';
class NewCategoryForm extends StatefulWidget { class NewCategoryForm extends StatefulWidget {
const NewCategoryForm({Key key}) : super(key: key);
@override @override
_NewCategoryFormState createState() => _NewCategoryFormState(); _NewCategoryFormState createState() => _NewCategoryFormState();
} }
@ -37,7 +39,8 @@ class EditCategoryForm extends StatefulWidget {
const EditCategoryForm({ const EditCategoryForm({
@required this.category, @required this.category,
@required this.onDone, @required this.onDone,
}); Key key,
}) : super(key: key);
@override @override
_EditCategoryFormState createState() => _EditCategoryFormState(); _EditCategoryFormState createState() => _EditCategoryFormState();

@ -11,10 +11,12 @@ import '../app.dart';
import 'edit_entry.dart'; import 'edit_entry.dart';
class NewCategoryDialog extends StatelessWidget { class NewCategoryDialog extends StatelessWidget {
const NewCategoryDialog({Key key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return SimpleDialog( return const SimpleDialog(
title: const Text('New Category'), title: Text('New Category'),
children: <Widget>[ children: <Widget>[
NewCategoryForm(), NewCategoryForm(),
], ],
@ -27,7 +29,8 @@ class EditCategoryDialog extends StatelessWidget {
const EditCategoryDialog({ const EditCategoryDialog({
@required this.category, @required this.category,
}); Key key,
}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -51,6 +54,8 @@ class EditCategoryDialog extends StatelessWidget {
} }
class NewEntryDialog extends StatefulWidget { class NewEntryDialog extends StatefulWidget {
const NewEntryDialog({Key key}) : super(key: key);
@override @override
_NewEntryDialogState createState() => _NewEntryDialogState(); _NewEntryDialogState createState() => _NewEntryDialogState();
} }
@ -58,8 +63,8 @@ class NewEntryDialog extends StatefulWidget {
class _NewEntryDialogState extends State<NewEntryDialog> { class _NewEntryDialogState extends State<NewEntryDialog> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return SimpleDialog( return const SimpleDialog(
title: const Text('New Entry'), title: Text('New Entry'),
children: [ children: [
NewEntryForm(), NewEntryForm(),
], ],
@ -74,7 +79,8 @@ class EditEntryDialog extends StatelessWidget {
const EditEntryDialog({ const EditEntryDialog({
this.category, this.category,
this.entry, this.entry,
}); Key key,
}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

@ -11,6 +11,8 @@ import '../app.dart';
import 'categories_dropdown.dart'; import 'categories_dropdown.dart';
class NewEntryForm extends StatefulWidget { class NewEntryForm extends StatefulWidget {
const NewEntryForm({Key key}) : super(key: key);
@override @override
_NewEntryFormState createState() => _NewEntryFormState(); _NewEntryFormState createState() => _NewEntryFormState();
} }
@ -58,7 +60,8 @@ class EditEntryForm extends StatefulWidget {
const EditEntryForm({ const EditEntryForm({
@required this.entry, @required this.entry,
@required this.onDone, @required this.onDone,
}); Key key,
}) : super(key: key);
@override @override
_EditEntryFormState createState() => _EditEntryFormState(); _EditEntryFormState createState() => _EditEntryFormState();

@ -43,7 +43,8 @@ class AdaptiveScaffold extends StatefulWidget {
@required this.destinations, @required this.destinations,
this.onNavigationIndexChange, this.onNavigationIndexChange,
this.floatingActionButton, this.floatingActionButton,
}); Key key,
}) : super(key: key);
@override @override
_AdaptiveScaffoldState createState() => _AdaptiveScaffoldState(); _AdaptiveScaffoldState createState() => _AdaptiveScaffoldState();

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

@ -10,19 +10,21 @@ import 'package:platform_channels/src/pet_list_screen.dart';
import 'package:platform_channels/src/platform_image_demo.dart'; import 'package:platform_channels/src/platform_image_demo.dart';
void main() { void main() {
runApp(PlatformChannelSample()); runApp(const PlatformChannelSample());
} }
class PlatformChannelSample extends StatelessWidget { class PlatformChannelSample extends StatelessWidget {
const PlatformChannelSample({Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return MaterialApp(
routes: { routes: {
'/methodChannelDemo': (context) => MethodChannelDemo(), '/methodChannelDemo': (context) => const MethodChannelDemo(),
'/eventChannelDemo': (context) => EventChannelDemo(), '/eventChannelDemo': (context) => const EventChannelDemo(),
'/platformImageDemo': (context) => PlatformImageDemo(), '/platformImageDemo': (context) => const PlatformImageDemo(),
'/petListScreen': (context) => PetListScreen(), '/petListScreen': (context) => const PetListScreen(),
'/addPetDetails': (context) => AddPetDetails(), '/addPetDetails': (context) => const AddPetDetails(),
}, },
title: 'Platform Channel Sample', title: 'Platform Channel Sample',
theme: ThemeData( theme: ThemeData(
@ -30,7 +32,7 @@ class PlatformChannelSample extends StatelessWidget {
backgroundColor: Colors.blue[500], backgroundColor: Colors.blue[500],
), ),
), ),
home: HomePage(), home: const HomePage(),
); );
} }
} }
@ -62,6 +64,8 @@ List<DemoInfo> demoList = [
]; ];
class HomePage extends StatelessWidget { class HomePage extends StatelessWidget {
const HomePage({Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@ -79,7 +83,7 @@ class HomePage extends StatelessWidget {
class DemoTile extends StatelessWidget { class DemoTile extends StatelessWidget {
final DemoInfo demoInfo; final DemoInfo demoInfo;
const DemoTile(this.demoInfo); const DemoTile(this.demoInfo, {Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

@ -10,6 +10,8 @@ import 'package:platform_channels/src/pet_list_message_channel.dart';
/// The widget uses [TextField] and [RadioListTile] to take the [PetDetails.breed] and /// The widget uses [TextField] and [RadioListTile] to take the [PetDetails.breed] and
/// [PetDetails.petType] from the user respectively. /// [PetDetails.petType] from the user respectively.
class AddPetDetails extends StatefulWidget { class AddPetDetails extends StatefulWidget {
const AddPetDetails({Key? key}) : super(key: key);
@override @override
_AddPetDetailsState createState() => _AddPetDetailsState(); _AddPetDetailsState createState() => _AddPetDetailsState();
} }

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

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

@ -9,6 +9,8 @@ import 'package:platform_channels/src/pet_list_message_channel.dart';
/// Demonstrates how to use [BasicMessageChannel] to send & receive the platform /// Demonstrates how to use [BasicMessageChannel] to send & receive the platform
/// Message. /// Message.
class PetListScreen extends StatefulWidget { class PetListScreen extends StatefulWidget {
const PetListScreen({Key? key}) : super(key: key);
@override @override
_PetListScreenState createState() => _PetListScreenState(); _PetListScreenState createState() => _PetListScreenState();
} }
@ -59,7 +61,7 @@ class _PetListScreenState extends State<PetListScreen> {
class BuildPetList extends StatelessWidget { class BuildPetList extends StatelessWidget {
final List<PetDetails> petList; final List<PetDetails> petList;
const BuildPetList(this.petList); const BuildPetList(this.petList, {Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

@ -13,6 +13,8 @@ import 'package:platform_channels/src/image_basic_message_channel.dart';
/// The widget uses [Image.memory] to display the image obtained from the /// The widget uses [Image.memory] to display the image obtained from the
/// platform. /// platform.
class PlatformImageDemo extends StatefulWidget { class PlatformImageDemo extends StatefulWidget {
const PlatformImageDemo({Key? key}) : super(key: key);
@override @override
_PlatformImageDemoState createState() => _PlatformImageDemoState(); _PlatformImageDemoState createState() => _PlatformImageDemoState();
} }

@ -9,7 +9,7 @@ import 'package:platform_channels/main.dart';
void main() { void main() {
group('HomePage tests', () { group('HomePage tests', () {
testWidgets('HomePage has multiple Text widgets', (tester) async { testWidgets('HomePage has multiple Text widgets', (tester) async {
await tester.pumpWidget(MaterialApp( await tester.pumpWidget(const MaterialApp(
home: HomePage(), home: HomePage(),
)); ));

@ -20,7 +20,7 @@ void main() {
}); });
testWidgets('Enter pet details', (tester) async { testWidgets('Enter pet details', (tester) async {
await tester.pumpWidget(MaterialApp(home: AddPetDetails())); await tester.pumpWidget(const MaterialApp(home: AddPetDetails()));
// Enter the breed of cat. // Enter the breed of cat.
await tester.enterText(find.byType(TextField), 'Persian'); await tester.enterText(find.byType(TextField), 'Persian');

@ -49,7 +49,7 @@ void main() {
testWidgets('EventChannel AccelerometerReadings Stream test', testWidgets('EventChannel AccelerometerReadings Stream test',
(tester) async { (tester) async {
await tester.pumpWidget(MaterialApp( await tester.pumpWidget(const MaterialApp(
home: EventChannelDemo(), home: EventChannelDemo(),
)); ));

@ -26,7 +26,7 @@ void main() {
}); });
testWidgets('MethodChannelDemo count test', (tester) async { testWidgets('MethodChannelDemo count test', (tester) async {
await tester.pumpWidget(MaterialApp( await tester.pumpWidget(const MaterialApp(
home: MethodChannelDemo(), home: MethodChannelDemo(),
)); ));

@ -20,7 +20,7 @@ void main() {
}); });
testWidgets('Platform Image test', (tester) async { testWidgets('Platform Image test', (tester) async {
await tester.pumpWidget(MaterialApp( await tester.pumpWidget(const MaterialApp(
home: PlatformImageDemo(), home: PlatformImageDemo(),
)); ));

@ -17,4 +17,5 @@ linter:
test_types_in_equals: true test_types_in_equals: true
throw_in_finally: true throw_in_finally: true
unnecessary_statements: true unnecessary_statements: true
# Tests fail if we enforce `use_key_in_widget_constructors`
use_key_in_widget_constructors: false use_key_in_widget_constructors: false

@ -17,4 +17,3 @@ linter:
test_types_in_equals: true test_types_in_equals: true
throw_in_finally: true throw_in_finally: true
unnecessary_statements: true unnecessary_statements: true
use_key_in_widget_constructors: false

@ -8,10 +8,12 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
void main() { void main() {
runApp(PlatformView()); runApp(const PlatformView());
} }
class PlatformView extends StatelessWidget { class PlatformView extends StatelessWidget {
const PlatformView({Key key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return MaterialApp(

@ -17,4 +17,3 @@ linter:
test_types_in_equals: true test_types_in_equals: true
throw_in_finally: true throw_in_finally: true
unnecessary_statements: true unnecessary_statements: true
use_key_in_widget_constructors: false

@ -18,7 +18,7 @@ void main() {
// can own Counter's lifecycle, making sure to call `dispose` // can own Counter's lifecycle, making sure to call `dispose`
// when not needed anymore. // when not needed anymore.
create: (context) => Counter(), create: (context) => Counter(),
child: MyApp(), child: const MyApp(),
), ),
); );
} }
@ -37,6 +37,8 @@ class Counter with ChangeNotifier {
} }
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return MaterialApp(
@ -44,12 +46,14 @@ class MyApp extends StatelessWidget {
theme: ThemeData( theme: ThemeData(
primarySwatch: Colors.blue, primarySwatch: Colors.blue,
), ),
home: MyHomePage(), home: const MyHomePage(),
); );
} }
} }
class MyHomePage extends StatelessWidget { class MyHomePage extends StatelessWidget {
const MyHomePage({Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(

@ -13,7 +13,7 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
ChangeNotifierProvider( ChangeNotifierProvider(
create: (context) => Counter(), create: (context) => Counter(),
child: MyApp(), child: const MyApp(),
), ),
); );

@ -17,4 +17,3 @@ linter:
test_types_in_equals: true test_types_in_equals: true
throw_in_finally: true throw_in_finally: true
unnecessary_statements: true unnecessary_statements: true
use_key_in_widget_constructors: false

@ -12,10 +12,12 @@ import 'package:provider_shopper/screens/catalog.dart';
import 'package:provider_shopper/screens/login.dart'; import 'package:provider_shopper/screens/login.dart';
void main() { void main() {
runApp(MyApp()); runApp(const MyApp());
} }
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// Using MultiProvider is convenient when providing multiple objects. // Using MultiProvider is convenient when providing multiple objects.
@ -41,9 +43,9 @@ class MyApp extends StatelessWidget {
theme: appTheme, theme: appTheme,
initialRoute: '/', initialRoute: '/',
routes: { routes: {
'/': (context) => MyLogin(), '/': (context) => const MyLogin(),
'/catalog': (context) => MyCatalog(), '/catalog': (context) => const MyCatalog(),
'/cart': (context) => MyCart(), '/cart': (context) => const MyCart(),
}, },
), ),
); );

@ -7,6 +7,8 @@ import 'package:provider/provider.dart';
import 'package:provider_shopper/models/cart.dart'; import 'package:provider_shopper/models/cart.dart';
class MyCart extends StatelessWidget { class MyCart extends StatelessWidget {
const MyCart({Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(

@ -8,6 +8,8 @@ import 'package:provider_shopper/models/cart.dart';
import 'package:provider_shopper/models/catalog.dart'; import 'package:provider_shopper/models/catalog.dart';
class MyCatalog extends StatelessWidget { class MyCatalog extends StatelessWidget {
const MyCatalog({Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(

@ -5,6 +5,8 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class MyLogin extends StatelessWidget { class MyLogin extends StatelessWidget {
const MyLogin({Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(

@ -24,7 +24,7 @@ Widget createCartScreen() => MultiProvider(
}, },
), ),
], ],
child: MaterialApp( child: const MaterialApp(
home: MyCart(), home: MyCart(),
), ),
); );

@ -21,7 +21,7 @@ Widget createCatalogScreen() => MultiProvider(
}, },
), ),
], ],
child: MaterialApp( child: const MaterialApp(
home: MyCatalog(), home: MyCatalog(),
), ),
); );

@ -26,8 +26,8 @@ void main() {
child: MaterialApp( child: MaterialApp(
initialRoute: '/', initialRoute: '/',
routes: { routes: {
'/': (context) => MyLogin(), '/': (context) => const MyLogin(),
'/catalog': (context) => MyCatalog(), '/catalog': (context) => const MyCatalog(),
}, },
), ),
)); ));

@ -9,7 +9,7 @@ import 'package:provider_shopper/main.dart';
void main() { void main() {
testWidgets('smoke test', (tester) async { testWidgets('smoke test', (tester) async {
// Build our app and trigger a frame. // Build our app and trigger a frame.
await tester.pumpWidget(MyApp()); await tester.pumpWidget(const MyApp());
// Navigating through login page. // Navigating through login page.
await tester.tap(find.text('ENTER')); await tester.tap(find.text('ENTER'));

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

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

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

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

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

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

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

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

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

@ -17,4 +17,3 @@ linter:
test_types_in_equals: true test_types_in_equals: true
throw_in_finally: true throw_in_finally: true
unnecessary_statements: true unnecessary_statements: true
use_key_in_widget_constructors: false

@ -18,7 +18,7 @@ void main() {
]); ]);
runApp( runApp(
RootRestorationScope( const RootRestorationScope(
restorationId: 'root', restorationId: 'root',
child: VeggieApp(), child: VeggieApp(),
), ),
@ -26,6 +26,8 @@ void main() {
} }
class VeggieApp extends StatefulWidget { class VeggieApp extends StatefulWidget {
const VeggieApp({Key key}) : super(key: key);
@override @override
State<StatefulWidget> createState() => _VeggieAppState(); State<StatefulWidget> createState() => _VeggieAppState();
} }

@ -13,7 +13,7 @@ import 'package:veggieseasons/widgets/close_button.dart';
import 'package:veggieseasons/widgets/trivia.dart'; import 'package:veggieseasons/widgets/trivia.dart';
class ServingInfoChart extends StatelessWidget { class ServingInfoChart extends StatelessWidget {
const ServingInfoChart(this.veggie, this.prefs); const ServingInfoChart(this.veggie, this.prefs, {Key key}) : super(key: key);
final Veggie veggie; final Veggie veggie;
@ -158,7 +158,7 @@ class ServingInfoChart extends StatelessWidget {
class InfoView extends StatelessWidget { class InfoView extends StatelessWidget {
final int id; final int id;
const InfoView(this.id); const InfoView(this.id, {Key key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -239,7 +239,7 @@ class DetailsScreen extends StatefulWidget {
final int id; final int id;
final String restorationId; final String restorationId;
const DetailsScreen({this.id, this.restorationId}); const DetailsScreen({this.id, this.restorationId, Key key}) : super(key: key);
static String show(NavigatorState navigator, int veggieId) { static String show(NavigatorState navigator, int veggieId) {
return navigator.restorablePush<void>(_routeBuilder, arguments: veggieId); return navigator.restorablePush<void>(_routeBuilder, arguments: veggieId);

@ -80,7 +80,7 @@ class _ColorChangingIconState
/// A simple "close this modal" button that invokes a callback when pressed. /// A simple "close this modal" button that invokes a callback when pressed.
class CloseButton extends StatefulWidget { class CloseButton extends StatefulWidget {
const CloseButton(this.onPressed); const CloseButton(this.onPressed, {Key key}) : super(key: key);
final VoidCallback onPressed; final VoidCallback onPressed;

@ -14,7 +14,7 @@ import 'settings_item.dart';
// See https://github.com/flutter/flutter/projects/29 for more info. // See https://github.com/flutter/flutter/projects/29 for more info.
class SettingsGroupHeader extends StatelessWidget { class SettingsGroupHeader extends StatelessWidget {
const SettingsGroupHeader(this.title); const SettingsGroupHeader(this.title, {Key key}) : super(key: key);
final String title; final String title;
@ -35,7 +35,7 @@ class SettingsGroupHeader extends StatelessWidget {
} }
class SettingsGroupFooter extends StatelessWidget { class SettingsGroupFooter extends StatelessWidget {
const SettingsGroupFooter(this.title); const SettingsGroupFooter(this.title, {Key key}) : super(key: key);
final String title; final String title;
@ -58,8 +58,10 @@ class SettingsGroup extends StatelessWidget {
@required this.items, @required this.items,
this.header, this.header,
this.footer, this.footer,
Key key,
}) : assert(items != null), }) : assert(items != null),
assert(items.isNotEmpty); assert(items.isNotEmpty),
super(key: key);
final List<SettingsItem> items; final List<SettingsItem> items;
final Widget header; final Widget header;

@ -11,7 +11,7 @@ class TriviaView extends StatefulWidget {
final int id; final int id;
final String restorationId; final String restorationId;
const TriviaView({this.id, this.restorationId}); const TriviaView({this.id, this.restorationId, Key key}) : super(key: key);
@override @override
_TriviaViewState createState() => _TriviaViewState(); _TriviaViewState createState() => _TriviaViewState();

@ -14,7 +14,8 @@ class FrostyBackground extends StatelessWidget {
this.color, this.color,
this.intensity = 25, this.intensity = 25,
this.child, this.child,
}); Key key,
}) : super(key: key);
final Color color; final Color color;
final double intensity; final double intensity;
@ -105,7 +106,9 @@ class _PressableCardState extends State<PressableCard> {
} }
class VeggieCard extends StatelessWidget { class VeggieCard extends StatelessWidget {
const VeggieCard(this.veggie, this.isInSeason, this.isPreferredCategory); const VeggieCard(this.veggie, this.isInSeason, this.isPreferredCategory,
{Key key})
: super(key: key);
/// Veggie to be displayed by the card. /// Veggie to be displayed by the card.
final Veggie veggie; final Veggie veggie;

@ -12,7 +12,9 @@ class ZoomClipAssetImage extends StatelessWidget {
{@required this.zoom, {@required this.zoom,
this.height, this.height,
this.width, this.width,
@required this.imageAsset}); @required this.imageAsset,
Key key})
: super(key: key);
final double zoom; final double zoom;
final double height; final double height;
@ -43,7 +45,7 @@ class ZoomClipAssetImage extends StatelessWidget {
class VeggieHeadline extends StatelessWidget { class VeggieHeadline extends StatelessWidget {
final Veggie veggie; final Veggie veggie;
const VeggieHeadline(this.veggie); const VeggieHeadline(this.veggie, {Key key}) : super(key: key);
List<Widget> _buildSeasonDots(List<Season> seasons) { List<Widget> _buildSeasonDots(List<Season> seasons) {
var widgets = <Widget>[]; var widgets = <Widget>[];

@ -16,7 +16,7 @@ void main() {
AppState.debugCurrentSeason = Season.autumn; AppState.debugCurrentSeason = Season.autumn;
await tester.pumpWidget( await tester.pumpWidget(
RootRestorationScope( const RootRestorationScope(
restorationId: 'root', restorationId: 'root',
child: VeggieApp(), child: VeggieApp(),
), ),

@ -17,4 +17,3 @@ linter:
test_types_in_equals: true test_types_in_equals: true
throw_in_finally: true throw_in_finally: true
unnecessary_statements: true unnecessary_statements: true
use_key_in_widget_constructors: false

@ -5,7 +5,8 @@ class Cook extends StatefulWidget {
final String? img; final String? img;
final String? nme; final String? nme;
const Cook(this.dr, this.img, this.nme); const Cook(this.dr, this.img, this.nme, {Key? key}) : super(key: key);
@override @override
CState createState() => CState(); CState createState() => CState();
} }

@ -1423,7 +1423,8 @@ class SwiperPluginView extends StatelessWidget {
final SwiperPlugin plugin; final SwiperPlugin plugin;
final SwiperPluginConfig config; final SwiperPluginConfig config;
const SwiperPluginView(this.plugin, this.config); const SwiperPluginView(this.plugin, this.config, {Key? key})
: super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

@ -5,16 +5,17 @@ import 'package:http/http.dart' as http;
import 'cook.dart'; import 'cook.dart';
import 'flutter_swiper.dart'; import 'flutter_swiper.dart';
void main() => runApp(MyApp()); void main() => runApp(const MyApp());
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(context) {
final _themeData = ThemeData( final _themeData = ThemeData(
brightness: Brightness.light, brightness: Brightness.light,
iconTheme: const IconThemeData(color: Colors.red), iconTheme: const IconThemeData(color: Colors.red),
); );
@override
Widget build(context) {
return MaterialApp( return MaterialApp(
theme: _themeData.copyWith( theme: _themeData.copyWith(
colorScheme: _themeData.colorScheme.copyWith( colorScheme: _themeData.colorScheme.copyWith(
@ -22,11 +23,13 @@ class MyApp extends StatelessWidget {
), ),
), ),
title: "Filipino Cuisine", title: "Filipino Cuisine",
home: Home()); home: const Home());
} }
} }
class Home extends StatefulWidget { class Home extends StatefulWidget {
const Home({Key? key}) : super(key: key);
@override @override
HState createState() => HState(); HState createState() => HState();
} }

@ -141,7 +141,8 @@ class ParallaxColor extends StatefulWidget {
required this.colors, required this.colors,
required this.info, required this.info,
required this.child, required this.child,
}); Key? key,
}) : super(key: key);
@override @override
State<StatefulWidget> createState() { State<StatefulWidget> createState() {
@ -159,7 +160,9 @@ class ParallaxContainer extends StatelessWidget {
{required this.child, {required this.child,
required this.position, required this.position,
this.translationFactor = 100.0, this.translationFactor = 100.0,
this.opacityFactor = 1.0}); this.opacityFactor = 1.0,
Key? key})
: super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -178,13 +181,14 @@ class ParallaxImage extends StatelessWidget {
final double imageFactor; final double imageFactor;
ParallaxImage.asset(String name, ParallaxImage.asset(String name,
{required double position, this.imageFactor = 0.3}) {required double position, this.imageFactor = 0.3, Key? key})
: image = Image.asset(name, : image = Image.asset(name,
fit: BoxFit.cover, fit: BoxFit.cover,
alignment: FractionalOffset( alignment: FractionalOffset(
0.5 + position * imageFactor, 0.5 + position * imageFactor,
0.5, 0.5,
)); )),
super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

@ -14,7 +14,7 @@ packages:
name: characters name: characters
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.0" version: "1.2.0"
charcode: charcode:
dependency: transitive dependency: transitive
description: description:

@ -19,4 +19,3 @@ linter:
test_types_in_equals: true test_types_in_equals: true
throw_in_finally: true throw_in_finally: true
unnecessary_statements: true unnecessary_statements: true
use_key_in_widget_constructors: false

Loading…
Cancel
Save