Skip to content

Commit 1264b1a

Browse files
authored
Migrate to flutter_lints as effective_dart is deprecated. (#789)
* Migrate to flutter_lints * Migrate to flutter_lints * Fixed formatting
1 parent fecf2c4 commit 1264b1a

File tree

11 files changed

+72
-109
lines changed

11 files changed

+72
-109
lines changed

geolocator/analysis_options.yaml

Lines changed: 3 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,10 @@
1+
include: package:flutter_lints/flutter.yaml
2+
13
analyzer:
24
exclude:
35
# Ignore generated files
46
- '**/*.g.dart'
57
- 'lib/src/generated/*.dart'
6-
78
linter:
89
rules:
9-
# STYLE
10-
- camel_case_types
11-
- camel_case_extensions
12-
- library_names
13-
- file_names
14-
- library_prefixes
15-
- non_constant_identifier_names
16-
- constant_identifier_names # prefer
17-
- directives_ordering
18-
- lines_longer_than_80_chars # avoid
19-
- curly_braces_in_flow_control_structures
20-
21-
# DOCUMENTATION
22-
- slash_for_doc_comments
23-
- package_api_docs # prefer
24-
- public_member_api_docs # prefer
25-
#- comment_references # Unused because https://github.com/dart-lang/sdk/issues/36974
26-
27-
# USAGE
28-
- implementation_imports
29-
- avoid_relative_lib_imports # prefer
30-
- prefer_relative_imports # prefer
31-
- prefer_adjacent_string_concatenation
32-
- prefer_interpolation_to_compose_strings # prefer
33-
- unnecessary_brace_in_string_interps # avoid
34-
- prefer_collection_literals
35-
- avoid_function_literals_in_foreach_calls # avoid
36-
- prefer_iterable_whereType
37-
- prefer_function_declarations_over_variables
38-
- unnecessary_lambdas
39-
- prefer_equal_for_default_values
40-
- avoid_init_to_null
41-
- unnecessary_getters_setters
42-
#- unnecessary_getters # prefer # Disabled pending fix: https://github.com/dart-lang/linter/issues/23
43-
#- prefer_expression_function_bodies # consider
44-
- unnecessary_this
45-
- prefer_initializing_formals
46-
- type_init_formals
47-
- empty_constructor_bodies
48-
- unnecessary_new
49-
- unnecessary_const
50-
- avoid_catches_without_on_clauses # avoid
51-
- avoid_catching_errors
52-
- use_rethrow_when_possible
53-
54-
# DESIGN
55-
- use_to_and_as_if_applicable # prefer
56-
- one_member_abstracts # avoid
57-
- avoid_classes_with_only_static_members # avoid
58-
- prefer_mixin
59-
- prefer_final_fields # prefer
60-
- use_setters_to_change_properties
61-
- avoid_setters_without_getters
62-
- avoid_returning_null # avoid
63-
- avoid_returning_this # avoid
64-
- type_annotate_public_apis # prefer
65-
#- prefer_typing_uninitialized_variables # consider
66-
- omit_local_variable_types # avoid
67-
- avoid_types_on_closure_parameters # avoid
68-
- avoid_return_types_on_setters # avoid
69-
- prefer_generic_function_type_aliases
70-
- avoid_private_typedef_functions # prefer
71-
#- use_function_type_syntax_for_parameters # consider
72-
- avoid_positional_boolean_parameters # avoid
73-
- hash_and_equals
74-
- avoid_equals_and_hash_code_on_mutable_classes # avoid
75-
- avoid_null_checks_in_equality_operators
10+
- public_member_api_docs

geolocator/example/lib/main.dart

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,31 @@ final MaterialColor themeMaterialColor =
1111
const Color.fromRGBO(48, 49, 60, 1));
1212

1313
void main() {
14-
runApp(GeolocatorWidget());
14+
runApp(const GeolocatorWidget());
1515
}
1616

