Skip to content

Commit dda2d89

Browse files
authored
feat: add lint rules (#1836)
add more lint rules
1 parent e0bec8b commit dda2d89

31 files changed

+85
-73
lines changed

analysis_options.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,14 @@ linter:
4242
use_if_null_to_convert_nulls_to_bools: true
4343
matching_super_parameters: true
4444
prefer_const_constructors: true
45+
use_decorated_box: true
46+
use_is_even_rather_than_modulo: true
47+
unnecessary_lambdas: true
48+
sort_pub_dependencies: true
49+
prefer_void_to_null: true
50+
unnecessary_raw_strings: true
51+
comment_references: true
52+
parameter_assignments: true
53+
avoid_unused_constructor_parameters: true
4554
# TODO: enable the following lint when all public APIs are documented
4655
# public_member_api_docs: true

benchmark/crs.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ Future<Result> timedRun(String name, dynamic Function() body) async {
3030
// If you run in JIT mode, the resulting execution times will be a lot more similar.
3131
Future<void> main() async {
3232
Logger.level = Level.all;
33-
Logger.defaultFilter = () => NoFilter();
34-
Logger.defaultPrinter = () => SimplePrinter();
33+
Logger.defaultFilter = NoFilter.new;
34+
Logger.defaultPrinter = SimplePrinter.new;
3535

3636
final results = <Result>[];
3737
const N = 100000000;

example/lib/pages/home.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class _HomePageState extends State<HomePage> {
5252
attributions: [
5353
TextSourceAttribution(
5454
'OpenStreetMap contributors',
55-
onTap: () => launchUrl(
55+
onTap: () async => launchUrl(
5656
Uri.parse('https://openstreetmap.org/copyright'),
5757
),
5858
),

example/lib/pages/moving_markers.dart

+8-15
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@ class MovingMarkersPage extends StatefulWidget {
1616
}
1717

1818
class MovingMarkersPageState extends State<MovingMarkersPage> {
19-
Marker? _marker;
20-
late final Timer _timer;
19+
late Marker _marker = _markers[_markerIndex];
20+
late final Timer _timer = Timer.periodic(const Duration(seconds: 1), (_) {
21+
setState(() {
22+
_marker = _markers[_markerIndex];
23+
_markerIndex = (_markerIndex + 1) % _markers.length;
24+
});
25+
});
2126
int _markerIndex = 0;
2227

2328
static const _markers = [
@@ -41,18 +46,6 @@ class MovingMarkersPageState extends State<MovingMarkersPage> {
4146
),
4247
];
4348

44-
@override
45-
void initState() {
46-
super.initState();
47-
_marker = _markers[_markerIndex];
48-
_timer = Timer.periodic(const Duration(seconds: 1), (_) {
49-
setState(() {
50-
_marker = _markers[_markerIndex];
51-
_markerIndex = (_markerIndex + 1) % _markers.length;
52-
});
53-
});
54-
}
55-
5649
@override
5750
void dispose() {
5851
super.dispose();
@@ -71,7 +64,7 @@ class MovingMarkersPageState extends State<MovingMarkersPage> {
7164
),
7265
children: [
7366
openStreetMapTileLayer,
74-
MarkerLayer(markers: [_marker!]),
67+
MarkerLayer(markers: [_marker]),
7568
],
7669
),
7770
);

example/lib/pages/retina.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,7 @@ class InputFieldStylizer extends TextEditingController {
210210
final Pattern pattern;
211211

212212
InputFieldStylizer(this.mapping, {String? initialValue})
213-
: pattern =
214-
RegExp(mapping.keys.map((key) => RegExp.escape(key)).join('|')),
213+
: pattern = RegExp(mapping.keys.map(RegExp.escape).join('|')),
215214
super(text: initialValue);
216215

217216
@override

example/pubspec.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ dependencies:
1212
sdk: flutter
1313
flutter_map:
1414
flutter_map_cancellable_tile_provider:
15+
flutter_map_geojson: ^1.0.6
16+
http: ^1.2.0
1517
latlong2: ^0.9.0
1618
proj4dart: ^2.1.0
17-
url_launcher: ^6.2.4
1819
shared_preferences: ^2.2.2
20+
url_launcher: ^6.2.4
1921
url_strategy: ^0.2.0
20-
http: ^1.2.0
2122
vector_math: ^2.1.4
22-
flutter_map_geojson: ^1.0.6
2323

2424
dependency_overrides:
25-
flutter_map_cancellable_tile_provider:
2625
flutter_map:
2726
path: ../
27+
flutter_map_cancellable_tile_provider:
2828

2929
dev_dependencies:
3030
flutter_lints: ^3.0.0

lib/src/gestures/interactive_flag.dart

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'package:flutter_map/flutter_map.dart';
2+
13
/// Use [InteractiveFlag] to disable / enable certain events Use
24
/// [InteractiveFlag.all] to enable all events, use [InteractiveFlag.none] to
35
/// disable all events

lib/src/gestures/map_events.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import 'package:flutter/widgets.dart';
12
import 'package:flutter_map/flutter_map.dart';
23
import 'package:latlong2/latlong.dart';
3-
import 'package:meta/meta.dart';
44

55
/// Event sources which are used to identify different types of
66
/// [MapEvent] events

lib/src/gestures/map_interactive_viewer.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ class MapInteractiveViewerState extends State<MapInteractiveViewer>
141141
bool cursorKeyboardRotationTriggerHandler(KeyEvent event) {
142142
_ckrTriggered.value = (event is KeyRepeatEvent || event is KeyDownEvent) &&
143143
(_interactionOptions.cursorKeyboardRotationOptions.isKeyTrigger ??
144-
(key) => CursorKeyboardRotationOptions.defaultTriggerKeys
145-
.contains(key))(event.logicalKey);
144+
CursorKeyboardRotationOptions
145+
.defaultTriggerKeys.contains)(event.logicalKey);
146146
return false;
147147
}
148148

lib/src/layer/attribution_layer/rich/source.dart

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
import 'package:flutter_map/flutter_map.dart';
23
import 'package:meta/meta.dart';
34

45
/// Base class for attributions that render themselves as widgets in a

lib/src/layer/attribution_layer/rich/widget.dart

+6-5
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class _RichAttributionWidgetState extends State<RichAttributionWidget> {
152152

153153
@override
154154
void dispose() {
155-
mapEventSubscription?.cancel();
155+
unawaited(mapEventSubscription?.cancel());
156156
super.dispose();
157157
}
158158

@@ -204,10 +204,11 @@ class _RichAttributionWidgetState extends State<RichAttributionWidget> {
204204
context,
205205
() {
206206
setState(() => popupExpanded = true);
207-
mapEventSubscription =
208-
MapController.of(context).mapEventStream.listen((e) {
207+
mapEventSubscription = MapController.of(context)
208+
.mapEventStream
209+
.listen((e) async {
209210
setState(() => popupExpanded = false);
210-
mapEventSubscription?.cancel();
211+
await mapEventSubscription?.cancel();
211212
});
212213
},
213214
),
@@ -225,7 +226,7 @@ class _RichAttributionWidgetState extends State<RichAttributionWidget> {
225226
context: context,
226227
isExpanded: popupExpanded,
227228
config: widget,
228-
child: Container(
229+
child: DecoratedBox(
229230
decoration: BoxDecoration(
230231
color: widget.popupBackgroundColor ??
231232
Theme.of(context).colorScheme.background,

lib/src/layer/attribution_layer/simple.dart

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
import 'package:flutter_map/flutter_map.dart';
23

34
/// A simple, classic style, attribution layer
45
///

lib/src/layer/marker_layer/marker.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Marker {
4444
/// user's perspective. Defaults to `false` if also unset by [MarkerLayer].
4545
///
4646
/// Note that this is not used to apply a custom rotation in degrees to the
47-
/// marker. Use a widget inside [builder] to perform this.
47+
/// marker. Use a widget inside [child] to perform this.
4848
final bool? rotate;
4949

5050
/// Creates a container for a [child] widget located at a geographic coordinate

lib/src/layer/marker_layer/marker_layer.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class MarkerLayer extends StatelessWidget {
2929
/// user's perspective. Defaults to `false`. Overriden by [Marker.rotate].
3030
///
3131
/// Note that this is not used to apply a custom rotation in degrees to the
32-
/// markers. Use a widget inside [Marker.builder] to perform this.
32+
/// markers. Use a widget inside [Marker.child] to perform this.
3333
final bool rotate;
3434

3535
/// Create a new [MarkerLayer] to use inside of [FlutterMap.children].

lib/src/layer/polygon_layer/polygon.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ class Polygon<R extends Object> {
179179
// Used to batch draw calls to the canvas
180180
int? _renderHashCode;
181181

182-
/// An optimized hash code dedicated to be used inside the [PolygonPainter].
182+
/// An optimized hash code dedicated to be used inside the [_PolygonPainter].
183183
int get renderHashCode => _renderHashCode ??= Object.hash(
184184
color,
185185
borderStrokeWidth,

lib/src/layer/polygon_layer/polygon_layer.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class _PolygonLayerState<R extends Object> extends State<PolygonLayer<R>> {
175175
return Earcut.triangulateRaw(
176176
List.generate(
177177
points.length * 2,
178-
(ii) => ii % 2 == 0
178+
(ii) => ii.isEven
179179
? points.elementAt(ii ~/ 2).x
180180
: points.elementAt(ii ~/ 2).y,
181181
growable: false,

lib/src/layer/tile_layer/tile_bounds/tile_bounds.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ abstract class TileBounds {
1212
final LatLngBounds? _latLngBounds;
1313

1414
/// Constructor that creates an instance of a subclass of [TileBounds]:
15-
/// [InfiniteTileBounds] if the CRS is [infinite].
15+
/// [InfiniteTileBounds] if the CRS is infinite.
1616
/// [DiscreteTileBounds] if the CRS has hard borders.
1717
/// [WrappedTileBounds] if the CRS is wrapped.
1818
factory TileBounds({

lib/src/layer/tile_layer/tile_display.dart

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import 'package:flutter/widgets.dart';
12
import 'package:flutter_map/flutter_map.dart';
2-
import 'package:meta/meta.dart';
33

44
@immutable
55
sealed class TileDisplay {
@@ -37,14 +37,12 @@ sealed class TileDisplay {
3737
/// range is (0.0 - 1.0).
3838
double startOpacity,
3939

40-
/// Opacity start value when a tile is reloaded, default 1.0. A tile reload
41-
/// will occur when the provider tile url changes and
42-
/// [TileLayer.overrideTilesWhenUrlChanges] is true. Valid range is
40+
/// Opacity start value when a tile is reloaded, default 1.0. Valid range is
4341
/// (0.0 - 1.0).
4442
double reloadStartOpacity,
4543
}) = FadeInTileDisplay._;
4644

47-
/// Output a value of type [T] dependent on [this] and its type
45+
/// Output a value of type [T] dependent on this and its type
4846
T? when<T>({
4947
T? Function(InstantaneousTileDisplay instantaneous)? instantaneous,
5048
T? Function(FadeInTileDisplay fadeIn)? fadeIn,

lib/src/layer/tile_layer/tile_error_evict_callback.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ enum EvictErrorTileStrategy {
1111
/// Evict images for tiles which failed to load and:
1212
/// - do not belong to the current zoom level AND/OR
1313
/// - are not visible, respecting the pruning buffer (the maximum of the
14-
/// [keepBuffer] and [panBuffer].
14+
/// keepBuffer and panBuffer.
1515
notVisibleRespectMargin,
1616

1717
/// Evict images for tiles which failed to load and:

lib/src/layer/tile_layer/tile_layer.dart

+6-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import 'package:flutter_map/src/layer/tile_layer/tile_image_manager.dart';
1212
import 'package:flutter_map/src/layer/tile_layer/tile_range.dart';
1313
import 'package:flutter_map/src/layer/tile_layer/tile_range_calculator.dart';
1414
import 'package:flutter_map/src/layer/tile_layer/tile_scale_calculator.dart';
15+
import 'package:http/http.dart';
1516
import 'package:http/retry.dart';
1617
import 'package:logger/logger.dart';
1718

@@ -362,7 +363,7 @@ class _TileLayerState extends State<TileLayer> with TickerProviderStateMixin {
362363
_tileUpdateSubscription = mapController.mapEventStream
363364
.map((mapEvent) => TileUpdateEvent(mapEvent: mapEvent))
364365
.transform(widget.tileUpdateTransformer)
365-
.listen((event) => _onTileUpdateEvent(event));
366+
.listen(_onTileUpdateEvent);
366367
}
367368

368369
var reloadTiles = false;
@@ -629,13 +630,13 @@ class _TileLayerState extends State<TileLayer> with TickerProviderStateMixin {
629630
required bool pruneAfterLoad,
630631
}) {
631632
final tileZoom = tileLoadRange.zoom;
632-
tileLoadRange = tileLoadRange.expand(widget.panBuffer);
633+
final expandedTileLoadRange = tileLoadRange.expand(widget.panBuffer);
633634

634635
// Build the queue of tiles to load. Marks all tiles with valid coordinates
635636
// in the tileLoadRange as current.
636637
final tileBoundsAtZoom = _tileBounds.atZoom(tileZoom);
637638
final tilesToLoad = _tileImageManager.createMissingTiles(
638-
tileLoadRange,
639+
expandedTileLoadRange,
639640
tileBoundsAtZoom,
640641
createTile: (coordinates) => _createTileImage(
641642
coordinates: coordinates,
@@ -645,7 +646,7 @@ class _TileLayerState extends State<TileLayer> with TickerProviderStateMixin {
645646
);
646647

647648
// Re-order the tiles by their distance to the center of the range.
648-
final tileCenter = tileLoadRange.center;
649+
final tileCenter = expandedTileLoadRange.center;
649650
tilesToLoad.sort(
650651
(a, b) => _distanceSq(a.coordinates, tileCenter)
651652
.compareTo(_distanceSq(b.coordinates, tileCenter)),
@@ -681,7 +682,7 @@ class _TileLayerState extends State<TileLayer> with TickerProviderStateMixin {
681682
_pruneLater?.cancel();
682683
_pruneLater = Timer(
683684
fadeIn.duration + const Duration(milliseconds: 50),
684-
() => _pruneWithCurrentCamera(),
685+
_pruneWithCurrentCamera,
685686
);
686687
});
687688
}

lib/src/layer/tile_layer/tile_provider/base_tile_provider.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ abstract class TileProvider {
140140
/// [70339807ed6b](https://github.com/Leaflet/Leaflet/commit/70339807ed6bec630ee9c2e96a9cb8356fa6bd86).
141141
/// It is never mentioned why this regex was used or changed in Leaflet.
142142
/// This regex is more permissive of the characters it allows.
143-
static final templatePlaceholderElement = RegExp(r'{([^{}]*)}');
143+
static final templatePlaceholderElement = RegExp('{([^{}]*)}');
144144

145145
/// Replaces placeholders in the form [templatePlaceholderElement] with their
146146
/// corresponding values

lib/src/layer/tile_layer/tile_provider/network_tile_provider.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class NetworkTileProvider extends TileProvider {
4343
final bool silenceExceptions;
4444

4545
/// Long living client used to make all tile requests by
46-
/// [FlutterMapNetworkImageProvider] for the duration that this provider is
46+
/// [MapNetworkImageProvider] for the duration that this provider is
4747
/// alive
4848
final BaseClient _httpClient;
4949

lib/src/layer/tile_layer/tile_range_calculator.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class TileRangeCalculator {
1212

1313
/// Calculates the visible pixel bounds at the [tileZoom] zoom level when
1414
/// viewing the map from the [viewingZoom] centered at the [center]. The
15-
/// resulting tile range is expanded by [panBuffer].
15+
/// resulting tile range is expanded by panBuffer.
1616
DiscreteTileRange calculate({
1717
// The map camera used to calculate the bounds.
1818
required MapCamera camera,

lib/src/layer/tile_layer/tile_scale_calculator.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class TileScaleCalculator {
1515
required this.tileSize,
1616
});
1717

18-
/// If [true] indicates that the TileSizeCache should be replaced.
18+
/// If true it indicates that the TileSizeCache should be replaced.
1919
bool shouldReplace(Crs crs, double tileSize) =>
2020
this.crs != crs || this.tileSize != tileSize;
2121

lib/src/map/camera/camera.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ class MapCamera {
207207
/// The current rotation value in radians
208208
double get rotationRad => rotation * degrees2Radians;
209209

210-
/// Calculates point value for the given [latLng] using this camera's
210+
/// Calculates point value for the given [latlng] using this camera's
211211
/// [crs] and [zoom] (or the provided [zoom]).
212212
Point<double> project(LatLng latlng, [double? zoom]) =>
213213
crs.latLngToPoint(latlng, zoom ?? this.zoom);

lib/src/map/camera/camera_fit.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ abstract class CameraFit {
4747
/// Allows for more fine grained boundaries when the camera is rotated. See
4848
/// https://github.com/fleaflet/flutter_map/pull/1549 for more information.
4949
///
50-
/// [inside] is not supported due to lack of implementation.
50+
/// `inside` is not supported due to lack of implementation.
5151
const factory CameraFit.coordinates({
5252
required List<LatLng> coordinates,
5353
EdgeInsets padding,

lib/src/map/controller/map_controller_impl.dart

+3-2
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,10 @@ class MapControllerImpl extends ValueNotifier<_MapControllerState>
150150
String? id,
151151
}) {
152152
// Algorithm thanks to https://github.com/tlserver/flutter_map_location_marker
153+
LatLng center = newCenter;
153154
if (offset != Offset.zero) {
154155
final newPoint = camera.project(newCenter, newZoom);
155-
newCenter = camera.unproject(
156+
center = camera.unproject(
156157
camera.rotatePoint(
157158
newPoint,
158159
newPoint - Point(offset.dx, offset.dy),
@@ -162,7 +163,7 @@ class MapControllerImpl extends ValueNotifier<_MapControllerState>
162163
}
163164

164165
MapCamera? newCamera = camera.withPosition(
165-
center: newCenter,
166+
center: center,
166167
zoom: camera.clampZoom(newZoom),
167168
);
168169

0 commit comments

Comments
 (0)