Skip to content

Commit 4e120d7

Browse files
chore: update linter and apply new rules (#12)
* chore: update linter and apply new rules * update example to support new linter rules
1 parent 9d9be0a commit 4e120d7

File tree

11 files changed

+93
-79
lines changed

11 files changed

+93
-79
lines changed

analysis_options.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include: package:very_good_analysis/analysis_options.yaml
1+
include: package:very_good_analysis/analysis_options.2.3.0.yaml

example/analysis_options.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
include: package:very_good_analysis/analysis_options.yaml
1+
include: package:very_good_analysis/analysis_options.2.3.0.yaml
22
linter:
33
rules:
44
public_member_api_docs: false

example/lib/app.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
import 'package:example/ui/ui.dart';
12
import 'package:flutter/material.dart';
23

3-
import 'ui/ui.dart';
4-
54
class App extends StatelessWidget {
65
const App({Key? key}) : super(key: key);
76

example/lib/ui/home_screen.dart

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ import 'dart:io';
33
import 'package:example/ui/ui.dart';
44
import 'package:flutter/material.dart';
55

6-
class HomeScreen extends StatelessWidget {
6+
class HomeScreen extends StatefulWidget {
77
const HomeScreen({Key? key}) : super(key: key);
88

9+
@override
10+
_HomeScreenState createState() => _HomeScreenState();
11+
}
12+
13+
class _HomeScreenState extends State<HomeScreen> {
914
Future<void> _showPincodeScreen(BuildContext context) async {
1015
final result = await Navigator.of(context).push(PincodeScreen.route());
1116

@@ -17,14 +22,16 @@ class HomeScreen extends StatelessWidget {
1722
snackBarContent = 'Pincode is "$result" 🔒';
1823
}
1924

20-
ScaffoldMessenger.of(context)
21-
..removeCurrentSnackBar()
22-
..showSnackBar(
23-
SnackBar(
24-
behavior: SnackBarBehavior.floating,
25-
content: Text(snackBarContent),
26-
),
27-
);
25+
if (mounted) {
26+
ScaffoldMessenger.of(context)
27+
..removeCurrentSnackBar()
28+
..showSnackBar(
29+
SnackBar(
30+
behavior: SnackBarBehavior.floating,
31+
content: Text(snackBarContent),
32+
),
33+
);
34+
}
2835
}
2936

3037
Future<void> _showQuizDialog(BuildContext context) async {
@@ -40,14 +47,16 @@ class HomeScreen extends StatelessWidget {
4047
snackBarContent = 'Hamburger all the way! 🍔';
4148
}
4249

43-
ScaffoldMessenger.of(context)
44-
..removeCurrentSnackBar()
45-
..showSnackBar(
46-
SnackBar(
47-
behavior: SnackBarBehavior.floating,
48-
content: Text(snackBarContent),
49-
),
50-
);
50+
if (mounted) {
51+
ScaffoldMessenger.of(context)
52+
..removeCurrentSnackBar()
53+
..showSnackBar(
54+
SnackBar(
55+
behavior: SnackBarBehavior.floating,
56+
content: Text(snackBarContent),
57+
),
58+
);
59+
}
5160
}
5261

5362
@override
@@ -64,17 +73,15 @@ class HomeScreen extends StatelessWidget {
6473
textAlign: TextAlign.center,
6574
child: SingleChildScrollView(
6675
child: Padding(
67-
padding: const EdgeInsets.all(32.0),
76+
padding: const EdgeInsets.all(32),
6877
child: Column(
69-
crossAxisAlignment: CrossAxisAlignment.center,
7078
mainAxisAlignment: MainAxisAlignment.center,
71-
mainAxisSize: MainAxisSize.max,
7279
children: [
7380
Text(
7481
'This is an example app showcasing the Mockingjay library.',
7582
style: theme.textTheme.headline6,
7683
),
77-
const SizedBox(height: 8.0),
84+
const SizedBox(height: 8),
7885
Text.rich(
7986
TextSpan(
8087
children: [
@@ -97,7 +104,7 @@ class HomeScreen extends StatelessWidget {
97104
),
98105
style: TextStyle(color: theme.disabledColor),
99106
),
100-
const SizedBox(height: 32.0),
107+
const SizedBox(height: 32),
101108
TextButton.icon(
102109
key: const Key('homeScreen_showPincodeScreen_textButton'),
103110
onPressed: () => _showPincodeScreen(context),

example/lib/ui/pincode_screen.dart

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,24 +62,21 @@ class _PincodeScreenState extends State<PincodeScreen> {
6262
textAlign: TextAlign.center,
6363
child: SingleChildScrollView(
6464
child: Padding(
65-
padding: const EdgeInsets.all(32.0),
65+
padding: const EdgeInsets.all(32),
6666
child: Column(
67-
crossAxisAlignment: CrossAxisAlignment.center,
6867
mainAxisAlignment: MainAxisAlignment.center,
69-
mainAxisSize: MainAxisSize.max,
7068
children: [
7169
const Text('Enter a pincode to continue.'),
72-
const SizedBox(height: 32.0),
70+
const SizedBox(height: 32),
7371
TextField(
7472
autofocus: true,
7573
minLines: 1,
76-
maxLines: 1,
7774
maxLength: 6,
7875
maxLengthEnforcement: MaxLengthEnforcement.enforced,
7976
obscureText: true,
8077
style: TextStyle(
8178
fontFamily: monospaceFontFamily,
82-
fontSize: 48.0,
79+
fontSize: 48,
8380
),
8481
decoration: InputDecoration(
8582
errorText: _errorText,

example/pubspec.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@ environment:
88
flutter: ">=1.17.0"
99

1010
dependencies:
11+
bloc: ^7.0.0
12+
equatable: ^2.0.3
1113
flutter:
1214
sdk: flutter
15+
flutter_bloc: ^7.1.0
1316

1417
dev_dependencies:
18+
bloc_test: ^8.1.0
1519
flutter_test:
1620
sdk: flutter
17-
mocktail: ^0.1.4
18-
very_good_analysis: 2.1.2
1921
mockingjay:
2022
path: ../
23+
mocktail: ^0.1.4
24+
very_good_analysis: ^2.3.0
2125

2226
flutter:
2327
uses-material-design: true

lib/src/mock_navigator.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class MockNavigatorProvider extends Navigator {
2929

3030
@override
3131
RouteFactory? get onGenerateRoute {
32-
return (_) => MaterialPageRoute(builder: (_) => child);
32+
return (_) => MaterialPageRoute<dynamic>(builder: (_) => child);
3333
}
3434
}
3535

@@ -41,7 +41,7 @@ class MockNavigator extends Mock
4141
implements NavigatorState {
4242
/// {@macro mock_navigator}
4343
MockNavigator() {
44-
registerFallbackValue(_FakeRoute());
44+
registerFallbackValue(_FakeRoute<dynamic>());
4545
}
4646
}
4747

@@ -64,10 +64,10 @@ class _MockNavigatorState extends NavigatorState {
6464

6565
final MockNavigator _navigator;
6666

67-
Widget? _child;
67+
late Widget _child;
6868

6969
@override
70-
Widget build(BuildContext context) => _child!;
70+
Widget build(BuildContext context) => _child;
7171

7272
@override
7373
Future<T?> push<T extends Object?>(Route<T> route) {

pubspec.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
name: mockingjay
2-
description: A package that makes it easy to mock, test and verify navigation calls in Flutter.
2+
description: A package that makes it easy to mock, test and verify navigation
3+
calls in Flutter.
34
version: 0.1.0
45
homepage: https://github.com/VeryGoodOpenSource/mockingjay
56

@@ -10,10 +11,10 @@ environment:
1011
dependencies:
1112
flutter:
1213
sdk: flutter
13-
test: ^1.16.8
1414
mocktail: ^0.1.4
15+
test: ^1.16.8
1516

1617
dev_dependencies:
1718
flutter_test:
1819
sdk: flutter
19-
very_good_analysis: ^2.1.2
20+
very_good_analysis: ^2.3.0

test/src/example_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class MyHomePage extends StatelessWidget {
1919
class MySettingsPage extends StatelessWidget {
2020
const MySettingsPage({Key? key}) : super(key: key);
2121

22-
static Route route() {
22+
static Route<void> route() {
2323
return MaterialPageRoute(
2424
builder: (_) => const MySettingsPage(),
2525
settings: const RouteSettings(name: '/settings'),

test/src/matchers_test.dart

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@ import 'package:flutter/material.dart';
22
import 'package:flutter_test/flutter_test.dart';
33
import 'package:mockingjay/mockingjay.dart';
44

5+
Future<void> expectToFail(
6+
dynamic actual,
7+
Matcher matcher, {
8+
required String withMessage,
9+
}) async {
10+
try {
11+
await expectLater(actual, matcher);
12+
fail('TestFailure expected but not thrown');
13+
} on TestFailure catch (error) {
14+
expect(error.message, contains(withMessage));
15+
}
16+
}
17+
518
void main() {
619
group('Matchers', () {
720
group('isRoute', () {
@@ -14,66 +27,72 @@ void main() {
1427

1528
group('without arguments', () {
1629
test('matches any route', () {
17-
expect(createRoute(), isRoute());
18-
expect(createRoute<String>(), isRoute());
19-
expect(createRoute('/test'), isRoute());
20-
expect(createRoute<String>('/test'), isRoute());
30+
expect(createRoute<dynamic>(), isRoute<dynamic>());
31+
expect(createRoute<String>(), isRoute<dynamic>());
32+
expect(createRoute<dynamic>('/test'), isRoute<dynamic>());
33+
expect(createRoute<String>('/test'), isRoute<dynamic>());
2134
});
2235

2336
test('does not match anything that is not a route', () {
24-
expectToFail(1, isRoute(), withMessage: 'is not a route');
25-
expectToFail('a', isRoute(), withMessage: 'is not a route');
26-
expectToFail(null, isRoute(), withMessage: 'is not a route');
37+
expectToFail(1, isRoute<dynamic>(), withMessage: 'is not a route');
38+
expectToFail('a', isRoute<dynamic>(), withMessage: 'is not a route');
39+
expectToFail(null, isRoute<dynamic>(), withMessage: 'is not a route');
2740
expectToFail(
2841
const SizedBox(),
29-
isRoute(),
42+
isRoute<dynamic>(),
3043
withMessage: 'is not a route',
3144
);
3245
});
3346
});
3447

3548
group('with name argument', () {
3649
test('matches any route with correct name', () {
37-
expect(createRoute('/test'), isRoute(named: '/test'));
38-
expect(createRoute<String>('/test'), isRoute(named: '/test'));
50+
expect(
51+
createRoute<dynamic>('/test'),
52+
isRoute<dynamic>(named: '/test'),
53+
);
54+
expect(
55+
createRoute<String>('/test'),
56+
isRoute<dynamic>(named: '/test'),
57+
);
3958
});
4059

4160
test('does not match anything that is not a route with that name', () {
4261
expectToFail(
43-
createRoute(),
44-
isRoute(named: '/test'),
62+
createRoute<dynamic>(),
63+
isRoute<dynamic>(named: '/test'),
4564
withMessage:
4665
'is a route with the wrong name (actually, no name at all)',
4766
);
4867
expectToFail(
4968
createRoute<String>(),
50-
isRoute(named: '/test'),
69+
isRoute<dynamic>(named: '/test'),
5170
withMessage:
5271
'is a route with the wrong name (actually, no name at all)',
5372
);
5473
expectToFail(
55-
createRoute('/other_name'),
56-
isRoute(named: '/test'),
74+
createRoute<dynamic>('/other_name'),
75+
isRoute<dynamic>(named: '/test'),
5776
withMessage: 'is a route with the wrong name ("/other_name")',
5877
);
5978
expectToFail(
6079
1,
61-
isRoute(named: '/test'),
80+
isRoute<dynamic>(named: '/test'),
6281
withMessage: 'is not a route',
6382
);
6483
expectToFail(
6584
'a',
66-
isRoute(named: '/test'),
85+
isRoute<dynamic>(named: '/test'),
6786
withMessage: 'is not a route',
6887
);
6988
expectToFail(
7089
null,
71-
isRoute(named: '/test'),
90+
isRoute<dynamic>(named: '/test'),
7291
withMessage: 'is not a route',
7392
);
7493
expectToFail(
7594
const SizedBox(),
76-
isRoute(named: '/test'),
95+
isRoute<dynamic>(named: '/test'),
7796
withMessage: 'is not a route',
7897
);
7998
});
@@ -87,13 +106,13 @@ void main() {
87106

88107
test('does not match anything that is not a route of that type', () {
89108
expectToFail(
90-
createRoute(),
109+
createRoute<dynamic>(),
91110
isRoute<String>(),
92111
withMessage:
93112
'is a route of the wrong type (MaterialPageRoute<dynamic>)',
94113
);
95114
expectToFail(
96-
createRoute('/test'),
115+
createRoute<dynamic>('/test'),
97116
isRoute<String>(),
98117
withMessage:
99118
'is a route of the wrong type (MaterialPageRoute<dynamic>)',
@@ -116,14 +135,14 @@ void main() {
116135

117136
test('does not match anything that is not a route of that type', () {
118137
expectToFail(
119-
createRoute(),
138+
createRoute<dynamic>(),
120139
isRoute<String>(named: '/test'),
121140
withMessage:
122141
'is a route of the wrong type (MaterialPageRoute<dynamic>) '
123142
'and name (actually, no name at all)',
124143
);
125144
expectToFail(
126-
createRoute('/test'),
145+
createRoute<dynamic>('/test'),
127146
isRoute<String>(named: '/test'),
128147
withMessage:
129148
'is a route of the wrong type (MaterialPageRoute<dynamic>)',
@@ -159,16 +178,3 @@ void main() {
159178
});
160179
});
161180
}
162-
163-
Future<void> expectToFail(
164-
dynamic actual,
165-
Matcher matcher, {
166-
required String withMessage,
167-
}) async {
168-
try {
169-
await expectLater(actual, matcher);
170-
fail('TestFailure expected but not thrown');
171-
} on TestFailure catch (error) {
172-
expect(error.message, contains(withMessage));
173-
}
174-
}

0 commit comments

Comments
 (0)