1717
/// Example [Widget] showing the functionalities of the geolocator plugin
1818
class GeolocatorWidget extends StatefulWidget {
19+
/// Creates a new GeolocatorWidget.
20+
const GeolocatorWidget({Key? key}) : super(key: key);
21+
1922
/// Utility method to create a page with the Baseflow templating.
2023
static ExamplePage createPage() {
21-
return ExamplePage(Icons.location_on, (context) => GeolocatorWidget());
24+
return ExamplePage(
25+
Icons.location_on, (context) => const GeolocatorWidget());
2226
}
2327

2428
@override
2529
_GeolocatorWidgetState createState() => _GeolocatorWidgetState();
2630
}
2731

2832
class _GeolocatorWidgetState extends State<GeolocatorWidget> {
29-
static final String _kLocationServicesDisabledMessage =
33+
static const String _kLocationServicesDisabledMessage =
3034
'Location services are disabled.';
31-
static final String _kPermissionDeniedMessage = 'Permission denied.';
32-
static final String _kPermissionDeniedForeverMessage =
35+
static const String _kPermissionDeniedMessage = 'Permission denied.';
36+
static const String _kPermissionDeniedForeverMessage =
3337
'Permission denied forever.';
34-
static final String _kPermissionGrantedMessage = 'Permission granted.';
38+
static const String _kPermissionGrantedMessage = 'Permission granted.';
3539

3640
final GeolocatorPlatform _geolocatorPlatform = GeolocatorPlatform.instance;
3741
final List<_PositionItem> _positionItems = <_PositionItem>[];
@@ -70,25 +74,25 @@ class _GeolocatorWidgetState extends State<GeolocatorWidget> {
7074
},
7175
itemBuilder: (context) => [
7276
if (Platform.isIOS)
73-
PopupMenuItem(
77+
const PopupMenuItem(
7478
child: Text("Get Location Accuracy"),
7579
value: 1,
7680
),
7781
if (Platform.isIOS)
78-
PopupMenuItem(
82+
const PopupMenuItem(
7983
child: Text("Request Temporary Full Accuracy"),
8084
value: 2,
8185
),
82-
PopupMenuItem(
86+
const PopupMenuItem(
8387
child: Text("Open App Settings"),
8488
value: 3,
8589
),
8690
if (Platform.isAndroid)
87-
PopupMenuItem(
91+
const PopupMenuItem(
8892
child: Text("Open Location Settings"),
8993
value: 4,
9094
),
91-
PopupMenuItem(
95+
const PopupMenuItem(
9296
child: Text("Clear"),
9397
value: 5,
9498
),
@@ -123,7 +127,7 @@ class _GeolocatorWidgetState extends State<GeolocatorWidget> {
123127
return ListTile(
124128
title: Text(positionItem.displayValue,
125129
textAlign: TextAlign.center,
126-
style: TextStyle(
130+
style: const TextStyle(
127131
color: Colors.white,
128132
fontWeight: FontWeight.bold,
129133
)),
@@ -134,7 +138,7 @@ class _GeolocatorWidgetState extends State<GeolocatorWidget> {
134138
tileColor: themeMaterialColor,
135139
title: Text(
136140
positionItem.displayValue,
137-
style: TextStyle(color: Colors.white),
141+
style: const TextStyle(color: Colors.white),
138142
),
139143
),
140144
);
@@ -148,8 +152,8 @@ class _GeolocatorWidgetState extends State<GeolocatorWidget> {
148152
FloatingActionButton(
149153
child: (_positionStreamSubscription == null ||
150154
_positionStreamSubscription!.isPaused)
151-
? Icon(Icons.play_arrow)
152-
: Icon(Icons.pause),
155+
? const Icon(Icons.play_arrow)
156+
: const Icon(Icons.pause),
153157
onPressed: _toggleListening,
154158
tooltip: (_positionStreamSubscription == null)
155159
? 'Start position updates'
@@ -160,12 +164,12 @@ class _GeolocatorWidgetState extends State<GeolocatorWidget> {
160164
),
161165
sizedBox,
162166
FloatingActionButton(
163-
child: Icon(Icons.my_location),
167+
child: const Icon(Icons.my_location),
164168
onPressed: _getCurrentPosition,
165169
),
166170
sizedBox,
167171
FloatingActionButton(
168-
child: Icon(Icons.bookmark),
172+
child: const Icon(Icons.bookmark),
169173
onPressed: _getLastKnownPosition,
170174
),
171175
],
@@ -246,7 +250,6 @@ class _GeolocatorWidgetState extends State<GeolocatorWidget> {
246250

247251
void _updatePositionList(_PositionItemType type, String displayValue) {
248252
_positionItems.add(_PositionItem(type, displayValue));
249-
print(displayValue);
250253
setState(() {});
251254
}
252255

geolocator/example/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ dependencies:
3535
dev_dependencies:
3636
flutter_test:
3737
sdk: flutter
38+
flutter_lints: ^1.0.4
3839

3940
# For information on the generic Dart part of this file, see the
4041
# following page: https://dart.dev/tools/pub/pubspec

geolocator/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ dependencies:
1717
dev_dependencies:
1818
flutter_test:
1919
sdk: flutter
20-
effective_dart: ^1.3.0
20+
flutter_lints: ^1.0.4
2121
mockito: ^5.0.0-nullsafety.7
2222
plugin_platform_interface: ^2.0.0
2323

geolocator/test/geolocator_test.dart

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,39 +67,39 @@ void main() {
6767
expect(accuracy, LocationAccuracyStatus.reduced);
6868
});
6969

70-
test('getServiceStatusStream', () async {
70+
test('getServiceStatusStream', () {
7171
when(GeolocatorPlatform.instance.getServiceStatusStream())
7272
.thenAnswer((_) => Stream.value(ServiceStatus.enabled));
7373

74-
final locationService = await Geolocator.getServiceStatusStream();
74+
final locationService = Geolocator.getServiceStatusStream();
7575

7676
expect(locationService,
7777
emitsInOrder([emits(ServiceStatus.enabled), emitsDone]));
7878
});
7979

80-
test('getPositionStream', () async {
80+
test('getPositionStream', () {
8181
when(GeolocatorPlatform.instance.getPositionStream(
8282
desiredAccuracy: LocationAccuracy.best,
8383
forceAndroidLocationManager: false,
8484
timeInterval: 0,
8585
timeLimit: null,
8686
)).thenAnswer((_) => Stream.value(mockPosition));
8787

88-
final position = await Geolocator.getPositionStream();
88+
final position = Geolocator.getPositionStream();
8989

9090
expect(position, emitsInOrder([emits(mockPosition), emitsDone]));
9191
});
9292

9393
test('getPositionStream: time interval should be set to zero if left null.',
94-
() async {
94+
() {
9595
when(GeolocatorPlatform.instance.getPositionStream(
9696
desiredAccuracy: LocationAccuracy.best,
9797
forceAndroidLocationManager: false,
9898
timeInterval: 0,
9999
timeLimit: null,
100100
)).thenAnswer((_) => Stream.value(mockPosition));
101101

102-
await Geolocator.getPositionStream(intervalDuration: null);
102+
Geolocator.getPositionStream(intervalDuration: null);
103103

104104
verify(GeolocatorPlatform.instance.getPositionStream(
105105
desiredAccuracy: LocationAccuracy.best,
@@ -113,16 +113,16 @@ void main() {
113113
test(
114114
// ignore: lines_longer_than_80_chars
115115
'getPositionStream: time interval duration should be set to milliseconds.',
116-
() async {
116+
() {
117117
when(GeolocatorPlatform.instance.getPositionStream(
118118
desiredAccuracy: LocationAccuracy.best,
119119
forceAndroidLocationManager: false,
120120
timeInterval: 10000,
121121
timeLimit: null,
122122
)).thenAnswer((_) => Stream.value(mockPosition));
123123

124-
await Geolocator.getPositionStream(
125-
intervalDuration: Duration(seconds: 10),
124+
Geolocator.getPositionStream(
125+
intervalDuration: const Duration(seconds: 10),
126126
);
127127

128128
verify(GeolocatorPlatform.instance.getPositionStream(
@@ -144,13 +144,13 @@ void main() {
144144
expect(hasOpened, true);
145145
});
146146

147-
test('distanceBetween', () async {
148-
final distance = await Geolocator.distanceBetween(0, 0, 0, 0);
147+
test('distanceBetween', () {
148+
final distance = Geolocator.distanceBetween(0, 0, 0, 0);
149149
expect(distance, 42);
150150
});
151151

152-
test('bearingBetween', () async {
153-
final bearing = await Geolocator.bearingBetween(0, 0, 0, 0);
152+
test('bearingBetween', () {
153+
final bearing = Geolocator.bearingBetween(0, 0, 0, 0);
154154
expect(bearing, 42);
155155
});
156156
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
include: package:flutter_lints/flutter.yaml
2+
3+
analyzer:
4+
exclude:
5+
# Ignore generated files
6+
- '**/*.g.dart'
7+
- 'lib/src/generated/*.dart'
8+
linter:
9+
rules:
10+
- public_member_api_docs

geolocator_web/example/lib/main.dart

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ void main() {
2020

2121
/// Example [Widget] showing the functionalities of the geolocator plugin
2222
class GeolocatorWidget extends StatefulWidget {
23+
/// Create a GeolocatorWidget.
24+
const GeolocatorWidget({Key? key}) : super(key: key);
25+
2326
/// Utility method to create a page with the Baseflow templating.
2427
static ExamplePage createPage() {
25-
return ExamplePage(Icons.location_on, (context) => GeolocatorWidget());
28+
return ExamplePage(
29+
Icons.location_on, (context) => const GeolocatorWidget());
2630
}
2731

2832
@override
@@ -58,7 +62,7 @@ class _GeolocatorWidgetState extends State<GeolocatorWidget> {
5862
return ListTile(
5963
title: Text(positionItem.displayValue,
6064
textAlign: TextAlign.center,
61-
style: TextStyle(
65+
style: const TextStyle(
6266
color: Colors.white,
6367
fontWeight: FontWeight.bold,
6468
)),
@@ -69,7 +73,7 @@ class _GeolocatorWidgetState extends State<GeolocatorWidget> {
6973
tileColor: themeMaterialColor,
7074
title: Text(
7175
positionItem.displayValue,
72-
style: TextStyle(color: Colors.white),
76+
style: const TextStyle(color: Colors.white),
7377
),
7478
),
7579
);
@@ -83,8 +87,8 @@ class _GeolocatorWidgetState extends State<GeolocatorWidget> {
8387
FloatingActionButton(
8488
child: (_positionStreamSubscription == null ||
8589
_positionStreamSubscription!.isPaused)
86-
? Icon(Icons.play_arrow)
87-
: Icon(Icons.pause),
90+
? const Icon(Icons.play_arrow)
91+
: const Icon(Icons.pause),
8892
onPressed: _toggleListening,
8993
tooltip: (_positionStreamSubscription == null)
9094
? 'Start position updates'
@@ -95,12 +99,12 @@ class _GeolocatorWidgetState extends State<GeolocatorWidget> {
9599
),
96100
buttonSpacer,
97101
FloatingActionButton(
98-
child: Icon(Icons.my_location),
102+
child: const Icon(Icons.my_location),
99103
onPressed: _getCurrentPosition,
100104
),
101105
buttonSpacer,
102106
FloatingActionButton(
103-
child: Icon(Icons.close),
107+
child: const Icon(Icons.close),
104108
onPressed: () => setState(_positionItems.clear),
105109
tooltip: 'clear',
106110
),
@@ -180,7 +184,6 @@ class _GeolocatorWidgetState extends State<GeolocatorWidget> {
180184

181185
void _updatePositionList(_PositionItemType type, String displayValue) {
182186
_positionItems.add(_PositionItem(type, displayValue));
183-
print(displayValue);
184187
setState(() {});
185188
}
186189

geolocator_web/example/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ dependencies:
3535
dev_dependencies:
3636
flutter_test:
3737
sdk: flutter
38+
flutter_lints: ^1.0.4
3839

3940
# For information on the generic Dart part of this file, see the
4041
# following page: https://dart.dev/tools/pub/pubspec

geolocator_web/lib/geolocator_web.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ class GeolocatorPlugin extends GeolocatorPlatform {
2828
);
2929
}
3030

31+
/// Creates a GeolocatorPlugin
32+
///
33+
/// This constructor is public for testing purposes only. It should not be
34+
/// used outside this class.
3135
@visibleForTesting
3236
GeolocatorPlugin.private(
3337
GeolocationManager geolocation, PermissionsManager permissions)

0 commit comments

Comments
 (0)