Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add lint rules #1836

Merged
merged 1 commit into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,14 @@ linter:
use_if_null_to_convert_nulls_to_bools: true
matching_super_parameters: true
prefer_const_constructors: true
use_decorated_box: true
use_is_even_rather_than_modulo: true
unnecessary_lambdas: true
sort_pub_dependencies: true
prefer_void_to_null: true
unnecessary_raw_strings: true
comment_references: true
parameter_assignments: true
avoid_unused_constructor_parameters: true
# TODO: enable the following lint when all public APIs are documented
# public_member_api_docs: true
4 changes: 2 additions & 2 deletions benchmark/crs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ Future<Result> timedRun(String name, dynamic Function() body) async {
// If you run in JIT mode, the resulting execution times will be a lot more similar.
Future<void> main() async {
Logger.level = Level.all;
Logger.defaultFilter = () => NoFilter();
Logger.defaultPrinter = () => SimplePrinter();
Logger.defaultFilter = NoFilter.new;
Logger.defaultPrinter = SimplePrinter.new;

final results = <Result>[];
const N = 100000000;
Expand Down
2 changes: 1 addition & 1 deletion example/lib/pages/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class _HomePageState extends State<HomePage> {
attributions: [
TextSourceAttribution(
'OpenStreetMap contributors',
onTap: () => launchUrl(
onTap: () async => launchUrl(
Uri.parse('https://openstreetmap.org/copyright'),
),
),
Expand Down
23 changes: 8 additions & 15 deletions example/lib/pages/moving_markers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ class MovingMarkersPage extends StatefulWidget {
}

class MovingMarkersPageState extends State<MovingMarkersPage> {
Marker? _marker;
late final Timer _timer;
late Marker _marker = _markers[_markerIndex];
late final Timer _timer = Timer.periodic(const Duration(seconds: 1), (_) {
setState(() {
_marker = _markers[_markerIndex];
_markerIndex = (_markerIndex + 1) % _markers.length;
});
});
int _markerIndex = 0;

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

@override
void initState() {
super.initState();
_marker = _markers[_markerIndex];
_timer = Timer.periodic(const Duration(seconds: 1), (_) {
setState(() {
_marker = _markers[_markerIndex];
_markerIndex = (_markerIndex + 1) % _markers.length;
});
});
}

@override
void dispose() {
super.dispose();
Expand All @@ -71,7 +64,7 @@ class MovingMarkersPageState extends State<MovingMarkersPage> {
),
children: [
openStreetMapTileLayer,
MarkerLayer(markers: [_marker!]),
MarkerLayer(markers: [_marker]),
],
),
);
Expand Down
3 changes: 1 addition & 2 deletions example/lib/pages/retina.dart
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,7 @@ class InputFieldStylizer extends TextEditingController {
final Pattern pattern;

InputFieldStylizer(this.mapping, {String? initialValue})
: pattern =
RegExp(mapping.keys.map((key) => RegExp.escape(key)).join('|')),
: pattern = RegExp(mapping.keys.map(RegExp.escape).join('|')),
super(text: initialValue);

@override
Expand Down
8 changes: 4 additions & 4 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ dependencies:
sdk: flutter
flutter_map:
flutter_map_cancellable_tile_provider:
flutter_map_geojson: ^1.0.6
http: ^1.2.0
latlong2: ^0.9.0
proj4dart: ^2.1.0
url_launcher: ^6.2.4
shared_preferences: ^2.2.2
url_launcher: ^6.2.4
url_strategy: ^0.2.0
http: ^1.2.0
vector_math: ^2.1.4
flutter_map_geojson: ^1.0.6

dependency_overrides:
flutter_map_cancellable_tile_provider:
flutter_map:
path: ../
flutter_map_cancellable_tile_provider:

dev_dependencies:
flutter_lints: ^3.0.0
Expand Down
2 changes: 2 additions & 0 deletions lib/src/gestures/interactive_flag.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:flutter_map/flutter_map.dart';

/// Use [InteractiveFlag] to disable / enable certain events Use
/// [InteractiveFlag.all] to enable all events, use [InteractiveFlag.none] to
/// disable all events
Expand Down
2 changes: 1 addition & 1 deletion lib/src/gestures/map_events.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';
import 'package:meta/meta.dart';

/// Event sources which are used to identify different types of
/// [MapEvent] events
Expand Down
4 changes: 2 additions & 2 deletions lib/src/gestures/map_interactive_viewer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ class MapInteractiveViewerState extends State<MapInteractiveViewer>
bool cursorKeyboardRotationTriggerHandler(KeyEvent event) {
_ckrTriggered.value = (event is KeyRepeatEvent || event is KeyDownEvent) &&
(_interactionOptions.cursorKeyboardRotationOptions.isKeyTrigger ??
(key) => CursorKeyboardRotationOptions.defaultTriggerKeys
.contains(key))(event.logicalKey);
CursorKeyboardRotationOptions
.defaultTriggerKeys.contains)(event.logicalKey);
return false;
}

Expand Down
1 change: 1 addition & 0 deletions lib/src/layer/attribution_layer/rich/source.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:meta/meta.dart';

/// Base class for attributions that render themselves as widgets in a
Expand Down
11 changes: 6 additions & 5 deletions lib/src/layer/attribution_layer/rich/widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class _RichAttributionWidgetState extends State<RichAttributionWidget> {

@override
void dispose() {
mapEventSubscription?.cancel();
unawaited(mapEventSubscription?.cancel());
super.dispose();
}

Expand Down Expand Up @@ -204,10 +204,11 @@ class _RichAttributionWidgetState extends State<RichAttributionWidget> {
context,
() {
setState(() => popupExpanded = true);
mapEventSubscription =
MapController.of(context).mapEventStream.listen((e) {
mapEventSubscription = MapController.of(context)
.mapEventStream
.listen((e) async {
setState(() => popupExpanded = false);
mapEventSubscription?.cancel();
await mapEventSubscription?.cancel();
});
},
),
Expand All @@ -225,7 +226,7 @@ class _RichAttributionWidgetState extends State<RichAttributionWidget> {
context: context,
isExpanded: popupExpanded,
config: widget,
child: Container(
child: DecoratedBox(
decoration: BoxDecoration(
color: widget.popupBackgroundColor ??
Theme.of(context).colorScheme.background,
Expand Down
1 change: 1 addition & 0 deletions lib/src/layer/attribution_layer/simple.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';

/// A simple, classic style, attribution layer
///
Expand Down
2 changes: 1 addition & 1 deletion lib/src/layer/marker_layer/marker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Marker {
/// user's perspective. Defaults to `false` if also unset by [MarkerLayer].
///
/// Note that this is not used to apply a custom rotation in degrees to the
/// marker. Use a widget inside [builder] to perform this.
/// marker. Use a widget inside [child] to perform this.
final bool? rotate;

/// Creates a container for a [child] widget located at a geographic coordinate
Expand Down
2 changes: 1 addition & 1 deletion lib/src/layer/marker_layer/marker_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class MarkerLayer extends StatelessWidget {
/// user's perspective. Defaults to `false`. Overriden by [Marker.rotate].
///
/// Note that this is not used to apply a custom rotation in degrees to the
/// markers. Use a widget inside [Marker.builder] to perform this.
/// markers. Use a widget inside [Marker.child] to perform this.
final bool rotate;

/// Create a new [MarkerLayer] to use inside of [FlutterMap.children].
Expand Down
2 changes: 1 addition & 1 deletion lib/src/layer/polygon_layer/polygon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class Polygon<R extends Object> {
// Used to batch draw calls to the canvas
int? _renderHashCode;

/// An optimized hash code dedicated to be used inside the [PolygonPainter].
/// An optimized hash code dedicated to be used inside the [_PolygonPainter].
int get renderHashCode => _renderHashCode ??= Object.hash(
color,
borderStrokeWidth,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/layer/polygon_layer/polygon_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class _PolygonLayerState<R extends Object> extends State<PolygonLayer<R>> {
return Earcut.triangulateRaw(
List.generate(
points.length * 2,
(ii) => ii % 2 == 0
(ii) => ii.isEven
? points.elementAt(ii ~/ 2).x
: points.elementAt(ii ~/ 2).y,
growable: false,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/layer/tile_layer/tile_bounds/tile_bounds.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ abstract class TileBounds {
final LatLngBounds? _latLngBounds;

/// Constructor that creates an instance of a subclass of [TileBounds]:
/// [InfiniteTileBounds] if the CRS is [infinite].
/// [InfiniteTileBounds] if the CRS is infinite.
/// [DiscreteTileBounds] if the CRS has hard borders.
/// [WrappedTileBounds] if the CRS is wrapped.
factory TileBounds({
Expand Down
8 changes: 3 additions & 5 deletions lib/src/layer/tile_layer/tile_display.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:meta/meta.dart';

@immutable
sealed class TileDisplay {
Expand Down Expand Up @@ -37,14 +37,12 @@ sealed class TileDisplay {
/// range is (0.0 - 1.0).
double startOpacity,

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

/// Output a value of type [T] dependent on [this] and its type
/// Output a value of type [T] dependent on this and its type
T? when<T>({
T? Function(InstantaneousTileDisplay instantaneous)? instantaneous,
T? Function(FadeInTileDisplay fadeIn)? fadeIn,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/layer/tile_layer/tile_error_evict_callback.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ enum EvictErrorTileStrategy {
/// Evict images for tiles which failed to load and:
/// - do not belong to the current zoom level AND/OR
/// - are not visible, respecting the pruning buffer (the maximum of the
/// [keepBuffer] and [panBuffer].
/// keepBuffer and panBuffer.
notVisibleRespectMargin,

/// Evict images for tiles which failed to load and:
Expand Down
11 changes: 6 additions & 5 deletions lib/src/layer/tile_layer/tile_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:flutter_map/src/layer/tile_layer/tile_image_manager.dart';
import 'package:flutter_map/src/layer/tile_layer/tile_range.dart';
import 'package:flutter_map/src/layer/tile_layer/tile_range_calculator.dart';
import 'package:flutter_map/src/layer/tile_layer/tile_scale_calculator.dart';
import 'package:http/http.dart';
import 'package:http/retry.dart';
import 'package:logger/logger.dart';

Expand Down Expand Up @@ -362,7 +363,7 @@ class _TileLayerState extends State<TileLayer> with TickerProviderStateMixin {
_tileUpdateSubscription = mapController.mapEventStream
.map((mapEvent) => TileUpdateEvent(mapEvent: mapEvent))
.transform(widget.tileUpdateTransformer)
.listen((event) => _onTileUpdateEvent(event));
.listen(_onTileUpdateEvent);
}

var reloadTiles = false;
Expand Down Expand Up @@ -629,13 +630,13 @@ class _TileLayerState extends State<TileLayer> with TickerProviderStateMixin {
required bool pruneAfterLoad,
}) {
final tileZoom = tileLoadRange.zoom;
tileLoadRange = tileLoadRange.expand(widget.panBuffer);
final expandedTileLoadRange = tileLoadRange.expand(widget.panBuffer);

// Build the queue of tiles to load. Marks all tiles with valid coordinates
// in the tileLoadRange as current.
final tileBoundsAtZoom = _tileBounds.atZoom(tileZoom);
final tilesToLoad = _tileImageManager.createMissingTiles(
tileLoadRange,
expandedTileLoadRange,
tileBoundsAtZoom,
createTile: (coordinates) => _createTileImage(
coordinates: coordinates,
Expand All @@ -645,7 +646,7 @@ class _TileLayerState extends State<TileLayer> with TickerProviderStateMixin {
);

// Re-order the tiles by their distance to the center of the range.
final tileCenter = tileLoadRange.center;
final tileCenter = expandedTileLoadRange.center;
tilesToLoad.sort(
(a, b) => _distanceSq(a.coordinates, tileCenter)
.compareTo(_distanceSq(b.coordinates, tileCenter)),
Expand Down Expand Up @@ -681,7 +682,7 @@ class _TileLayerState extends State<TileLayer> with TickerProviderStateMixin {
_pruneLater?.cancel();
_pruneLater = Timer(
fadeIn.duration + const Duration(milliseconds: 50),
() => _pruneWithCurrentCamera(),
_pruneWithCurrentCamera,
);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ abstract class TileProvider {
/// [70339807ed6b](https://github.com/Leaflet/Leaflet/commit/70339807ed6bec630ee9c2e96a9cb8356fa6bd86).
/// It is never mentioned why this regex was used or changed in Leaflet.
/// This regex is more permissive of the characters it allows.
static final templatePlaceholderElement = RegExp(r'{([^{}]*)}');
static final templatePlaceholderElement = RegExp('{([^{}]*)}');

/// Replaces placeholders in the form [templatePlaceholderElement] with their
/// corresponding values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class NetworkTileProvider extends TileProvider {
final bool silenceExceptions;

/// Long living client used to make all tile requests by
/// [FlutterMapNetworkImageProvider] for the duration that this provider is
/// [MapNetworkImageProvider] for the duration that this provider is
/// alive
final BaseClient _httpClient;

Expand Down
2 changes: 1 addition & 1 deletion lib/src/layer/tile_layer/tile_range_calculator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class TileRangeCalculator {

/// Calculates the visible pixel bounds at the [tileZoom] zoom level when
/// viewing the map from the [viewingZoom] centered at the [center]. The
/// resulting tile range is expanded by [panBuffer].
/// resulting tile range is expanded by panBuffer.
DiscreteTileRange calculate({
// The map camera used to calculate the bounds.
required MapCamera camera,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/layer/tile_layer/tile_scale_calculator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class TileScaleCalculator {
required this.tileSize,
});

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

Expand Down
2 changes: 1 addition & 1 deletion lib/src/map/camera/camera.dart
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class MapCamera {
/// The current rotation value in radians
double get rotationRad => rotation * degrees2Radians;

/// Calculates point value for the given [latLng] using this camera's
/// Calculates point value for the given [latlng] using this camera's
/// [crs] and [zoom] (or the provided [zoom]).
Point<double> project(LatLng latlng, [double? zoom]) =>
crs.latLngToPoint(latlng, zoom ?? this.zoom);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/map/camera/camera_fit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ abstract class CameraFit {
/// Allows for more fine grained boundaries when the camera is rotated. See
/// https://github.com/fleaflet/flutter_map/pull/1549 for more information.
///
/// [inside] is not supported due to lack of implementation.
/// `inside` is not supported due to lack of implementation.
const factory CameraFit.coordinates({
required List<LatLng> coordinates,
EdgeInsets padding,
Expand Down
5 changes: 3 additions & 2 deletions lib/src/map/controller/map_controller_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,10 @@ class MapControllerImpl extends ValueNotifier<_MapControllerState>
String? id,
}) {
// Algorithm thanks to https://github.com/tlserver/flutter_map_location_marker
LatLng center = newCenter;
if (offset != Offset.zero) {
final newPoint = camera.project(newCenter, newZoom);
newCenter = camera.unproject(
center = camera.unproject(
camera.rotatePoint(
newPoint,
newPoint - Point(offset.dx, offset.dy),
Expand All @@ -162,7 +163,7 @@ class MapControllerImpl extends ValueNotifier<_MapControllerState>
}

MapCamera? newCamera = camera.withPosition(
center: newCenter,
center: center,
zoom: camera.clampZoom(newZoom),
);

Expand Down
Loading
Loading