mirror of
https://github.com/flutter/samples.git
synced 2026-03-21 20:08:16 +00:00
Upgrading samples to flutter_lints, part 1 of n (#804)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
include: package:pedantic/analysis_options.yaml
|
||||
include: package:flutter_lints/flutter.yaml
|
||||
|
||||
analyzer:
|
||||
strong-mode:
|
||||
@@ -7,25 +7,15 @@ analyzer:
|
||||
|
||||
linter:
|
||||
rules:
|
||||
- avoid_types_on_closure_parameters
|
||||
- avoid_void_async
|
||||
- await_only_futures
|
||||
- camel_case_types
|
||||
- cancel_subscriptions
|
||||
- close_sinks
|
||||
- constant_identifier_names
|
||||
- control_flow_in_finally
|
||||
- directives_ordering
|
||||
- empty_statements
|
||||
- hash_and_equals
|
||||
- implementation_imports
|
||||
- non_constant_identifier_names
|
||||
- package_api_docs
|
||||
- package_names
|
||||
- package_prefixed_library_names
|
||||
- test_types_in_equals
|
||||
- throw_in_finally
|
||||
- unnecessary_brace_in_string_interps
|
||||
- unnecessary_getters_setters
|
||||
- unnecessary_new
|
||||
- unnecessary_statements
|
||||
avoid_types_on_closure_parameters: true
|
||||
avoid_void_async: true
|
||||
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
|
||||
|
||||
@@ -15,7 +15,7 @@ void main() {
|
||||
await tester.pumpWidget(TestingApp());
|
||||
|
||||
// Create variables for finders that are used multiple times.
|
||||
final itemFinder = find.byKey(ValueKey('text_25'));
|
||||
final itemFinder = find.byKey(const ValueKey('text_25'));
|
||||
|
||||
// Scroll until the item to be found appears.
|
||||
await tester.scrollUntilVisible(
|
||||
@@ -31,22 +31,22 @@ void main() {
|
||||
await tester.pumpWidget(TestingApp());
|
||||
|
||||
// Create a finder for the icon.
|
||||
final iconFinder = find.byKey(ValueKey('icon_0'));
|
||||
final iconFinder = find.byKey(const ValueKey('icon_0'));
|
||||
|
||||
// Tap on the icon.
|
||||
await tester.tap(iconFinder);
|
||||
await tester.pumpAndSettle(Duration(seconds: 1));
|
||||
await tester.pumpAndSettle(const Duration(seconds: 1));
|
||||
|
||||
// Verify if appropriate message appears.
|
||||
expect(find.text('Added to favorites.'), findsOneWidget);
|
||||
|
||||
// Tap on the icon again.
|
||||
await tester.tap(iconFinder);
|
||||
await tester.pumpAndSettle(Duration(seconds: 1));
|
||||
await tester.pumpAndSettle(const Duration(seconds: 1));
|
||||
|
||||
// Verify if appropriate message appears.
|
||||
expect(find.text('Removed from favorites.'), findsOneWidget);
|
||||
await tester.pumpAndSettle(Duration(seconds: 1));
|
||||
await tester.pumpAndSettle(const Duration(seconds: 1));
|
||||
});
|
||||
|
||||
testWidgets('Verifying whether item gets added to favorites',
|
||||
@@ -54,8 +54,8 @@ void main() {
|
||||
await tester.pumpWidget(TestingApp());
|
||||
|
||||
// Add item to favorites.
|
||||
await tester.tap(find.byKey(ValueKey('icon_5')));
|
||||
await tester.pumpAndSettle(Duration(seconds: 1));
|
||||
await tester.tap(find.byKey(const ValueKey('icon_5')));
|
||||
await tester.pumpAndSettle(const Duration(seconds: 1));
|
||||
|
||||
// Tap on the favorites button on the AppBar.
|
||||
// The Favorites List should appear.
|
||||
@@ -63,7 +63,10 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Check if the added item has appeared in the list.
|
||||
expect(tester.widget<Text>(find.byKey(ValueKey('favorites_text_5'))).data,
|
||||
expect(
|
||||
tester
|
||||
.widget<Text>(find.byKey(const ValueKey('favorites_text_5')))
|
||||
.data,
|
||||
equals('Item 5'));
|
||||
});
|
||||
|
||||
@@ -71,16 +74,16 @@ void main() {
|
||||
await tester.pumpWidget(TestingApp());
|
||||
|
||||
// Add item to favorites.
|
||||
await tester.tap(find.byKey(ValueKey('icon_5')));
|
||||
await tester.pumpAndSettle(Duration(seconds: 1));
|
||||
await tester.tap(find.byKey(const ValueKey('icon_5')));
|
||||
await tester.pumpAndSettle(const Duration(seconds: 1));
|
||||
|
||||
// Navigate to Favorites screen.
|
||||
await tester.tap(find.text('Favorites'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Tap on the remove icon.
|
||||
await tester.tap(find.byKey(ValueKey('remove_icon_5')));
|
||||
await tester.pumpAndSettle(Duration(seconds: 1));
|
||||
await tester.tap(find.byKey(const ValueKey('remove_icon_5')));
|
||||
await tester.pumpAndSettle(const Duration(seconds: 1));
|
||||
|
||||
// Verify if it disappears.
|
||||
expect(find.text('Item 5'), findsNothing);
|
||||
|
||||
@@ -66,7 +66,7 @@ void main() {
|
||||
for (var icon in iconKeys) {
|
||||
// Tap onto the icon.
|
||||
await tester.tap(find.byKey(ValueKey(icon)));
|
||||
await tester.pumpAndSettle(Duration(seconds: 1));
|
||||
await tester.pumpAndSettle(const Duration(seconds: 1));
|
||||
|
||||
// Verify if appropriate message appears.
|
||||
expect(find.text('Added to favorites.'), findsOneWidget);
|
||||
@@ -87,7 +87,7 @@ void main() {
|
||||
for (final iconKey in removeIconKeys) {
|
||||
// Tap onto the remove icon.
|
||||
await tester.tap(find.byKey(ValueKey(iconKey)));
|
||||
await tester.pumpAndSettle(Duration(seconds: 1));
|
||||
await tester.pumpAndSettle(const Duration(seconds: 1));
|
||||
|
||||
// Verify if appropriate message appears.
|
||||
expect(find.text('Removed from favorites.'), findsOneWidget);
|
||||
|
||||
@@ -13,7 +13,7 @@ class FavoritesPage extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Favorites'),
|
||||
title: const Text('Favorites'),
|
||||
),
|
||||
body: Consumer<Favorites>(
|
||||
builder: (context, value, child) => value.items.isNotEmpty
|
||||
@@ -23,7 +23,7 @@ class FavoritesPage extends StatelessWidget {
|
||||
itemBuilder: (context, index) =>
|
||||
FavoriteItemTile(value.items[index]),
|
||||
)
|
||||
: Center(
|
||||
: const Center(
|
||||
child: Text('No favorites added.'),
|
||||
),
|
||||
),
|
||||
@@ -52,11 +52,11 @@ class FavoriteItemTile extends StatelessWidget {
|
||||
),
|
||||
trailing: IconButton(
|
||||
key: Key('remove_icon_$itemNo'),
|
||||
icon: Icon(Icons.close),
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: () {
|
||||
Provider.of<Favorites>(context, listen: false).remove(itemNo);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Removed from favorites.'),
|
||||
duration: Duration(seconds: 1),
|
||||
),
|
||||
|
||||
@@ -14,15 +14,15 @@ class HomePage extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Testing Sample'),
|
||||
title: const Text('Testing Sample'),
|
||||
actions: <Widget>[
|
||||
TextButton.icon(
|
||||
style: TextButton.styleFrom(primary: Colors.white),
|
||||
onPressed: () {
|
||||
Navigator.pushNamed(context, FavoritesPage.routeName);
|
||||
},
|
||||
icon: Icon(Icons.favorite_border),
|
||||
label: Text('Favorites'),
|
||||
icon: const Icon(Icons.favorite_border),
|
||||
label: const Text('Favorites'),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -61,8 +61,8 @@ class ItemTile extends StatelessWidget {
|
||||
trailing: IconButton(
|
||||
key: Key('icon_$itemNo'),
|
||||
icon: favoritesList.items.contains(itemNo)
|
||||
? Icon(Icons.favorite)
|
||||
: Icon(Icons.favorite_border),
|
||||
? const Icon(Icons.favorite)
|
||||
: const Icon(Icons.favorite_border),
|
||||
onPressed: () {
|
||||
!favoritesList.items.contains(itemNo)
|
||||
? favoritesList.add(itemNo)
|
||||
@@ -72,7 +72,7 @@ class ItemTile extends StatelessWidget {
|
||||
content: Text(favoritesList.items.contains(itemNo)
|
||||
? 'Added to favorites.'
|
||||
: 'Removed from favorites.'),
|
||||
duration: Duration(seconds: 1),
|
||||
duration: const Duration(seconds: 1),
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -130,6 +130,13 @@ packages:
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
flutter_lints:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: flutter_lints
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.3"
|
||||
flutter_test:
|
||||
dependency: "direct dev"
|
||||
description: flutter
|
||||
@@ -180,6 +187,13 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.6.3"
|
||||
lints:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: lints
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.1"
|
||||
logging:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -237,7 +251,7 @@ packages:
|
||||
source: hosted
|
||||
version: "1.8.0"
|
||||
pedantic:
|
||||
dependency: "direct dev"
|
||||
dependency: transitive
|
||||
description:
|
||||
name: pedantic
|
||||
url: "https://pub.dartlang.org"
|
||||
|
||||
@@ -4,7 +4,7 @@ description: A sample that shows testing in Flutter.
|
||||
version: 1.0.0+1
|
||||
|
||||
environment:
|
||||
sdk: '>=2.12.0 <3.0.0'
|
||||
sdk: ">=2.12.0 <3.0.0"
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
@@ -19,7 +19,7 @@ dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
test: ^1.16.8
|
||||
pedantic: ^1.11.0
|
||||
flutter_lints: ^1.0.0
|
||||
|
||||
flutter:
|
||||
uses-material-design: true
|
||||
|
||||
@@ -31,7 +31,7 @@ void main() {
|
||||
expect(find.text('Item 0'), findsOneWidget);
|
||||
|
||||
// Fling i.e scroll down.
|
||||
await tester.fling(find.byType(ListView), Offset(0, -200), 3000);
|
||||
await tester.fling(find.byType(ListView), const Offset(0, -200), 3000);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Check if "Item 0" disappeared.
|
||||
@@ -46,7 +46,7 @@ void main() {
|
||||
|
||||
// Tap the first item's icon to add it to favorites.
|
||||
await tester.tap(find.byIcon(Icons.favorite_border).first);
|
||||
await tester.pumpAndSettle(Duration(seconds: 1));
|
||||
await tester.pumpAndSettle(const Duration(seconds: 1));
|
||||
|
||||
// Verify if the appropriate message is shown.
|
||||
expect(find.text('Added to favorites.'), findsOneWidget);
|
||||
@@ -57,7 +57,7 @@ void main() {
|
||||
// Tap the first item's icon which has filled icon to
|
||||
// remove it from favorites.
|
||||
await tester.tap(find.byIcon(Icons.favorite).first);
|
||||
await tester.pumpAndSettle(Duration(seconds: 1));
|
||||
await tester.pumpAndSettle(const Duration(seconds: 1));
|
||||
|
||||
// Verify if the appropriate message is shown.
|
||||
expect(find.text('Removed from favorites.'), findsOneWidget);
|
||||
|
||||
Reference in New Issue
Block a user