diff --git a/analysis_options.yaml b/analysis_options.yaml index cde91768d..db6a211fe 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -10,60 +10,30 @@ analyzer: linter: rules: # temporary rules - avoid_escaping_inner_quotes: false - prefer_interpolation_to_compose_strings: false - prefer_if_elements_to_conditional_expressions: false - constant_identifier_names: false flutter_style_todos: false one_member_abstracts: false lines_longer_than_80_chars: false prefer_int_literals: false unnecessary_lambdas: false avoid_print: false - noop_primitive_operations: false - avoid_bool_literals_in_conditional_expressions: false avoid_unused_constructor_parameters: false - no_default_cases: false - sort_pub_dependencies: false - unnecessary_breaks: false - avoid_redundant_argument_values: false unawaited_futures: false overridden_fields: false - avoid_setters_without_getters: false - cast_nullable_to_non_nullable: false - only_throw_errors: false - no_runtimeType_toString: false always_put_required_named_parameters_first: false leading_newlines_in_multiline_strings: false - prefer_constructors_over_static_methods: false - prefer_null_aware_method_calls: false directives_ordering: false - unnecessary_await_in_return: false - avoid_multiple_declarations_per_line: false - unnecessary_string_escapes: false parameter_assignments: false - combinators_ordering: false use_setters_to_change_properties: false - avoid_equals_and_hash_code_on_mutable_classes: false type_annotate_public_apis: false - unnecessary_library_directive: false prefer_asserts_with_message: false public_member_api_docs: false require_trailing_commas: false avoid_dynamic_calls: false - avoid_void_async: false always_use_package_imports: false prefer_single_quotes: false always_declare_return_types: false sort_constructors_first: false avoid_relative_lib_imports: false avoid_positional_boolean_parameters: false - prefer_final_fields: false - prefer_final_locals: false - prefer_final_in_for_each: false - implicit_call_tearoffs: false comment_references: false cascade_invocations: false - avoid_type_to_string: false - omit_local_variable_types: false - use_named_constants: false diff --git a/example/analysis_options.yaml b/example/analysis_options.yaml index cb1978b3a..6bc76834f 100644 --- a/example/analysis_options.yaml +++ b/example/analysis_options.yaml @@ -3,3 +3,4 @@ include: ../analysis_options.yaml linter: rules: public_member_api_docs: false + avoid_redundant_argument_values: false \ No newline at end of file diff --git a/example/lib/annotation_order_maps.dart b/example/lib/annotation_order_maps.dart index 9c00557a4..a077757d3 100644 --- a/example/lib/annotation_order_maps.dart +++ b/example/lib/annotation_order_maps.dart @@ -31,71 +31,65 @@ class _AnnotationOrderBodyState extends State { return Column( children: [ Card( - child: Padding( - padding: const EdgeInsets.symmetric(vertical: 0.0), - child: Column( - children: [ - const Padding( - padding: EdgeInsets.only(bottom: 5.0), - child: Text( - 'This map has polygones (fill) above all other anotations (default behavior)'), - ), - Center( - child: SizedBox( - width: 250.0, - height: 250.0, - child: MapLibreMap( - onMapCreated: onMapCreatedOne, - onStyleLoadedCallback: () => onStyleLoaded(controllerOne), - initialCameraPosition: CameraPosition( - target: center, - zoom: 5.0, - ), - annotationOrder: const [ - AnnotationType.line, - AnnotationType.symbol, - AnnotationType.circle, - AnnotationType.fill, - ], + child: Column( + children: [ + const Padding( + padding: EdgeInsets.only(bottom: 5.0), + child: Text( + 'This map has polygones (fill) above all other anotations (default behavior)'), + ), + Center( + child: SizedBox( + width: 250.0, + height: 250.0, + child: MapLibreMap( + onMapCreated: onMapCreatedOne, + onStyleLoadedCallback: () => onStyleLoaded(controllerOne), + initialCameraPosition: CameraPosition( + target: center, + zoom: 5.0, ), + annotationOrder: const [ + AnnotationType.line, + AnnotationType.symbol, + AnnotationType.circle, + AnnotationType.fill, + ], ), ), - ], - ), + ), + ], ), ), Card( - child: Padding( - padding: const EdgeInsets.symmetric(vertical: 0.0), - child: Column( - children: [ - const Padding( - padding: EdgeInsets.only(bottom: 5.0, top: 5.0), - child: Text( - 'This map has polygones (fill) under all other anotations'), - ), - Center( - child: SizedBox( - width: 250.0, - height: 250.0, - child: MapLibreMap( - onMapCreated: onMapCreatedTwo, - onStyleLoadedCallback: () => onStyleLoaded(controllerTwo), - initialCameraPosition: CameraPosition( - target: center, - zoom: 5.0, - ), - annotationOrder: const [ - AnnotationType.fill, - AnnotationType.line, - AnnotationType.symbol, - AnnotationType.circle, - ], + child: Column( + children: [ + const Padding( + padding: EdgeInsets.only(bottom: 5.0, top: 5.0), + child: Text( + 'This map has polygones (fill) under all other anotations'), + ), + Center( + child: SizedBox( + width: 250.0, + height: 250.0, + child: MapLibreMap( + onMapCreated: onMapCreatedTwo, + onStyleLoadedCallback: () => onStyleLoaded(controllerTwo), + initialCameraPosition: CameraPosition( + target: center, + zoom: 5.0, ), + annotationOrder: const [ + AnnotationType.fill, + AnnotationType.line, + AnnotationType.symbol, + AnnotationType.circle, + ], ), ), - ], - ), + ), + ], ), ), ], @@ -110,7 +104,7 @@ class _AnnotationOrderBodyState extends State { controllerTwo = controller; } - void onStyleLoaded(MapLibreMapController controller) async { + Future onStyleLoaded(MapLibreMapController controller) async { await addImageFromAsset( controller, "custom-marker", "assets/symbols/custom-marker.png"); controller.addSymbol( diff --git a/example/lib/click_annotations.dart b/example/lib/click_annotations.dart index 10f7f7690..93a5a41b0 100644 --- a/example/lib/click_annotations.dart +++ b/example/lib/click_annotations.dart @@ -79,7 +79,7 @@ class ClickAnnotationBodyState extends State { _showSnackBar('symbol', symbol.id); } - void _onStyleLoaded() async { + Future _onStyleLoaded() async { await addImageFromAsset( controller!, "custom-marker", "assets/symbols/custom-marker.png"); controller!.addCircle( diff --git a/example/lib/custom_marker.dart b/example/lib/custom_marker.dart index e202f1711..32d5d7e9f 100644 --- a/example/lib/custom_marker.dart +++ b/example/lib/custom_marker.dart @@ -111,7 +111,7 @@ class CustomMarkerState extends State { //_measurePerformance(); // Generate random markers - var param = []; + final param = []; for (var i = 0; i < randomMarkerNum; i++) { final lat = _rnd.nextDouble() * 20 + 30; final lng = _rnd.nextDouble() * 20 + 125; @@ -120,7 +120,7 @@ class CustomMarkerState extends State { _mapController.toScreenLocationBatch(param).then((value) { for (var i = 0; i < randomMarkerNum; i++) { - var point = + final point = Point(value[i].x as double, value[i].y as double); _addMarker(point, param[i]); } @@ -141,7 +141,7 @@ class CustomMarkerState extends State { } _mapController.toScreenLocation(const LatLng(0, 0)); - Stopwatch sw = Stopwatch(); + final sw = Stopwatch(); for (final batch in batches) { // @@ -149,9 +149,9 @@ class CustomMarkerState extends State { // for (var i = 0; i < trial; i++) { sw.start(); - var list = >>[]; + final list = >>[]; for (var j = 0; j < batch; j++) { - var p = _mapController + final p = _mapController .toScreenLocation(LatLng(j.toDouble() % 80, j.toDouble() % 300)); list.add(p); } @@ -166,7 +166,7 @@ class CustomMarkerState extends State { // for (var i = 0; i < trial; i++) { sw.start(); - var param = []; + final param = []; for (var j = 0; j < batch; j++) { param.add(LatLng(j.toDouble() % 80, j.toDouble() % 300)); } diff --git a/example/lib/get_map_informations.dart b/example/lib/get_map_informations.dart index fcbe67ddc..5819f741d 100644 --- a/example/lib/get_map_informations.dart +++ b/example/lib/get_map_informations.dart @@ -30,21 +30,21 @@ class _GetMapInfoBodyState extends State { }); } - void displaySources() async { + Future displaySources() async { if (controller == null) { return; } - List sources = await controller!.getSourceIds(); + final sources = await controller!.getSourceIds(); setState(() { data = 'Sources: ${sources.map((e) => '"$e"').join(', ')}'; }); } - void displayLayers() async { + Future displayLayers() async { if (controller == null) { return; } - List layers = (await controller!.getLayerIds()).cast(); + final layers = (await controller!.getLayerIds()).cast(); setState(() { data = 'Layers: ${layers.map((e) => '"$e"').join(', ')}'; }); diff --git a/example/lib/layer.dart b/example/lib/layer.dart index 50df8ec1d..7a03fb471 100644 --- a/example/lib/layer.dart +++ b/example/lib/layer.dart @@ -157,7 +157,7 @@ class LayerState extends State { ScaffoldMessenger.of(context).showSnackBar(snackBar); } - void _onStyleLoadedCallback() async { + Future _onStyleLoadedCallback() async { await addImageFromAsset( controller, "custom-marker", "assets/symbols/custom-marker.png"); await controller.addGeoJsonSource("points", _points); diff --git a/example/lib/line.dart b/example/lib/line.dart index b287441b3..1b09f10c8 100644 --- a/example/lib/line.dart +++ b/example/lib/line.dart @@ -49,8 +49,8 @@ class LineBodyState extends State { /// Adds an asset image to the currently displayed style Future addImageFromAsset(String name, String assetName) async { - final ByteData bytes = await rootBundle.load(assetName); - final Uint8List list = bytes.buffer.asUint8List(); + final bytes = await rootBundle.load(assetName); + final list = bytes.buffer.asUint8List(); return controller!.addImage(name, list); } @@ -109,7 +109,7 @@ class LineBodyState extends State { } Future _changeLinePattern() async { - String? current = + final current = _selectedLine!.options.linePattern == null ? "assetImage" : null; await _updateSelectedLine( LineOptions(linePattern: current), @@ -117,7 +117,7 @@ class LineBodyState extends State { } Future _changeAlpha() async { - double? current = _selectedLine!.options.lineOpacity; + var current = _selectedLine!.options.lineOpacity; current ??= 1.0; await _updateSelectedLine( @@ -126,7 +126,7 @@ class LineBodyState extends State { } Future _toggleVisible() async { - double? current = _selectedLine!.options.lineOpacity; + var current = _selectedLine!.options.lineOpacity; current ??= 1.0; await _updateSelectedLine( LineOptions(lineOpacity: current == 0.0 ? 1.0 : 0.0), @@ -213,9 +213,9 @@ class LineBodyState extends State { onPressed: (_selectedLine == null) ? null : () async { - var latLngs = await controller! + final latLngs = await controller! .getLineLatLngs(_selectedLine!); - for (var latLng in latLngs) { + for (final latLng in latLngs) { debugPrint(latLng.toString()); } }, diff --git a/example/lib/local_style.dart b/example/lib/local_style.dart index 0ad4a84f1..5a3c35309 100644 --- a/example/lib/local_style.dart +++ b/example/lib/local_style.dart @@ -32,14 +32,14 @@ class LocalStyleState extends State { super.initState(); getApplicationDocumentsDirectory().then((dir) async { - String documentDir = dir.path; - String stylesDir = '$documentDir/styles'; - String styleJSON = + final documentDir = dir.path; + final stylesDir = '$documentDir/styles'; + const styleJSON = '{"version":8,"name":"Demo style","center":[50,10],"zoom":4,"sources":{"demotiles":{"type":"vector","url":"https://demotiles.maplibre.org/tiles/tiles.json"}},"sprite":"","glyphs":"https://orangemug.github.io/font-glyphs/glyphs/{fontstack}/{range}.pbf","layers":[{"id":"background","type":"background","paint":{"background-color":"rgba(255, 255, 255, 1)"}},{"id":"countries","type":"line","source":"demotiles","source-layer":"countries","paint":{"line-color":"rgba(0, 0, 0, 1)","line-width":1,"line-opacity":1}}]}'; await Directory(stylesDir).create(recursive: true); - File styleFile = File('$stylesDir/style.json'); + final styleFile = File('$stylesDir/style.json'); await styleFile.writeAsString(styleJSON); diff --git a/example/lib/main.dart b/example/lib/main.dart index c54460f31..57d7e598f 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -85,7 +85,7 @@ class _MapsDemoState extends State { } } - void _pushPage(BuildContext context, ExamplePage page) async { + Future _pushPage(BuildContext context, ExamplePage page) async { if (!kIsWeb && page.needsLocationPermission) { final location = Location(); final hasPermissions = await location.hasPermission(); diff --git a/example/lib/map_ui.dart b/example/lib/map_ui.dart index 3d92ba060..8321fd501 100644 --- a/example/lib/map_ui.dart +++ b/example/lib/map_ui.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:math'; - import 'package:flutter/material.dart'; import 'package:collection/collection.dart'; import 'package:maplibre_gl/maplibre_gl.dart'; @@ -86,7 +84,7 @@ class MapUiBodyState extends State { } Widget _myLocationTrackingModeCycler() { - final MyLocationTrackingMode nextType = MyLocationTrackingMode.values[ + final nextType = MyLocationTrackingMode.values[ (_myLocationTrackingMode.index + 1) % MyLocationTrackingMode.values.length]; return TextButton( @@ -278,12 +276,11 @@ class MapUiBodyState extends State { return TextButton( child: const Text('get currently visible region'), onPressed: () async { - var result = await mapController!.getVisibleRegion(); + final result = await mapController!.getVisibleRegion(); if (!mounted) return; ScaffoldMessenger.of(context).showSnackBar(SnackBar( - content: Text( - "SW: ${result.southwest.toString()} NE: ${result.northeast.toString()}"), + content: Text("SW: ${result.southwest} NE: ${result.northeast}"), )); }, ); @@ -293,7 +290,7 @@ class MapUiBodyState extends State { return TextButton( child: const Text('get source features (maplibre)'), onPressed: () async { - var result = await mapController! + final result = await mapController! .querySourceFeatures("maplibre", "centroids", null); debugPrint(result.toString()); }, @@ -320,16 +317,16 @@ class MapUiBodyState extends State { } _drawFill(List features) async { - Map? feature = + final Map? feature = features.firstWhereOrNull((f) => f['geometry']['type'] == 'Polygon'); if (feature != null) { - List> geometry = feature['geometry']['coordinates'] + final List> geometry = feature['geometry']['coordinates'] .map( (ll) => ll.map((l) => LatLng(l[1], l[0])).toList().cast()) .toList() .cast>(); - Fill fill = await mapController!.addFill(FillOptions( + final fill = await mapController!.addFill(FillOptions( geometry: geometry, fillColor: "#FF0000", fillOutlineColor: "#FF0000", @@ -343,7 +340,7 @@ class MapUiBodyState extends State { @override Widget build(BuildContext context) { - final MapLibreMap maplibreMap = MapLibreMap( + final maplibreMap = MapLibreMap( onMapCreated: onMapCreated, initialCameraPosition: _kInitialPosition, trackCameraPosition: true, @@ -363,7 +360,7 @@ class MapUiBodyState extends State { debugPrint( "Map click: ${point.x},${point.y} ${latLng.latitude}/${latLng.longitude}"); debugPrint("Filter $_featureQueryFilter"); - List features = await mapController! + final features = await mapController! .queryRenderedFeatures(point, [], _featureQueryFilter); if (!mounted) return; @@ -381,17 +378,17 @@ class MapUiBodyState extends State { onMapLongClick: (point, latLng) async { debugPrint( "Map long press: ${point.x},${point.y} ${latLng.latitude}/${latLng.longitude}"); - Point convertedPoint = await mapController!.toScreenLocation(latLng); - LatLng convertedLatLng = await mapController!.toLatLng(point); + final convertedPoint = await mapController!.toScreenLocation(latLng); + final convertedLatLng = await mapController!.toLatLng(point); debugPrint( "Map long press converted: ${convertedPoint.x},${convertedPoint.y} ${convertedLatLng.latitude}/${convertedLatLng.longitude}"); - double metersPerPixel = + final metersPerPixel = await mapController!.getMetersPerPixelAtLatitude(latLng.latitude); debugPrint( "Map long press The distance measured in meters at latitude ${latLng.latitude} is $metersPerPixel m"); - List features = + final features = await mapController!.queryRenderedFeatures(point, [], null); if (features.isNotEmpty) { debugPrint(features[0]); @@ -408,7 +405,7 @@ class MapUiBodyState extends State { }, ); - final List listViewChildren = []; + final listViewChildren = []; if (mapController != null) { listViewChildren.addAll( diff --git a/example/lib/offline_regions.dart b/example/lib/offline_regions.dart index 95a9f6040..7d387c19c 100644 --- a/example/lib/offline_regions.dart +++ b/example/lib/offline_regions.dart @@ -157,22 +157,23 @@ class _OfflineRegionsBodyState extends State { ], ), const Spacer(), - _items[index].isDownloading - ? const SizedBox( - height: 16, - width: 16, - child: CircularProgressIndicator(), - ) - : IconButton( - icon: Icon( - _items[index].isDownloaded - ? Icons.delete - : Icons.file_download, - ), - onPressed: _items[index].isDownloaded - ? () => _deleteRegion(_items[index], index) - : () => _downloadRegion(_items[index], index), - ), + if (_items[index].isDownloading) + const SizedBox( + height: 16, + width: 16, + child: CircularProgressIndicator(), + ) + else + IconButton( + icon: Icon( + _items[index].isDownloaded + ? Icons.delete + : Icons.file_download, + ), + onPressed: _items[index].isDownloaded + ? () => _deleteRegion(_items[index], index) + : () => _downloadRegion(_items[index], index), + ), ], ), ), @@ -180,10 +181,10 @@ class _OfflineRegionsBodyState extends State { ); } - void _updateListOfRegions() async { - List offlineRegions = await getListOfRegions(); - List regionItems = []; - for (var item in allRegions) { + Future _updateListOfRegions() async { + final offlineRegions = await getListOfRegions(); + final regionItems = []; + for (final item in allRegions) { final offlineRegion = offlineRegions.firstWhereOrNull( (offlineRegion) => offlineRegion.metadata['name'] == item.name); if (offlineRegion != null) { @@ -198,7 +199,7 @@ class _OfflineRegionsBodyState extends State { }); } - void _downloadRegion(OfflineRegionListItem item, int index) async { + Future _downloadRegion(OfflineRegionListItem item, int index) async { setState(() { _items.removeAt(index); _items.insert(index, item.copyWith(isDownloading: true)); @@ -234,7 +235,7 @@ class _OfflineRegionsBodyState extends State { } } - void _deleteRegion(OfflineRegionListItem item, int index) async { + Future _deleteRegion(OfflineRegionListItem item, int index) async { setState(() { _items.removeAt(index); _items.insert(index, item.copyWith(isDownloading: true)); diff --git a/example/lib/place_batch.dart b/example/lib/place_batch.dart index 9e2fbfd6a..6fac0535c 100644 --- a/example/lib/place_batch.dart +++ b/example/lib/place_batch.dart @@ -116,7 +116,7 @@ class BatchAddBodyState extends State { return symbolOptions; } - void _add() async { + Future _add() async { if (_fills.isEmpty) { _fills = await controller.addFills(fillOptions); _lines = await controller diff --git a/example/lib/place_circle.dart b/example/lib/place_circle.dart index 2a7a32625..918d93401 100644 --- a/example/lib/place_circle.dart +++ b/example/lib/place_circle.dart @@ -90,8 +90,8 @@ class PlaceCircleBodyState extends State { } void _changePosition() { - final LatLng current = _selectedCircle!.options.geometry!; - final Offset offset = Offset( + final current = _selectedCircle!.options.geometry!; + final offset = Offset( center.latitude - current.latitude, center.longitude - current.longitude, ); @@ -106,7 +106,7 @@ class PlaceCircleBodyState extends State { } void _changeDraggable() { - bool? draggable = _selectedCircle!.options.draggable; + var draggable = _selectedCircle!.options.draggable; draggable ??= false; _updateSelectedCircle( CircleOptions( @@ -115,8 +115,8 @@ class PlaceCircleBodyState extends State { ); } - void _getLatLng() async { - LatLng latLng = await controller!.getCircleLatLng(_selectedCircle!); + Future _getLatLng() async { + final latLng = await controller!.getCircleLatLng(_selectedCircle!); if (!mounted) return; ScaffoldMessenger.of(context).showSnackBar( @@ -127,7 +127,7 @@ class PlaceCircleBodyState extends State { } void _changeCircleStrokeOpacity() { - double? current = _selectedCircle!.options.circleStrokeOpacity; + var current = _selectedCircle!.options.circleStrokeOpacity; current ??= 1.0; _updateSelectedCircle( @@ -136,14 +136,14 @@ class PlaceCircleBodyState extends State { } void _changeCircleStrokeWidth() { - double? current = _selectedCircle!.options.circleStrokeWidth; + var current = _selectedCircle!.options.circleStrokeWidth; current ??= 0; _updateSelectedCircle( CircleOptions(circleStrokeWidth: current == 0 ? 5.0 : 0)); } Future _changeCircleStrokeColor() async { - String? current = _selectedCircle!.options.circleStrokeColor; + var current = _selectedCircle!.options.circleStrokeColor; current ??= "#FFFFFF"; _updateSelectedCircle( @@ -153,7 +153,7 @@ class PlaceCircleBodyState extends State { } Future _changeCircleOpacity() async { - double? current = _selectedCircle!.options.circleOpacity; + var current = _selectedCircle!.options.circleOpacity; current ??= 1.0; _updateSelectedCircle( @@ -162,7 +162,7 @@ class PlaceCircleBodyState extends State { } Future _changeCircleRadius() async { - double? current = _selectedCircle!.options.circleRadius; + var current = _selectedCircle!.options.circleRadius; current ??= 0; _updateSelectedCircle( CircleOptions(circleRadius: current == 120.0 ? 30.0 : current + 30.0), @@ -170,7 +170,7 @@ class PlaceCircleBodyState extends State { } Future _changeCircleColor() async { - String? current = _selectedCircle!.options.circleColor; + var current = _selectedCircle!.options.circleColor; current ??= "#FF0000"; _updateSelectedCircle( @@ -179,7 +179,7 @@ class PlaceCircleBodyState extends State { } Future _changeCircleBlur() async { - double? current = _selectedCircle!.options.circleBlur; + var current = _selectedCircle!.options.circleBlur; current ??= 0; _updateSelectedCircle( CircleOptions(circleBlur: current == 0.75 ? 0 : 0.75), diff --git a/example/lib/place_fill.dart b/example/lib/place_fill.dart index cc3e830de..b0bc014be 100644 --- a/example/lib/place_fill.dart +++ b/example/lib/place_fill.dart @@ -65,7 +65,7 @@ class PlaceFillBodyState extends State { required origin, required point, required eventType}) { - DragEventType type = eventType; + final DragEventType type = eventType; switch (type) { case DragEventType.start: // TODO: Handle this case. @@ -85,8 +85,8 @@ class PlaceFillBodyState extends State { /// Adds an asset image to the currently displayed style Future addImageFromAsset(String name, String assetName) async { - final ByteData bytes = await rootBundle.load(assetName); - final Uint8List list = bytes.buffer.asUint8List(); + final bytes = await rootBundle.load(assetName); + final list = bytes.buffer.asUint8List(); return controller!.addImage(name, list); } @@ -127,7 +127,7 @@ class PlaceFillBodyState extends State { } void _changePosition() { - List>? geometry = _selectedFill!.options.geometry; + var geometry = _selectedFill!.options.geometry; geometry ??= _defaultGeometry; @@ -142,7 +142,7 @@ class PlaceFillBodyState extends State { } void _changeDraggable() { - bool? draggable = _selectedFill!.options.draggable; + var draggable = _selectedFill!.options.draggable; draggable ??= false; _updateSelectedFill( FillOptions(draggable: !draggable), @@ -150,7 +150,7 @@ class PlaceFillBodyState extends State { } Future _changeFillOpacity() async { - double? current = _selectedFill!.options.fillOpacity; + var current = _selectedFill!.options.fillOpacity; current ??= 1.0; _updateSelectedFill( @@ -159,7 +159,7 @@ class PlaceFillBodyState extends State { } Future _changeFillColor() async { - String? current = _selectedFill!.options.fillColor; + var current = _selectedFill!.options.fillColor; current ??= "#FF0000"; _updateSelectedFill( @@ -168,7 +168,7 @@ class PlaceFillBodyState extends State { } Future _changeFillOutlineColor() async { - String? current = _selectedFill!.options.fillOutlineColor; + var current = _selectedFill!.options.fillOutlineColor; current ??= "#FF0000"; _updateSelectedFill( @@ -177,7 +177,7 @@ class PlaceFillBodyState extends State { } Future _changeFillPattern() async { - String? current = + final current = _selectedFill!.options.fillPattern == null ? "assetImage" : null; _updateSelectedFill( FillOptions(fillPattern: current), diff --git a/example/lib/place_source.dart b/example/lib/place_source.dart index f59f8abd8..1d92326aa 100644 --- a/example/lib/place_source.dart +++ b/example/lib/place_source.dart @@ -50,8 +50,8 @@ class PlaceSymbolBodyState extends State { /// Adds an asset image as a source to the currently displayed style Future addImageSourceFromAsset( String imageSourceId, String assetName) async { - final ByteData bytes = await rootBundle.load(assetName); - final Uint8List list = bytes.buffer.asUint8List(); + final bytes = await rootBundle.load(assetName); + final list = bytes.buffer.asUint8List(); return controller.addImageSource( imageSourceId, list, @@ -93,8 +93,8 @@ class PlaceSymbolBodyState extends State { Future updateImageSourceFromAsset( String imageSourceId, String assetName) async { - final ByteData bytes = await rootBundle.load(assetName); - final Uint8List list = bytes.buffer.asUint8List(); + final bytes = await rootBundle.load(assetName); + final list = bytes.buffer.asUint8List(); return controller.updateImageSource(imageSourceId, list, null); } diff --git a/example/lib/place_symbol.dart b/example/lib/place_symbol.dart index 873001692..323f188fd 100644 --- a/example/lib/place_symbol.dart +++ b/example/lib/place_symbol.dart @@ -60,14 +60,14 @@ class PlaceSymbolBodyState extends State { /// Adds an asset image to the currently displayed style Future addImageFromAsset(String name, String assetName) async { - final ByteData bytes = await rootBundle.load(assetName); - final Uint8List list = bytes.buffer.asUint8List(); + final bytes = await rootBundle.load(assetName); + final list = bytes.buffer.asUint8List(); return controller!.addImage(name, list); } /// Adds a network image to the currently displayed style Future addImageFromUrl(String name, Uri uri) async { - var response = await http.get(uri); + final response = await http.get(uri); return controller!.addImage(name, response.bodyBytes); } @@ -85,13 +85,13 @@ class PlaceSymbolBodyState extends State { ); } - void _updateSelectedSymbol(SymbolOptions changes) async { + Future _updateSelectedSymbol(SymbolOptions changes) async { await controller!.updateSymbol(_selectedSymbol!, changes); } void _add(String iconImage) { - List availableNumbers = Iterable.generate(12).toList(); - for (var s in controller!.symbols) { + final availableNumbers = Iterable.generate(12).toList(); + for (final s in controller!.symbols) { availableNumbers.removeWhere((i) => i == s.data!['count']); } if (availableNumbers.isNotEmpty) { @@ -105,7 +105,7 @@ class PlaceSymbolBodyState extends State { } SymbolOptions _getSymbolOptions(String iconImage, int symbolCount) { - LatLng geometry = LatLng( + final geometry = LatLng( center.latitude + sin(symbolCount * pi / 6.0) / 20.0, center.longitude + cos(symbolCount * pi / 6.0) / 20.0, ); @@ -133,13 +133,13 @@ class PlaceSymbolBodyState extends State { } Future _addAll(String iconImage) async { - List symbolsToAddNumbers = Iterable.generate(12).toList(); - for (var s in controller!.symbols) { + final symbolsToAddNumbers = Iterable.generate(12).toList(); + for (final s in controller!.symbols) { symbolsToAddNumbers.removeWhere((i) => i == s.data!['count']); } if (symbolsToAddNumbers.isNotEmpty) { - final List symbolOptionsList = symbolsToAddNumbers + final symbolOptionsList = symbolsToAddNumbers .map((i) => _getSymbolOptions(iconImage, i)) .toList(); controller!.addSymbols(symbolOptionsList, @@ -168,8 +168,8 @@ class PlaceSymbolBodyState extends State { } void _changePosition() { - final LatLng current = _selectedSymbol!.options.geometry!; - final Offset offset = Offset( + final current = _selectedSymbol!.options.geometry!; + final offset = Offset( center.latitude - current.latitude, center.longitude - current.longitude, ); @@ -184,14 +184,14 @@ class PlaceSymbolBodyState extends State { } void _changeIconOffset() { - Offset? currentAnchor = _selectedSymbol!.options.iconOffset; - currentAnchor ??= const Offset(0.0, 0.0); - final Offset newAnchor = Offset(1.0 - currentAnchor.dy, currentAnchor.dx); + var currentAnchor = _selectedSymbol!.options.iconOffset; + currentAnchor ??= Offset.zero; + final newAnchor = Offset(1.0 - currentAnchor.dy, currentAnchor.dx); _updateSelectedSymbol(SymbolOptions(iconOffset: newAnchor)); } Future _changeIconAnchor() async { - String? current = _selectedSymbol!.options.iconAnchor; + var current = _selectedSymbol!.options.iconAnchor; if (current == null || current == 'center') { current = 'bottom'; } else { @@ -203,7 +203,7 @@ class PlaceSymbolBodyState extends State { } Future _toggleDraggable() async { - bool? draggable = _selectedSymbol!.options.draggable; + var draggable = _selectedSymbol!.options.draggable; draggable ??= false; _updateSelectedSymbol( @@ -212,7 +212,7 @@ class PlaceSymbolBodyState extends State { } Future _changeAlpha() async { - double? current = _selectedSymbol!.options.iconOpacity; + var current = _selectedSymbol!.options.iconOpacity; current ??= 1.0; _updateSelectedSymbol( @@ -221,7 +221,7 @@ class PlaceSymbolBodyState extends State { } Future _changeRotation() async { - double? current = _selectedSymbol!.options.iconRotate; + var current = _selectedSymbol!.options.iconRotate; current ??= 0; _updateSelectedSymbol( SymbolOptions(iconRotate: current == 330.0 ? 0.0 : current + 30.0), @@ -229,7 +229,7 @@ class PlaceSymbolBodyState extends State { } Future _toggleVisible() async { - double? current = _selectedSymbol!.options.iconOpacity; + var current = _selectedSymbol!.options.iconOpacity; current ??= 1.0; _updateSelectedSymbol( @@ -238,14 +238,14 @@ class PlaceSymbolBodyState extends State { } Future _changeZIndex() async { - int? current = _selectedSymbol!.options.zIndex; + var current = _selectedSymbol!.options.zIndex; current ??= 0; _updateSelectedSymbol( SymbolOptions(zIndex: current == 12 ? 0 : current + 1), ); } - void _getLatLng() async { + Future _getLatLng() async { final latLng = await controller!.getSymbolLatLng(_selectedSymbol!); if (!mounted) return; diff --git a/example/lib/scrolling_map.dart b/example/lib/scrolling_map.dart index 059d59e66..d5abf4df7 100644 --- a/example/lib/scrolling_map.dart +++ b/example/lib/scrolling_map.dart @@ -76,7 +76,7 @@ class _ScrollingMapBodyState extends State { padding: const EdgeInsets.symmetric(vertical: 30.0), child: Column( children: [ - const Text('This map doesn\'t consume the vertical drags.'), + const Text("This map doesn't consume the vertical drags."), const Padding( padding: EdgeInsets.only(bottom: 12.0), child: @@ -118,7 +118,7 @@ class _ScrollingMapBodyState extends State { controllerTwo = controller; } - void onStyleLoaded(MapLibreMapController controller) async { + Future onStyleLoaded(MapLibreMapController controller) async { await addImageFromAsset( controller, "custom-marker", "assets/symbols/custom-marker.png"); controller.addSymbol(SymbolOptions( diff --git a/example/lib/util.dart b/example/lib/util.dart index fa5ae9ed6..035c5c050 100644 --- a/example/lib/util.dart +++ b/example/lib/util.dart @@ -4,7 +4,7 @@ import 'package:maplibre_gl/maplibre_gl.dart'; /// Adds an asset image to the currently displayed style Future addImageFromAsset( MapLibreMapController controller, String name, String assetName) async { - final ByteData bytes = await rootBundle.load(assetName); - final Uint8List list = bytes.buffer.asUint8List(); + final bytes = await rootBundle.load(assetName); + final list = bytes.buffer.asUint8List(); return controller.addImage(name, list); } diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 343c61785..71b4a0c82 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -10,22 +10,20 @@ environment: flutter: '>=3.10.0' dependencies: + collection: ^1.17.1 + device_info_plus: ^9.0.2 flutter: sdk: flutter - maplibre_gl: - path: ../maplibre_gl + http: ^1.1.0 location: ^5.0.3 + maplibre_gl: ^0.19.0 path_provider: ^2.0.15 - http: ^1.1.0 - collection: ^1.17.1 - device_info_plus: ^9.0.2 dev_dependencies: flutter_test: sdk: flutter very_good_analysis: ^5.0.0 - flutter: uses-material-design: true assets: diff --git a/maplibre_gl/lib/maplibre_gl.dart b/maplibre_gl/lib/maplibre_gl.dart index 3def53d8e..ee1312ae2 100644 --- a/maplibre_gl/lib/maplibre_gl.dart +++ b/maplibre_gl/lib/maplibre_gl.dart @@ -48,39 +48,39 @@ import 'package:maplibre_gl_platform_interface/maplibre_gl_platform_interface.da export 'package:maplibre_gl_platform_interface/maplibre_gl_platform_interface.dart' show - LatLng, - LatLngBounds, - LatLngQuad, - CameraPosition, - UserLocation, - UserHeading, - CameraUpdate, + Annotation, ArgumentCallbacks, - Symbol, - SymbolOptions, - CameraTargetBounds, - MinMaxZoomPreference, - MyLocationTrackingMode, - MyLocationRenderMode, - CompassViewPosition, AttributionButtonPosition, - Annotation, + CameraPosition, + CameraTargetBounds, + CameraUpdate, Circle, CircleOptions, - Line, - LineOptions, + CompassViewPosition, Fill, FillOptions, - SourceProperties, - RasterSourceProperties, - VectorSourceProperties, - RasterDemSourceProperties, GeojsonSourceProperties, - VideoSourceProperties, ImageSourceProperties, - MapLibrePlatform, + LatLng, + LatLngBounds, + LatLngQuad, + Line, + LineOptions, MapLibreMethodChannel, - OnPlatformViewCreatedCallback; + MapLibrePlatform, + MinMaxZoomPreference, + MyLocationRenderMode, + MyLocationTrackingMode, + OnPlatformViewCreatedCallback, + RasterDemSourceProperties, + RasterSourceProperties, + SourceProperties, + Symbol, + SymbolOptions, + UserHeading, + UserLocation, + VectorSourceProperties, + VideoSourceProperties; part 'src/controller.dart'; diff --git a/maplibre_gl/lib/src/annotation_manager.dart b/maplibre_gl/lib/src/annotation_manager.dart index 1ba3d4331..4c8ac4d95 100644 --- a/maplibre_gl/lib/src/annotation_manager.dart +++ b/maplibre_gl/lib/src/annotation_manager.dart @@ -91,7 +91,7 @@ abstract class AnnotationManager { /// Adds a multiple annotations to the map. This much faster than calling add /// multiple times Future addAll(Iterable annotations) async { - for (var a in annotations) { + for (final a in annotations) { _idToAnnotation[a.id] = a; } await _setAll(); @@ -105,7 +105,7 @@ abstract class AnnotationManager { /// Removes multiple annotations from the map Future removeAll(Iterable annotations) async { - for (var a in annotations) { + for (final a in annotations) { _idToAnnotation.remove(a.id); } await _setAll(); diff --git a/maplibre_gl/lib/src/controller.dart b/maplibre_gl/lib/src/controller.dart index 0d45d154c..71a5e827f 100644 --- a/maplibre_gl/lib/src/controller.dart +++ b/maplibre_gl/lib/src/controller.dart @@ -99,7 +99,7 @@ class MapLibreMapController extends ChangeNotifier { _maplibrePlatform.onFeatureDraggedPlatform.add((payload) { for (final fun in List.from(onFeatureDrag)) { - final DragEventType enmDragEventType = DragEventType.values + final enmDragEventType = DragEventType.values .firstWhere((element) => element.name == payload["eventType"]); fun(payload["id"], point: payload["point"], @@ -125,71 +125,52 @@ class MapLibreMapController extends ChangeNotifier { if (cameraPosition != null) { _cameraPosition = cameraPosition; } - if (onCameraIdle != null) { - onCameraIdle!(); - } + onCameraIdle?.call(); notifyListeners(); }); _maplibrePlatform.onMapStyleLoadedPlatform.add((_) { final interactionEnabled = annotationConsumeTapEvents.toSet(); - for (var type in annotationOrder.toSet()) { + for (final type in annotationOrder.toSet()) { final enableInteraction = interactionEnabled.contains(type); switch (type) { case AnnotationType.fill: fillManager = FillManager(this, onTap: onFillTapped.call, enableInteraction: enableInteraction); - break; case AnnotationType.line: lineManager = LineManager(this, onTap: onLineTapped.call, enableInteraction: enableInteraction); - break; case AnnotationType.circle: circleManager = CircleManager(this, onTap: onCircleTapped.call, enableInteraction: enableInteraction); - break; case AnnotationType.symbol: symbolManager = SymbolManager(this, onTap: onSymbolTapped.call, enableInteraction: enableInteraction); - break; - default: } } - if (onStyleLoadedCallback != null) { - onStyleLoadedCallback!(); - } + onStyleLoadedCallback?.call(); }); _maplibrePlatform.onMapClickPlatform.add((dict) { - if (onMapClick != null) { - onMapClick!(dict['point'], dict['latLng']); - } + onMapClick?.call(dict['point'], dict['latLng']); }); _maplibrePlatform.onMapLongClickPlatform.add((dict) { - if (onMapLongClick != null) { - onMapLongClick!(dict['point'], dict['latLng']); - } + onMapLongClick?.call(dict['point'], dict['latLng']); }); _maplibrePlatform.onCameraTrackingChangedPlatform.add((mode) { - if (onCameraTrackingChanged != null) { - onCameraTrackingChanged!(mode); - } + onCameraTrackingChanged?.call(mode); }); _maplibrePlatform.onCameraTrackingDismissedPlatform.add((_) { - if (onCameraTrackingDismissed != null) { - onCameraTrackingDismissed!(); - } + onCameraTrackingDismissed?.call(); }); _maplibrePlatform.onMapIdlePlatform.add((_) { - if (onMapIdle != null) { - onMapIdle!(); - } + onMapIdle?.call(); }); _maplibrePlatform.onUserLocationUpdatedPlatform.add((location) { onUserLocationUpdated?.call(location); @@ -929,8 +910,7 @@ class MapLibreMapController extends ChangeNotifier { /// The returned [Future] completes with the added circle once listeners have /// been notified. Future addCircle(CircleOptions options, [Map? data]) async { - final CircleOptions effectiveOptions = - CircleOptions.defaultOptions.copyWith(options); + final effectiveOptions = CircleOptions.defaultOptions.copyWith(options); final circle = Circle(getRandomString(), effectiveOptions, data); await circleManager!.add(circle); notifyListeners(); @@ -1024,8 +1004,7 @@ class MapLibreMapController extends ChangeNotifier { /// The returned [Future] completes with the added fill once listeners have /// been notified. Future addFill(FillOptions options, [Map? data]) async { - final FillOptions effectiveOptions = - FillOptions.defaultOptions.copyWith(options); + final effectiveOptions = FillOptions.defaultOptions.copyWith(options); final fill = Fill(getRandomString(), effectiveOptions, data); await fillManager!.add(fill); notifyListeners(); diff --git a/maplibre_gl/lib/src/download_region_status.dart b/maplibre_gl/lib/src/download_region_status.dart index 4edef4b73..2f9aed2d3 100644 --- a/maplibre_gl/lib/src/download_region_status.dart +++ b/maplibre_gl/lib/src/download_region_status.dart @@ -21,5 +21,5 @@ class Error extends DownloadRegionStatus { @override String toString() => - "Instance of 'DownloadRegionStatus.Error', cause = ${cause.toString()}"; + "Instance of 'DownloadRegionStatus.Error', cause = $cause"; } diff --git a/maplibre_gl/lib/src/global.dart b/maplibre_gl/lib/src/global.dart index a892ae892..ab10ba6f9 100644 --- a/maplibre_gl/lib/src/global.dart +++ b/maplibre_gl/lib/src/global.dart @@ -36,22 +36,22 @@ Future setHttpHeaders(Map headers) { } Future> mergeOfflineRegions(String path) async { - String regionsJson = await _globalChannel.invokeMethod( + final String regionsJson = await _globalChannel.invokeMethod( 'mergeOfflineRegions', { 'path': path, }, ); - Iterable regions = json.decode(regionsJson); + final Iterable regions = json.decode(regionsJson); return regions.map((region) => OfflineRegion.fromMap(region)).toList(); } Future> getListOfRegions() async { - String regionsJson = await _globalChannel.invokeMethod( + final String regionsJson = await _globalChannel.invokeMethod( 'getListOfRegions', {}, ); - Iterable regions = json.decode(regionsJson); + final Iterable regions = json.decode(regionsJson); return regions.map((region) => OfflineRegion.fromMap(region)).toList(); } @@ -88,7 +88,7 @@ Future downloadOfflineRegion( Map metadata = const {}, Function(DownloadRegionStatus event)? onEvent, }) async { - String channelName = + final channelName = 'downloadOfflineRegion_${DateTime.now().microsecondsSinceEpoch}'; await _globalChannel @@ -102,7 +102,7 @@ Future downloadOfflineRegion( onEvent(Error(error)); return Error(error); } - var unknownError = Error( + final unknownError = Error( PlatformException( code: 'UnknowException', message: @@ -113,31 +113,14 @@ Future downloadOfflineRegion( onEvent(unknownError); return unknownError; }).listen((data) { - final Map jsonData = json.decode(data); - DownloadRegionStatus? status; - switch (jsonData['status']) { - case 'start': - status = InProgress(0.0); - break; - case 'progress': - final dynamic value = jsonData['progress']; - double progress = 0.0; - - if (value is int) { - progress = value.toDouble(); - } - - if (value is double) { - progress = value; - } - - status = InProgress(progress); - break; - case 'success': - status = Success(); - break; - } - onEvent(status ?? (throw 'Invalid event status ${jsonData['status']}')); + final Map jsonData = json.decode(data); + final status = switch (jsonData['status']) { + 'start' => InProgress(0.0), + 'progress' => InProgress((jsonData['progress']! as num).toDouble()), + 'success' => Success(), + _ => throw Exception('Invalid event status ${jsonData['status']}'), + }; + onEvent(status); }); } diff --git a/maplibre_gl/lib/src/layer_properties.dart b/maplibre_gl/lib/src/layer_properties.dart index 389fcd463..f4e5735aa 100644 --- a/maplibre_gl/lib/src/layer_properties.dart +++ b/maplibre_gl/lib/src/layer_properties.dart @@ -904,7 +904,7 @@ class SymbolLayerProperties implements LayerProperties { @override Map toJson() { - final Map json = {}; + final json = {}; void addIfPresent(String fieldName, dynamic value) { if (value != null) { @@ -1229,7 +1229,7 @@ class CircleLayerProperties implements LayerProperties { @override Map toJson() { - final Map json = {}; + final json = {}; void addIfPresent(String fieldName, dynamic value) { if (value != null) { @@ -1533,7 +1533,7 @@ class LineLayerProperties implements LayerProperties { @override Map toJson() { - final Map json = {}; + final json = {}; void addIfPresent(String fieldName, dynamic value) { if (value != null) { @@ -1720,7 +1720,7 @@ class FillLayerProperties implements LayerProperties { @override Map toJson() { - final Map json = {}; + final json = {}; void addIfPresent(String fieldName, dynamic value) { if (value != null) { @@ -1901,7 +1901,7 @@ class FillExtrusionLayerProperties implements LayerProperties { @override Map toJson() { - final Map json = {}; + final json = {}; void addIfPresent(String fieldName, dynamic value) { if (value != null) { @@ -2078,7 +2078,7 @@ class RasterLayerProperties implements LayerProperties { @override Map toJson() { - final Map json = {}; + final json = {}; void addIfPresent(String fieldName, dynamic value) { if (value != null) { @@ -2228,7 +2228,7 @@ class HillshadeLayerProperties implements LayerProperties { @override Map toJson() { - final Map json = {}; + final json = {}; void addIfPresent(String fieldName, dynamic value) { if (value != null) { @@ -2358,7 +2358,7 @@ class HeatmapLayerProperties implements LayerProperties { @override Map toJson() { - final Map json = {}; + final json = {}; void addIfPresent(String fieldName, dynamic value) { if (value != null) { diff --git a/maplibre_gl/lib/src/maplibre_map.dart b/maplibre_gl/lib/src/maplibre_map.dart index a515dc10d..15a9aebf1 100644 --- a/maplibre_gl/lib/src/maplibre_map.dart +++ b/maplibre_gl/lib/src/maplibre_map.dart @@ -60,9 +60,8 @@ class MapLibreMap extends StatefulWidget { AnnotationType.circle, ], }) : assert( - myLocationRenderMode != MyLocationRenderMode.normal - ? myLocationEnabled - : true, + myLocationRenderMode == MyLocationRenderMode.normal || + myLocationEnabled, "$myLocationRenderMode requires [myLocationEnabled] set to true.", ), assert(annotationOrder.length <= 4), @@ -262,7 +261,7 @@ class _MapLibreMapState extends State { assert( widget.annotationOrder.toSet().length == widget.annotationOrder.length, "annotationOrder must not have duplicate types"); - final Map creationParams = { + final creationParams = { 'initialCameraPosition': widget.initialCameraPosition.toMap(), 'styleString': widget.styleString, 'options': _MapLibreMapOptions.fromWidget(widget).toMap(), @@ -282,7 +281,7 @@ class _MapLibreMapState extends State { } @override - void dispose() async { + Future dispose() async { super.dispose(); if (_controller.isCompleted) { final controller = await _controller.future; @@ -293,24 +292,22 @@ class _MapLibreMapState extends State { @override void didUpdateWidget(MapLibreMap oldWidget) { super.didUpdateWidget(oldWidget); - final _MapLibreMapOptions newOptions = - _MapLibreMapOptions.fromWidget(widget); - final Map updates = - _maplibreMapOptions.updatesMap(newOptions); + final newOptions = _MapLibreMapOptions.fromWidget(widget); + final updates = _maplibreMapOptions.updatesMap(newOptions); _updateOptions(updates); _maplibreMapOptions = newOptions; } - void _updateOptions(Map updates) async { + Future _updateOptions(Map updates) async { if (updates.isEmpty) { return; } - final MapLibreMapController controller = await _controller.future; + final controller = await _controller.future; controller._updateMapOptions(updates); } Future onPlatformViewCreated(int id) async { - final MapLibreMapController controller = MapLibreMapController( + final controller = MapLibreMapController( maplibrePlatform: _maplibrePlatform, initialCameraPosition: widget.initialCameraPosition, onStyleLoadedCallback: () { @@ -332,9 +329,7 @@ class _MapLibreMapState extends State { ); await _maplibrePlatform.initPlatform(id); _controller.complete(controller); - if (widget.onMapCreated != null) { - widget.onMapCreated!(controller); - } + widget.onMapCreated?.call(controller); } } @@ -364,29 +359,28 @@ class _MapLibreMapOptions { this.attributionButtonMargins, }); - static _MapLibreMapOptions fromWidget(MapLibreMap map) { - return _MapLibreMapOptions( - compassEnabled: map.compassEnabled, - cameraTargetBounds: map.cameraTargetBounds, - styleString: map.styleString, - minMaxZoomPreference: map.minMaxZoomPreference, - rotateGesturesEnabled: map.rotateGesturesEnabled, - scrollGesturesEnabled: map.scrollGesturesEnabled, - tiltGesturesEnabled: map.tiltGesturesEnabled, - trackCameraPosition: map.trackCameraPosition, - zoomGesturesEnabled: map.zoomGesturesEnabled, - doubleClickZoomEnabled: - map.doubleClickZoomEnabled ?? map.zoomGesturesEnabled, - myLocationEnabled: map.myLocationEnabled, - myLocationTrackingMode: map.myLocationTrackingMode, - myLocationRenderMode: map.myLocationRenderMode, - logoViewMargins: map.logoViewMargins, - compassViewPosition: map.compassViewPosition, - compassViewMargins: map.compassViewMargins, - attributionButtonPosition: map.attributionButtonPosition, - attributionButtonMargins: map.attributionButtonMargins, - ); - } + _MapLibreMapOptions.fromWidget(MapLibreMap map) + : this( + compassEnabled: map.compassEnabled, + cameraTargetBounds: map.cameraTargetBounds, + styleString: map.styleString, + minMaxZoomPreference: map.minMaxZoomPreference, + rotateGesturesEnabled: map.rotateGesturesEnabled, + scrollGesturesEnabled: map.scrollGesturesEnabled, + tiltGesturesEnabled: map.tiltGesturesEnabled, + trackCameraPosition: map.trackCameraPosition, + zoomGesturesEnabled: map.zoomGesturesEnabled, + doubleClickZoomEnabled: + map.doubleClickZoomEnabled ?? map.zoomGesturesEnabled, + myLocationEnabled: map.myLocationEnabled, + myLocationTrackingMode: map.myLocationTrackingMode, + myLocationRenderMode: map.myLocationRenderMode, + logoViewMargins: map.logoViewMargins, + compassViewPosition: map.compassViewPosition, + compassViewMargins: map.compassViewMargins, + attributionButtonPosition: map.attributionButtonPosition, + attributionButtonMargins: map.attributionButtonMargins, + ); final bool? compassEnabled; @@ -433,7 +427,7 @@ class _MapLibreMapOptions { }; Map toMap() { - final Map optionsMap = {}; + final optionsMap = {}; void addIfNonNull(String fieldName, dynamic value) { if (value != null) { @@ -474,7 +468,7 @@ class _MapLibreMapOptions { } Map updatesMap(_MapLibreMapOptions newOptions) { - final Map prevOptionsMap = toMap(); + final prevOptionsMap = toMap(); final newOptionsMap = newOptions.toMap(); // if any gesture is updated also all other gestures have to the saved to diff --git a/maplibre_gl/lib/src/offline_region.dart b/maplibre_gl/lib/src/offline_region.dart index 53a8cdab0..e5e70cc76 100644 --- a/maplibre_gl/lib/src/offline_region.dart +++ b/maplibre_gl/lib/src/offline_region.dart @@ -19,10 +19,10 @@ class OfflineRegionDefinition { @override String toString() => - "$runtimeType, bounds = $bounds, mapStyleUrl = $mapStyleUrl, minZoom = $minZoom, maxZoom = $maxZoom"; + "OfflineRegionDefinition, bounds = $bounds, mapStyleUrl = $mapStyleUrl, minZoom = $minZoom, maxZoom = $maxZoom"; Map toMap() { - final Map data = {}; + final data = {}; data['bounds'] = bounds.toList(); data['mapStyleUrl'] = mapStyleUrl; data['minZoom'] = minZoom; @@ -72,5 +72,5 @@ class OfflineRegion { @override String toString() => - "$runtimeType, id = $id, definition = $definition, metadata = $metadata"; + "OfflineRegion, id = $id, definition = $definition, metadata = $metadata"; } diff --git a/maplibre_gl_platform_interface/lib/src/callbacks.dart b/maplibre_gl_platform_interface/lib/src/callbacks.dart index 48ee24b88..fe3bd9cdd 100644 --- a/maplibre_gl_platform_interface/lib/src/callbacks.dart +++ b/maplibre_gl_platform_interface/lib/src/callbacks.dart @@ -23,12 +23,11 @@ class ArgumentCallbacks { /// method and is unaffected by any changes subsequently made to this /// collection. void call(T argument) { - final int length = _callbacks.length; + final length = _callbacks.length; if (length == 1) { _callbacks[0].call(argument); } else if (0 < length) { - for (ArgumentCallback callback - in List>.from(_callbacks)) { + for (final callback in List>.from(_callbacks)) { callback(argument); } } diff --git a/maplibre_gl_platform_interface/lib/src/camera.dart b/maplibre_gl_platform_interface/lib/src/camera.dart index 8e9651338..a9ad87780 100644 --- a/maplibre_gl_platform_interface/lib/src/camera.dart +++ b/maplibre_gl_platform_interface/lib/src/camera.dart @@ -7,6 +7,7 @@ part of '../maplibre_gl_platform_interface.dart'; /// The position of the map "camera", the view point from which the world is /// shown in the map view. Aggregates the camera's [target] geographical /// location, its [zoom] level, [tilt] angle, and [bearing]. +@immutable class CameraPosition { const CameraPosition({ this.bearing = 0.0, @@ -92,42 +93,34 @@ class CameraUpdate { CameraUpdate._(this._json); /// Returns a camera update that moves the camera to the specified position. - static CameraUpdate newCameraPosition(CameraPosition cameraPosition) { - return CameraUpdate._( - ['newCameraPosition', cameraPosition.toMap()], - ); - } + CameraUpdate.newCameraPosition(CameraPosition cameraPosition) + : this._(['newCameraPosition', cameraPosition.toMap()]); /// Returns a camera update that moves the camera target to the specified /// geographical location. - static CameraUpdate newLatLng(LatLng latLng) { - return CameraUpdate._(['newLatLng', latLng.toJson()]); - } + CameraUpdate.newLatLng(LatLng latLng) + : this._(['newLatLng', latLng.toJson()]); /// Returns a camera update that transforms the camera so that the specified /// geographical bounding box is centered in the map view at the greatest /// possible zoom level. A non-zero [left], [top], [right] and [bottom] padding /// insets the bounding box from the map view's edges. /// The camera's new tilt and bearing will both be 0.0. - static CameraUpdate newLatLngBounds(LatLngBounds bounds, - {double left = 0, double top = 0, double right = 0, double bottom = 0}) { - return CameraUpdate._([ - 'newLatLngBounds', - bounds.toList(), - left, - top, - right, - bottom, - ]); - } + CameraUpdate.newLatLngBounds(LatLngBounds bounds, + {double left = 0, double top = 0, double right = 0, double bottom = 0}) + : this._([ + 'newLatLngBounds', + bounds.toList(), + left, + top, + right, + bottom, + ]); /// Returns a camera update that moves the camera target to the specified /// geographical location and zoom level. - static CameraUpdate newLatLngZoom(LatLng latLng, double zoom) { - return CameraUpdate._( - ['newLatLngZoom', latLng.toJson(), zoom], - ); - } + CameraUpdate.newLatLngZoom(LatLng latLng, double zoom) + : this._(['newLatLngZoom', latLng.toJson(), zoom]); /// Returns a camera update that moves the camera target the specified screen /// distance. @@ -135,16 +128,13 @@ class CameraUpdate { /// For a camera with bearing 0.0 (pointing north), scrolling by 50,75 moves /// the camera's target to a geographical location that is 50 to the east and /// 75 to the south of the current location, measured in screen coordinates. - static CameraUpdate scrollBy(double dx, double dy) { - return CameraUpdate._( - ['scrollBy', dx, dy], - ); - } + CameraUpdate.scrollBy(double dx, double dy) + : this._(['scrollBy', dx, dy]); /// Returns a camera update that modifies the camera zoom level by the /// specified amount. The optional [focus] is a screen point whose underlying /// geographical location should be invariant, if possible, by the movement. - static CameraUpdate zoomBy(double amount, [Offset? focus]) { + factory CameraUpdate.zoomBy(double amount, [Offset? focus]) { if (focus == null) { return CameraUpdate._(['zoomBy', amount]); } else { @@ -160,32 +150,23 @@ class CameraUpdate { /// closer to the surface of the Earth. /// /// Equivalent to the result of calling `zoomBy(1.0)`. - static CameraUpdate zoomIn() { - return CameraUpdate._(['zoomIn']); - } + CameraUpdate.zoomIn() : this._(['zoomIn']); /// Returns a camera update that zooms the camera out, bringing the camera /// further away from the surface of the Earth. /// /// Equivalent to the result of calling `zoomBy(-1.0)`. - static CameraUpdate zoomOut() { - return CameraUpdate._(['zoomOut']); - } + CameraUpdate.zoomOut() : this._(['zoomOut']); /// Returns a camera update that sets the camera zoom level. - static CameraUpdate zoomTo(double zoom) { - return CameraUpdate._(['zoomTo', zoom]); - } + CameraUpdate.zoomTo(double zoom) : this._(['zoomTo', zoom]); /// Returns a camera update that sets the camera bearing. - static CameraUpdate bearingTo(double bearing) { - return CameraUpdate._(['bearingTo', bearing]); - } + CameraUpdate.bearingTo(double bearing) + : this._(['bearingTo', bearing]); /// Returns a camera update that sets the camera bearing. - static CameraUpdate tiltTo(double tilt) { - return CameraUpdate._(['tiltTo', tilt]); - } + CameraUpdate.tiltTo(double tilt) : this._(['tiltTo', tilt]); final dynamic _json; diff --git a/maplibre_gl_platform_interface/lib/src/circle.dart b/maplibre_gl_platform_interface/lib/src/circle.dart index 9c80815b9..bee69ee55 100644 --- a/maplibre_gl_platform_interface/lib/src/circle.dart +++ b/maplibre_gl_platform_interface/lib/src/circle.dart @@ -92,7 +92,7 @@ class CircleOptions { } dynamic toJson([bool addGeometry = true]) { - final Map json = {}; + final json = {}; void addIfPresent(String fieldName, dynamic value) { if (value != null) { diff --git a/maplibre_gl_platform_interface/lib/src/fill.dart b/maplibre_gl_platform_interface/lib/src/fill.dart index b19f5d2c2..c2913e589 100644 --- a/maplibre_gl_platform_interface/lib/src/fill.dart +++ b/maplibre_gl_platform_interface/lib/src/fill.dart @@ -8,10 +8,10 @@ part of '../maplibre_gl_platform_interface.dart'; FillOptions translateFillOptions(FillOptions options, LatLng delta) { if (options.geometry != null) { - List> newGeometry = []; - for (var ring in options.geometry!) { - List newRing = []; - for (var coords in ring) { + final newGeometry = >[]; + for (final ring in options.geometry!) { + final newRing = []; + for (final coords in ring) { newRing.add(coords + delta); } newGeometry.add(newRing); @@ -94,7 +94,7 @@ class FillOptions { } dynamic toJson([bool addGeometry = true]) { - final Map json = {}; + final json = {}; void addIfPresent(String fieldName, dynamic value) { if (value != null) { diff --git a/maplibre_gl_platform_interface/lib/src/line.dart b/maplibre_gl_platform_interface/lib/src/line.dart index 2d2f30e37..98599572c 100644 --- a/maplibre_gl_platform_interface/lib/src/line.dart +++ b/maplibre_gl_platform_interface/lib/src/line.dart @@ -95,7 +95,7 @@ class LineOptions { } dynamic toJson([bool addGeometry = true]) { - final Map json = {}; + final json = {}; void addIfPresent(String fieldName, dynamic value) { if (value != null) { diff --git a/maplibre_gl_platform_interface/lib/src/location.dart b/maplibre_gl_platform_interface/lib/src/location.dart index 075aa2dc1..d8b540aa9 100644 --- a/maplibre_gl_platform_interface/lib/src/location.dart +++ b/maplibre_gl_platform_interface/lib/src/location.dart @@ -5,6 +5,7 @@ part of '../maplibre_gl_platform_interface.dart'; /// A pair of latitude and longitude coordinates, stored as degrees. +@immutable class LatLng { /// Creates a geographical location specified in degrees [latitude] and /// [longitude]. @@ -40,12 +41,10 @@ class LatLng { return [longitude, latitude]; } - static LatLng _fromJson(List json) { - return LatLng(json[0], json[1]); - } + LatLng._fromJson(List json) : this(json[0], json[1]); @override - String toString() => '$runtimeType($latitude, $longitude)'; + String toString() => 'LatLng($latitude, $longitude)'; @override bool operator ==(Object other) { @@ -66,6 +65,7 @@ class LatLng { /// if `southwest.longitude` ≤ `northeast.longitude`, /// * lng ∈ [-180, `northeast.longitude`] ∪ [`southwest.longitude`, 180[, /// if `northeast.longitude` < `southwest.longitude` +@immutable class LatLngBounds { /// Creates geographical bounding box with the specified corners. /// @@ -97,7 +97,7 @@ class LatLngBounds { @override String toString() { - return '$runtimeType($southwest, $northeast)'; + return 'LatLngBounds($southwest, $northeast)'; } @override @@ -113,6 +113,7 @@ class LatLngBounds { /// A geographical area representing a non-aligned quadrilateral /// This class does not wrap values to the world bounds +@immutable class LatLngQuad { const LatLngQuad({ required this.topLeft, @@ -153,7 +154,7 @@ class LatLngQuad { @override String toString() { - return '$runtimeType($topLeft, $topRight, $bottomRight, $bottomLeft)'; + return 'LatLngQuad($topLeft, $topRight, $bottomRight, $bottomLeft)'; } @override @@ -235,6 +236,7 @@ class UserHeading { /// Returns a timestamp for when the magnetic heading was determined. final DateTime timestamp; + const UserHeading( {required this.magneticHeading, required this.trueHeading, diff --git a/maplibre_gl_platform_interface/lib/src/maplibre_gl_platform_interface.dart b/maplibre_gl_platform_interface/lib/src/maplibre_gl_platform_interface.dart index c54a4dfd2..9f6bb1a86 100644 --- a/maplibre_gl_platform_interface/lib/src/maplibre_gl_platform_interface.dart +++ b/maplibre_gl_platform_interface/lib/src/maplibre_gl_platform_interface.dart @@ -17,10 +17,6 @@ abstract class MapLibrePlatform { static MapLibrePlatform Function() createInstance = () => _instance ?? MapLibreMethodChannel(); - static set instance(MapLibreMethodChannel instance) { - _instance = instance; - } - final onInfoWindowTappedPlatform = ArgumentCallbacks(); final onFeatureTappedPlatform = ArgumentCallbacks>(); diff --git a/maplibre_gl_platform_interface/lib/src/method_channel_maplibre_gl.dart b/maplibre_gl_platform_interface/lib/src/method_channel_maplibre_gl.dart index db317365b..d2b4ccccd 100644 --- a/maplibre_gl_platform_interface/lib/src/method_channel_maplibre_gl.dart +++ b/maplibre_gl_platform_interface/lib/src/method_channel_maplibre_gl.dart @@ -11,7 +11,6 @@ class MapLibreMethodChannel extends MapLibrePlatform { if (symbolId != null) { onInfoWindowTappedPlatform(symbolId); } - break; case 'feature#onTap': final id = call.arguments['id']; @@ -24,7 +23,6 @@ class MapLibreMethodChannel extends MapLibrePlatform { 'point': Point(x, y), 'latLng': LatLng(lat, lng) }); - break; case 'feature#onDrag': final id = call.arguments['id']; final double x = call.arguments['x']; @@ -47,24 +45,18 @@ class MapLibreMethodChannel extends MapLibrePlatform { 'delta': LatLng(deltaLat, deltaLng), 'eventType': eventType, }); - break; - case 'camera#onMoveStarted': onCameraMoveStartedPlatform(null); - break; case 'camera#onMove': final cameraPosition = CameraPosition.fromMap(call.arguments['position'])!; onCameraMovePlatform(cameraPosition); - break; case 'camera#onIdle': final cameraPosition = CameraPosition.fromMap(call.arguments['position']); onCameraIdlePlatform(cameraPosition); - break; case 'map#onStyleLoaded': onMapStyleLoadedPlatform(null); - break; case 'map#onMapClick': final double x = call.arguments['x']; final double y = call.arguments['y']; @@ -72,7 +64,6 @@ class MapLibreMethodChannel extends MapLibrePlatform { final double lat = call.arguments['lat']; onMapClickPlatform( {'point': Point(x, y), 'latLng': LatLng(lat, lng)}); - break; case 'map#onMapLongClick': final double x = call.arguments['x']; final double y = call.arguments['y']; @@ -80,18 +71,13 @@ class MapLibreMethodChannel extends MapLibrePlatform { final double lat = call.arguments['lat']; onMapLongClickPlatform( {'point': Point(x, y), 'latLng': LatLng(lat, lng)}); - - break; case 'map#onCameraTrackingChanged': final int mode = call.arguments['mode']; onCameraTrackingChangedPlatform(MyLocationTrackingMode.values[mode]); - break; case 'map#onCameraTrackingDismissed': onCameraTrackingDismissedPlatform(null); - break; case 'map#onIdle': onMapIdlePlatform(null); - break; case 'map#onUserLocationUpdated': final dynamic userLocation = call.arguments['userLocation']; final dynamic heading = call.arguments['heading']; @@ -119,7 +105,6 @@ class MapLibreMethodChannel extends MapLibrePlatform { ), timestamp: DateTime.fromMillisecondsSinceEpoch( userLocation['timestamp']))); - break; default: throw MissingPluginException(); } @@ -209,7 +194,7 @@ class MapLibreMethodChannel extends MapLibrePlatform { @override Future animateCamera(cameraUpdate, {Duration? duration}) async { - return await _channel.invokeMethod('camera#animate', { + return _channel.invokeMethod('camera#animate', { 'cameraUpdate': cameraUpdate.toJson(), 'duration': duration?.inMilliseconds, }); @@ -217,7 +202,7 @@ class MapLibreMethodChannel extends MapLibrePlatform { @override Future moveCamera(CameraUpdate cameraUpdate) async { - return await _channel.invokeMethod('camera#move', { + return _channel.invokeMethod('camera#move', { 'cameraUpdate': cameraUpdate.toJson(), }); } @@ -339,9 +324,10 @@ class MapLibreMethodChannel extends MapLibrePlatform { @override Future requestMyLocationLatLng() async { try { - final Map reply = await _channel.invokeMethod( - 'locationComponent#getLastLocation', null); - double latitude = 0.0, longitude = 0.0; + final Map reply = + await _channel.invokeMethod('locationComponent#getLastLocation'); + var latitude = 0.0; + var longitude = 0.0; if (reply.containsKey('latitude') && reply['latitude'] != null) { latitude = double.parse(reply['latitude'].toString()); } @@ -358,7 +344,7 @@ class MapLibreMethodChannel extends MapLibrePlatform { Future getVisibleRegion() async { try { final Map reply = - await _channel.invokeMethod('map#getVisibleRegion', null); + await _channel.invokeMethod('map#getVisibleRegion'); final southwest = reply['sw'] as List; final northeast = reply['ne'] as List; return LatLngBounds( @@ -420,7 +406,7 @@ class MapLibreMethodChannel extends MapLibrePlatform { @override Future toScreenLocation(LatLng latLng) async { try { - var screenPosMap = + final screenPosMap = await _channel.invokeMethod('map#toScreenLocation', { 'latitude': latLng.latitude, 'longitude': latLng.longitude, @@ -434,15 +420,15 @@ class MapLibreMethodChannel extends MapLibrePlatform { @override Future> toScreenLocationBatch(Iterable latLngs) async { try { - var coordinates = Float64List.fromList(latLngs + final coordinates = Float64List.fromList(latLngs .map((e) => [e.latitude, e.longitude]) .expand((e) => e) .toList()); - Float64List result = await _channel.invokeMethod( + final Float64List result = await _channel.invokeMethod( 'map#toScreenLocationBatch', {"coordinates": coordinates}); - var points = []; - for (int i = 0; i < result.length; i += 2) { + final points = []; + for (var i = 0; i < result.length; i += 2) { points.add(Point(result[i], result[i + 1])); } @@ -519,7 +505,7 @@ class MapLibreMethodChannel extends MapLibrePlatform { @override Future getFilter(String layerId) async { try { - Map reply = + final Map reply = await _channel.invokeMethod('style#getFilter', { 'layerId': layerId, }); @@ -533,7 +519,7 @@ class MapLibreMethodChannel extends MapLibrePlatform { @override Future toLatLng(Point screenLocation) async { try { - var latLngMap = + final latLngMap = await _channel.invokeMethod('map#toLatLng', { 'x': screenLocation.x, 'y': screenLocation.y, @@ -547,7 +533,7 @@ class MapLibreMethodChannel extends MapLibrePlatform { @override Future getMetersPerPixelAtLatitude(double latitude) async { try { - var latLngMap = await _channel + final latLngMap = await _channel .invokeMethod('map#getMetersPerPixelAtLatitude', { 'latitude': latitude, }); diff --git a/maplibre_gl_platform_interface/lib/src/source_properties.dart b/maplibre_gl_platform_interface/lib/src/source_properties.dart index 79e58f6ad..d0da46ce6 100644 --- a/maplibre_gl_platform_interface/lib/src/source_properties.dart +++ b/maplibre_gl_platform_interface/lib/src/source_properties.dart @@ -105,7 +105,7 @@ class VectorSourceProperties implements SourceProperties { @override Map toJson() { - final Map json = {}; + final json = {}; void addIfPresent(String fieldName, dynamic value) { if (value != null) { @@ -236,7 +236,7 @@ class RasterSourceProperties implements SourceProperties { @override Map toJson() { - final Map json = {}; + final json = {}; void addIfPresent(String fieldName, dynamic value) { if (value != null) { @@ -370,7 +370,7 @@ class RasterDemSourceProperties implements SourceProperties { @override Map toJson() { - final Map json = {}; + final json = {}; void addIfPresent(String fieldName, dynamic value) { if (value != null) { @@ -554,7 +554,7 @@ class GeojsonSourceProperties implements SourceProperties { @override Map toJson() { - final Map json = {}; + final json = {}; void addIfPresent(String fieldName, dynamic value) { if (value != null) { @@ -624,7 +624,7 @@ class VideoSourceProperties implements SourceProperties { @override Map toJson() { - final Map json = {}; + final json = {}; void addIfPresent(String fieldName, dynamic value) { if (value != null) { @@ -674,7 +674,7 @@ class ImageSourceProperties implements SourceProperties { @override Map toJson() { - final Map json = {}; + final json = {}; void addIfPresent(String fieldName, dynamic value) { if (value != null) { diff --git a/maplibre_gl_platform_interface/lib/src/symbol.dart b/maplibre_gl_platform_interface/lib/src/symbol.dart index e54558855..978bb4a28 100644 --- a/maplibre_gl_platform_interface/lib/src/symbol.dart +++ b/maplibre_gl_platform_interface/lib/src/symbol.dart @@ -157,7 +157,7 @@ class SymbolOptions { } dynamic toJson([bool addGeometry = true]) { - final Map json = {}; + final json = {}; void addIfPresent(String fieldName, dynamic value) { if (value != null) { diff --git a/maplibre_gl_platform_interface/lib/src/ui.dart b/maplibre_gl_platform_interface/lib/src/ui.dart index 2b7212787..abeebfc98 100644 --- a/maplibre_gl_platform_interface/lib/src/ui.dart +++ b/maplibre_gl_platform_interface/lib/src/ui.dart @@ -44,6 +44,7 @@ enum AttributionButtonPosition { /// Used with [_MapLibreMapOptions] to wrap a [LatLngBounds] value. This allows /// distinguishing between specifying an unbounded target (null `LatLngBounds`) /// from not specifying anything (null `CameraTargetBounds`). +@immutable class CameraTargetBounds { /// Creates a camera target bounds with the specified bounding box, or null /// to indicate that the camera target is not bounded. @@ -79,6 +80,7 @@ class CameraTargetBounds { /// Used with [_MapLibreMapOptions] to wrap min and max zoom. This allows /// distinguishing between specifying unbounded zooming (null [minZoom] and /// [maxZoom]) from not specifying anything (null [MinMaxZoomPreference]). +@immutable class MinMaxZoomPreference { const MinMaxZoomPreference(this.minZoom, this.maxZoom) : assert(minZoom == null || maxZoom == null || minZoom <= maxZoom); diff --git a/maplibre_gl_web/lib/src/convert.dart b/maplibre_gl_web/lib/src/convert.dart index 65a62bfa0..1f8e2245c 100644 --- a/maplibre_gl_web/lib/src/convert.dart +++ b/maplibre_gl_web/lib/src/convert.dart @@ -203,7 +203,7 @@ class Convert { static Feature interpretSymbolOptions( SymbolOptions options, Feature feature) { - var properties = feature.properties; + final properties = feature.properties; var geometry = feature.geometry; if (options.iconSize != null) { properties['iconSize'] = options.iconSize; @@ -299,7 +299,7 @@ class Convert { } static Feature interpretLineOptions(LineOptions options, Feature feature) { - var properties = feature.properties; + final properties = feature.properties; var geometry = feature.geometry; if (options.lineJoin != null) { properties['lineJoin'] = options.lineJoin; @@ -341,7 +341,7 @@ class Convert { static Feature interpretCircleOptions( CircleOptions options, Feature feature) { - var properties = feature.properties; + final properties = feature.properties; var geometry = feature.geometry; if (options.circleRadius != null) { properties['circleRadius'] = options.circleRadius; @@ -378,9 +378,9 @@ class Convert { static List>> fillGeometryToFeatureGeometry( List> geom) { - List>> convertedFill = []; + final convertedFill = >>[]; for (final ring in geom) { - List> convertedRing = []; + final convertedRing = >[]; for (final coords in ring) { convertedRing.add([coords.longitude, coords.latitude]); } @@ -391,9 +391,9 @@ class Convert { static List> featureGeometryToFillGeometry( List>> geom) { - List> convertedFill = []; + final convertedFill = >[]; for (final ring in geom) { - List convertedRing = []; + final convertedRing = []; for (final coords in ring) { convertedRing.add(LatLng(coords[1], coords[0])); } @@ -403,7 +403,7 @@ class Convert { } static Feature intepretFillOptions(FillOptions options, Feature feature) { - var properties = feature.properties; + final properties = feature.properties; var geometry = feature.geometry; if (options.draggable != null) { properties['draggable'] = options.draggable; diff --git a/maplibre_gl_web/lib/src/geo/geojson.dart b/maplibre_gl_web/lib/src/geo/geojson.dart index f523c5544..0450f2c59 100644 --- a/maplibre_gl_web/lib/src/geo/geojson.dart +++ b/maplibre_gl_web/lib/src/geo/geojson.dart @@ -1,5 +1,3 @@ -library maplibre.geo.geojson; - import 'package:js/js_util.dart'; import 'package:maplibre_gl_web/src/interop/interop.dart'; import 'package:maplibre_gl_web/src/utils.dart'; diff --git a/maplibre_gl_web/lib/src/geo/lng_lat.dart b/maplibre_gl_web/lib/src/geo/lng_lat.dart index 62a88c2ae..4a0fbe58d 100644 --- a/maplibre_gl_web/lib/src/geo/lng_lat.dart +++ b/maplibre_gl_web/lib/src/geo/lng_lat.dart @@ -1,5 +1,3 @@ -library maplibre.geo.lng_lat; - import 'package:maplibre_gl_web/src/geo/lng_lat_bounds.dart'; import 'package:maplibre_gl_web/src/interop/interop.dart'; @@ -80,8 +78,8 @@ class LngLat extends JsObjectWrapper { /// var arr = [-73.9749, 40.7736]; /// var ll = maplibregl.LngLat.convert(arr); /// ll; // = LngLat {lng: -73.9749, lat: 40.7736} - static LngLat convert(dynamic input) => - LngLat.fromJsObject(LngLatJsImpl.convert(input)); + LngLat.convert(dynamic input) + : this.fromJsObject(LngLatJsImpl.convert(input)); /// Creates a new LngLat from a [jsObject]. LngLat.fromJsObject(super.jsObject) : super.fromJsObject(); diff --git a/maplibre_gl_web/lib/src/geo/lng_lat_bounds.dart b/maplibre_gl_web/lib/src/geo/lng_lat_bounds.dart index a620954e0..7eb9110e9 100644 --- a/maplibre_gl_web/lib/src/geo/lng_lat_bounds.dart +++ b/maplibre_gl_web/lib/src/geo/lng_lat_bounds.dart @@ -1,5 +1,3 @@ -library maplibre.geo.lng_lat_bounds; - import 'package:maplibre_gl_web/src/geo/lng_lat.dart'; import 'package:maplibre_gl_web/src/interop/interop.dart'; @@ -139,8 +137,8 @@ class LngLatBounds extends JsObjectWrapper { /// var arr = [[-73.9876, 40.7661], [-73.9397, 40.8002]]; /// var llb = maplibregl.LngLatBounds.convert(arr); /// llb; // = LngLatBounds {_sw: LngLat {lng: -73.9876, lat: 40.7661}, _ne: LngLat {lng: -73.9397, lat: 40.8002}} - static LngLatBounds convert(dynamic input) => - LngLatBounds.fromJsObject(LngLatBoundsJsImpl.convert(input)); + LngLatBounds.convert(dynamic input) + : this.fromJsObject(LngLatBoundsJsImpl.convert(input)); /// Creates a new LngLatBounds from a [jsObject]. LngLatBounds.fromJsObject(super.jsObject) : super.fromJsObject(); diff --git a/maplibre_gl_web/lib/src/geo/point.dart b/maplibre_gl_web/lib/src/geo/point.dart index db631abc8..f44065eef 100644 --- a/maplibre_gl_web/lib/src/geo/point.dart +++ b/maplibre_gl_web/lib/src/geo/point.dart @@ -1,5 +1,3 @@ -library maplibre.geo.point; - import 'package:maplibre_gl_web/src/interop/interop.dart'; class Point extends JsObjectWrapper { diff --git a/maplibre_gl_web/lib/src/interop/interop.dart b/maplibre_gl_web/lib/src/interop/interop.dart index 52a797c09..3a31bacfc 100644 --- a/maplibre_gl_web/lib/src/interop/interop.dart +++ b/maplibre_gl_web/lib/src/interop/interop.dart @@ -1,5 +1,3 @@ -library maplibre.interop; - export 'geo/geojson_interop.dart'; export 'geo/lng_lat_bounds_interop.dart'; export 'geo/lng_lat_interop.dart'; diff --git a/maplibre_gl_web/lib/src/interop/style/layers/circle_layer_interop.dart b/maplibre_gl_web/lib/src/interop/style/layers/circle_layer_interop.dart index 8a6eec60a..e1c8cc9b9 100644 --- a/maplibre_gl_web/lib/src/interop/style/layers/circle_layer_interop.dart +++ b/maplibre_gl_web/lib/src/interop/style/layers/circle_layer_interop.dart @@ -1,5 +1,3 @@ -library maplibre.interop.style.layers.circle_layer; - import 'package:js/js_util.dart'; import 'package:maplibre_gl_web/src/style/layers/circle_layer.dart'; @@ -7,7 +5,7 @@ class CircleLayerJsImpl { static toJs(CircleLayer circleLayer) => jsify(toDict(circleLayer)); static toDict(CircleLayer circleLayer) { - Map dict = { + final dict = { 'id': circleLayer.id, 'type': 'circle', }; @@ -30,7 +28,7 @@ class CirclePaintJsImpl { static toJs(CirclePaint circlePaint) => jsify(toDict(circlePaint)); static toDict(CirclePaint circlePaint) { - Map dict = {}; + final dict = {}; if (circlePaint.circleRadius != null) { dict['circle-radius'] = circlePaint.circleRadius; } diff --git a/maplibre_gl_web/lib/src/interop/style/layers/line_layer_interop.dart b/maplibre_gl_web/lib/src/interop/style/layers/line_layer_interop.dart index d8e548b6c..f843af268 100644 --- a/maplibre_gl_web/lib/src/interop/style/layers/line_layer_interop.dart +++ b/maplibre_gl_web/lib/src/interop/style/layers/line_layer_interop.dart @@ -1,5 +1,3 @@ -library maplibre.interop.style.layers.line_layer; - import 'package:js/js_util.dart'; import 'package:maplibre_gl_web/src/style/layers/line_layer.dart'; @@ -7,7 +5,7 @@ class LineLayerJsImpl { static toJs(LineLayer lineLayer) => jsify(toDict(lineLayer)); static toDict(LineLayer lineLayer) { - Map dict = { + final dict = { 'id': lineLayer.id, 'type': 'line', }; @@ -35,7 +33,7 @@ class LinePaintJsImpl { static toJs(LinePaint linePaint) => jsify(toDict(linePaint)); static toDict(LinePaint linePaint) { - Map dict = {}; + final dict = {}; if (linePaint.lineOpacity != null) { dict['line-opacity'] = linePaint.lineOpacity; } @@ -77,7 +75,7 @@ class LineLayoutJsImpl { static toJs(LineLayout lineLayout) => jsify(toDict(lineLayout)); static toDict(LineLayout lineLayout) { - Map dict = {}; + final dict = {}; if (lineLayout.lineCap != null) { dict['line-cap'] = lineLayout.lineCap; } diff --git a/maplibre_gl_web/lib/src/interop/style/layers/symbol_layer_interop.dart b/maplibre_gl_web/lib/src/interop/style/layers/symbol_layer_interop.dart index 5da48e352..fea76de17 100644 --- a/maplibre_gl_web/lib/src/interop/style/layers/symbol_layer_interop.dart +++ b/maplibre_gl_web/lib/src/interop/style/layers/symbol_layer_interop.dart @@ -1,5 +1,3 @@ -library maplibre.interop.style.layers.symbol_layer; - import 'package:js/js_util.dart'; import 'package:maplibre_gl_web/src/style/layers/symbol_layer.dart'; @@ -7,7 +5,7 @@ class SymbolLayerJsImpl { static toJs(SymbolLayer symbolLayer) => jsify(toDict(symbolLayer)); static toDict(SymbolLayer symbolLayer) { - Map dict = { + final dict = { 'id': symbolLayer.id, 'type': 'symbol', }; @@ -45,7 +43,7 @@ class SymbolPaintJsImpl { static toJs(SymbolPaint symbolPaint) => jsify(toDict(symbolPaint)); static toDict(SymbolPaint symbolPaint) { - Map dict = {}; + final dict = {}; if (symbolPaint.iconOpacity != null) { dict['icon-opacity'] = symbolPaint.iconOpacity; } @@ -96,7 +94,7 @@ class SymbolLayoutJsImpl { static toJs(SymbolLayout symbolLayout) => jsify(toDict(symbolLayout)); static toDict(SymbolLayout symbolLayout) { - Map dict = {}; + final dict = {}; if (symbolLayout.symbolAvoidEdges != null) { dict['symbol-avoid-edges'] = symbolLayout.symbolAvoidEdges; } diff --git a/maplibre_gl_web/lib/src/maplibre_web_gl_platform.dart b/maplibre_gl_web/lib/src/maplibre_web_gl_platform.dart index f9e601c4b..426f89f57 100644 --- a/maplibre_gl_web/lib/src/maplibre_web_gl_platform.dart +++ b/maplibre_gl_web/lib/src/maplibre_web_gl_platform.dart @@ -58,7 +58,7 @@ class MapLibreMapController extends MapLibrePlatform @override Future initPlatform(int id) async { if (_creationParams.containsKey('initialCameraPosition')) { - var camera = _creationParams['initialCameraPosition']; + final camera = _creationParams['initialCameraPosition']; _dragEnabled = _creationParams['dragEnabled'] ?? true; _map = MapLibreMap( @@ -101,23 +101,23 @@ class MapLibreMapController extends MapLibrePlatform _onMapResize(); }); }); - resizeObserver.observe(html.document.body as html.Element); + resizeObserver.observe(html.document.body!); } - void _loadFromAssets(Event event) async { + Future _loadFromAssets(Event event) async { final imagePath = event.id; - final ByteData bytes = await rootBundle.load(imagePath); + final bytes = await rootBundle.load(imagePath); await addImage(imagePath, bytes.buffer.asUint8List()); } _onMouseDown(Event e) { - var isDraggable = e.features[0].properties['draggable']; + final isDraggable = e.features[0].properties['draggable']; if (isDraggable != null && isDraggable) { // Prevent the default map drag behavior. e.preventDefault(); _draggedFeatureId = e.features[0].id; _map.getCanvas().style.cursor = 'grabbing'; - var coords = e.lngLat; + final coords = e.lngLat; _dragOrigin = LatLng(coords.lat as double, coords.lng as double); if (_draggedFeatureId != null) { @@ -268,7 +268,7 @@ class MapLibreMapController extends MapLibrePlatform @override Future queryRenderedFeatures( Point point, List layerIds, List? filter) async { - Map options = {}; + final options = {}; if (layerIds.isNotEmpty) { options['layers'] = layerIds; } @@ -296,7 +296,7 @@ class MapLibreMapController extends MapLibrePlatform @override Future queryRenderedFeaturesInRect( Rect rect, List layerIds, String? filter) async { - Map options = {}; + final options = {}; if (layerIds.isNotEmpty) { options['layers'] = layerIds; } @@ -324,7 +324,7 @@ class MapLibreMapController extends MapLibrePlatform @override Future querySourceFeatures( String sourceId, String? sourceLayerId, List? filter) async { - Map parameters = {}; + final parameters = {}; if (sourceLayerId != null) { parameters['sourceLayer'] = sourceLayerId; @@ -417,11 +417,11 @@ class MapLibreMapController extends MapLibrePlatform } void _onMapResize() { - Timer(const Duration(), () { - var container = _map.getContainer(); - var canvas = _map.getCanvas(); - var widthMismatch = canvas.clientWidth != container.clientWidth; - var heightMismatch = canvas.clientHeight != container.clientHeight; + Timer(Duration.zero, () { + final container = _map.getContainer(); + final canvas = _map.getCanvas(); + final widthMismatch = canvas.clientWidth != container.clientWidth; + final heightMismatch = canvas.clientHeight != container.clientHeight; if (widthMismatch || heightMismatch) { _map.resize(); } @@ -456,7 +456,7 @@ class MapLibreMapController extends MapLibrePlatform void _onCameraMove(_) { final center = _map.getCenter(); - var camera = CameraPosition( + final camera = CameraPosition( bearing: _map.getBearing() as double, target: LatLng(center.lat as double, center.lng as double), tilt: _map.getPitch() as double, @@ -467,7 +467,7 @@ class MapLibreMapController extends MapLibrePlatform void _onCameraIdle(_) { final center = _map.getCenter(); - var camera = CameraPosition( + final camera = CameraPosition( bearing: _map.getBearing() as double, target: LatLng(center.lat as double, center.lng as double), tilt: _map.getPitch() as double, @@ -535,28 +535,18 @@ class MapLibreMapController extends MapLibrePlatform if (_navigationControl != null) { prevShowCompass = _navigationControl!.options.showCompass; } - String? prevPosition = _navigationControlPosition; - - String? positionString; - switch (position) { - case CompassViewPosition.topRight: - positionString = 'top-right'; - break; - case CompassViewPosition.topLeft: - positionString = 'top-left'; - break; - case CompassViewPosition.bottomRight: - positionString = 'bottom-right'; - break; - case CompassViewPosition.bottomLeft: - positionString = 'bottom-left'; - break; - default: - positionString = null; - } + final prevPosition = _navigationControlPosition; + + final positionString = switch (position) { + CompassViewPosition.topRight => 'top-right', + CompassViewPosition.topLeft => 'top-left', + CompassViewPosition.bottomRight => 'bottom-right', + CompassViewPosition.bottomLeft => 'bottom-left', + _ => null, + }; - bool newShowCompass = compassEnabled ?? prevShowCompass ?? false; - String? newPosition = positionString ?? prevPosition; + final newShowCompass = compassEnabled ?? prevShowCompass ?? false; + final newPosition = positionString ?? prevPosition; _removeNavigationControl(); _navigationControl = NavigationControl(NavigationControlOptions( @@ -587,16 +577,12 @@ class MapLibreMapController extends MapLibrePlatform switch (position) { case AttributionButtonPosition.topRight: positionString = 'top-right'; - break; case AttributionButtonPosition.topLeft: positionString = 'top-left'; - break; case AttributionButtonPosition.bottomRight: positionString = 'bottom-right'; - break; case AttributionButtonPosition.bottomLeft: positionString = 'bottom-left'; - break; } _removeAttributionButton(); @@ -674,7 +660,7 @@ class MapLibreMapController extends MapLibrePlatform @override void setMyLocationEnabled(bool myLocationEnabled) { if (myLocationEnabled) { - _addGeolocateControl(trackUserLocation: false); + _addGeolocateControl(); } else { _removeGeolocateControl(); } @@ -692,7 +678,7 @@ class MapLibreMapController extends MapLibrePlatform return; } if (myLocationTrackingMode == 0) { - _addGeolocateControl(trackUserLocation: false); + _addGeolocateControl(); } else { print('Only one tracking mode available in web'); _addGeolocateControl(trackUserLocation: true); @@ -702,7 +688,7 @@ class MapLibreMapController extends MapLibrePlatform @override void setStyleString(String? styleString) { //remove old mouseenter callbacks to avoid multicalling - for (var layerId in _interactiveFeatureLayerIds) { + for (final layerId in _interactiveFeatureLayerIds) { _map.off('mouseenter', layerId, _onMouseEnterFeature); _map.off('mousemouve', layerId, _onMouseEnterFeature); _map.off('mouseleave', layerId, _onMouseLeaveFeature); @@ -724,14 +710,14 @@ class MapLibreMapController extends MapLibrePlatform @override Future toLatLng(Point screenLocation) async { - var lngLat = + final lngLat = _map.unproject(geo_point.Point(screenLocation.x, screenLocation.y)); return LatLng(lngLat.lat as double, lngLat.lng as double); } @override Future toScreenLocation(LatLng latLng) async { - var screenPosition = + final screenPosition = _map.project(LngLat(latLng.longitude, latLng.latitude)); final point = Point(screenPosition.x.round(), screenPosition.y.round()); @@ -742,7 +728,7 @@ class MapLibreMapController extends MapLibrePlatform Future>> toScreenLocationBatch( Iterable latLngs) async { return latLngs.map((latLng) { - var screenPosition = + final screenPosition = _map.project(LngLat(latLng.longitude, latLng.latitude)); return Point(screenPosition.x.round(), screenPosition.y.round()); }).toList(growable: false); @@ -751,8 +737,8 @@ class MapLibreMapController extends MapLibrePlatform @override Future getMetersPerPixelAtLatitude(double latitude) async { //https://wiki.openstreetmap.org/wiki/Zoom_levels - var circumference = 40075017.686; - var zoom = _map.getZoom(); + const circumference = 40075017.686; + final zoom = _map.getZoom(); return circumference * cos(latitude * (pi / 180)) / pow(2, zoom + 9); } diff --git a/maplibre_gl_web/lib/src/style/evaluation_parameters.dart b/maplibre_gl_web/lib/src/style/evaluation_parameters.dart index bacfd9085..ede955fd1 100644 --- a/maplibre_gl_web/lib/src/style/evaluation_parameters.dart +++ b/maplibre_gl_web/lib/src/style/evaluation_parameters.dart @@ -1,5 +1,3 @@ -library maplibre.style.evaluation_parameters; - import 'package:maplibre_gl_web/src/interop/interop.dart'; class EvaluationParameters extends JsObjectWrapper { diff --git a/maplibre_gl_web/lib/src/style/layers/circle_layer.dart b/maplibre_gl_web/lib/src/style/layers/circle_layer.dart index 882b68c9a..247c8b972 100644 --- a/maplibre_gl_web/lib/src/style/layers/circle_layer.dart +++ b/maplibre_gl_web/lib/src/style/layers/circle_layer.dart @@ -1,5 +1,3 @@ -library maplibre.style.layers.circle_layer; - import 'package:maplibre_gl_web/src/interop/style/layers/circle_layer_interop.dart'; import 'package:maplibre_gl_web/src/style/layers/layer.dart'; diff --git a/maplibre_gl_web/lib/src/style/layers/layer.dart b/maplibre_gl_web/lib/src/style/layers/layer.dart index 456c60b2f..d9038f8bf 100644 --- a/maplibre_gl_web/lib/src/style/layers/layer.dart +++ b/maplibre_gl_web/lib/src/style/layers/layer.dart @@ -1,5 +1,3 @@ -library maplibre.style.layers.layer; - abstract class Layer { /// JS object. dynamic get jsObject => throw Exception('jsObject not implemented!'); diff --git a/maplibre_gl_web/lib/src/style/layers/line_layer.dart b/maplibre_gl_web/lib/src/style/layers/line_layer.dart index b5e17f9c8..ba17429c3 100644 --- a/maplibre_gl_web/lib/src/style/layers/line_layer.dart +++ b/maplibre_gl_web/lib/src/style/layers/line_layer.dart @@ -1,5 +1,3 @@ -library maplibre.style.layers.line_layer; - import 'package:maplibre_gl_web/src/interop/style/layers/line_layer_interop.dart'; import 'package:maplibre_gl_web/src/style/layers/layer.dart'; diff --git a/maplibre_gl_web/lib/src/style/layers/symbol_layer.dart b/maplibre_gl_web/lib/src/style/layers/symbol_layer.dart index 974987e06..f9d38e875 100644 --- a/maplibre_gl_web/lib/src/style/layers/symbol_layer.dart +++ b/maplibre_gl_web/lib/src/style/layers/symbol_layer.dart @@ -1,5 +1,3 @@ -library maplibre.style.layers.symbol_layer; - import 'package:maplibre_gl_web/src/interop/style/layers/symbol_layer_interop.dart'; import 'package:maplibre_gl_web/src/style/layers/layer.dart'; diff --git a/maplibre_gl_web/lib/src/style/sources/geojson_source.dart b/maplibre_gl_web/lib/src/style/sources/geojson_source.dart index 0667e4d42..93f8358ea 100644 --- a/maplibre_gl_web/lib/src/style/sources/geojson_source.dart +++ b/maplibre_gl_web/lib/src/style/sources/geojson_source.dart @@ -1,5 +1,3 @@ -library maplibre.style.sources.geojson_source; - import 'package:maplibre_gl_web/src/geo/geojson.dart'; import 'package:maplibre_gl_web/src/interop/style/sources/geojson_source_interop.dart'; import 'package:maplibre_gl_web/src/style/sources/source.dart'; diff --git a/maplibre_gl_web/lib/src/style/sources/source.dart b/maplibre_gl_web/lib/src/style/sources/source.dart index 2907f1fc7..40fa29239 100644 --- a/maplibre_gl_web/lib/src/style/sources/source.dart +++ b/maplibre_gl_web/lib/src/style/sources/source.dart @@ -1,5 +1,3 @@ -library maplibre.style.sources.source; - abstract class Source { final T jsObject; diff --git a/maplibre_gl_web/lib/src/style/sources/vector_source.dart b/maplibre_gl_web/lib/src/style/sources/vector_source.dart index 463b464a4..34af784bf 100644 --- a/maplibre_gl_web/lib/src/style/sources/vector_source.dart +++ b/maplibre_gl_web/lib/src/style/sources/vector_source.dart @@ -1,5 +1,3 @@ -library maplibre.style.sources.vector_source; - import 'package:maplibre_gl_web/src/interop/style/sources/vector_source_interop.dart'; import 'package:maplibre_gl_web/src/style/sources/source.dart'; @@ -32,7 +30,7 @@ class VectorSource extends Source { @override get dict { - Map dict = { + final dict = { 'type': 'vector', }; if (url != null) { diff --git a/maplibre_gl_web/lib/src/style/style.dart b/maplibre_gl_web/lib/src/style/style.dart index 2805ceaca..338393e0b 100644 --- a/maplibre_gl_web/lib/src/style/style.dart +++ b/maplibre_gl_web/lib/src/style/style.dart @@ -1,5 +1,3 @@ -library maplibre.style.style; - import 'package:maplibre_gl_web/src/interop/interop.dart'; import 'package:maplibre_gl_web/src/style/evaluation_parameters.dart'; import 'package:maplibre_gl_web/src/style/style_image.dart'; diff --git a/maplibre_gl_web/lib/src/style/style_image.dart b/maplibre_gl_web/lib/src/style/style_image.dart index 74977965f..05cb61f0d 100644 --- a/maplibre_gl_web/lib/src/style/style_image.dart +++ b/maplibre_gl_web/lib/src/style/style_image.dart @@ -1,5 +1,3 @@ -library maplibre.style.style_image; - import 'package:maplibre_gl_web/src/interop/interop.dart'; class StyleImage extends JsObjectWrapper { diff --git a/maplibre_gl_web/lib/src/ui/camera.dart b/maplibre_gl_web/lib/src/ui/camera.dart index ef72be799..e98beead4 100644 --- a/maplibre_gl_web/lib/src/ui/camera.dart +++ b/maplibre_gl_web/lib/src/ui/camera.dart @@ -1,5 +1,3 @@ -library maplibre.ui.camera; - import 'package:js/js_util.dart'; import 'package:maplibre_gl_web/src/geo/lng_lat.dart'; import 'package:maplibre_gl_web/src/geo/lng_lat_bounds.dart'; diff --git a/maplibre_gl_web/lib/src/ui/control/attribution_control.dart b/maplibre_gl_web/lib/src/ui/control/attribution_control.dart index 325fcb813..ec5935c91 100644 --- a/maplibre_gl_web/lib/src/ui/control/attribution_control.dart +++ b/maplibre_gl_web/lib/src/ui/control/attribution_control.dart @@ -1,5 +1,3 @@ -library maplibre.ui.control.attribution_control; - import 'package:maplibre_gl_web/src/interop/interop.dart'; import 'package:maplibre_gl_web/src/interop/ui/control/attribution_control_interop.dart'; import 'package:maplibre_gl_web/src/ui/map.dart'; diff --git a/maplibre_gl_web/lib/src/ui/control/geolocate_control.dart b/maplibre_gl_web/lib/src/ui/control/geolocate_control.dart index dc645d2a4..e7191e59f 100644 --- a/maplibre_gl_web/lib/src/ui/control/geolocate_control.dart +++ b/maplibre_gl_web/lib/src/ui/control/geolocate_control.dart @@ -1,5 +1,3 @@ -library maplibre.ui.control.geolocate_control; - import 'package:maplibre_gl_web/src/interop/interop.dart'; import 'package:maplibre_gl_web/src/ui/map.dart'; import 'package:maplibre_gl_web/src/util/evented.dart'; diff --git a/maplibre_gl_web/lib/src/ui/control/logo_control.dart b/maplibre_gl_web/lib/src/ui/control/logo_control.dart index b0b404ee0..dec72b870 100644 --- a/maplibre_gl_web/lib/src/ui/control/logo_control.dart +++ b/maplibre_gl_web/lib/src/ui/control/logo_control.dart @@ -1,5 +1,3 @@ -library maplibre.ui.control.logo_control; - import 'package:maplibre_gl_web/src/interop/interop.dart'; import 'package:maplibre_gl_web/src/ui/map.dart'; diff --git a/maplibre_gl_web/lib/src/ui/control/navigation_control.dart b/maplibre_gl_web/lib/src/ui/control/navigation_control.dart index fa9fb957f..b701d8ea6 100644 --- a/maplibre_gl_web/lib/src/ui/control/navigation_control.dart +++ b/maplibre_gl_web/lib/src/ui/control/navigation_control.dart @@ -1,5 +1,3 @@ -library maplibre.ui.control.navigation_control; - import 'package:maplibre_gl_web/src/interop/interop.dart'; import 'package:maplibre_gl_web/src/ui/map.dart'; diff --git a/maplibre_gl_web/lib/src/ui/events.dart b/maplibre_gl_web/lib/src/ui/events.dart index 621d56ef0..2622813c8 100644 --- a/maplibre_gl_web/lib/src/ui/events.dart +++ b/maplibre_gl_web/lib/src/ui/events.dart @@ -1,5 +1,3 @@ -library maplibre.ui.events; - import 'dart:html'; import 'package:maplibre_gl_web/src/geo/lng_lat.dart'; diff --git a/maplibre_gl_web/lib/src/ui/handler/box_zoom.dart b/maplibre_gl_web/lib/src/ui/handler/box_zoom.dart index 8beaec0be..e2112e90f 100644 --- a/maplibre_gl_web/lib/src/ui/handler/box_zoom.dart +++ b/maplibre_gl_web/lib/src/ui/handler/box_zoom.dart @@ -1,5 +1,3 @@ -library maplibre.ui.handler.box_zoom; - import 'dart:html'; import 'package:maplibre_gl_web/src/interop/interop.dart'; diff --git a/maplibre_gl_web/lib/src/ui/handler/dblclick_zoom.dart b/maplibre_gl_web/lib/src/ui/handler/dblclick_zoom.dart index b0e87d239..d8fd65e8f 100644 --- a/maplibre_gl_web/lib/src/ui/handler/dblclick_zoom.dart +++ b/maplibre_gl_web/lib/src/ui/handler/dblclick_zoom.dart @@ -1,5 +1,3 @@ -library maplibre.ui.handler.dbclick_zoom; - import 'package:maplibre_gl_web/src/interop/interop.dart'; import 'package:maplibre_gl_web/src/ui/events.dart'; diff --git a/maplibre_gl_web/lib/src/ui/handler/drag_pan.dart b/maplibre_gl_web/lib/src/ui/handler/drag_pan.dart index a67fdeddf..1366c146d 100644 --- a/maplibre_gl_web/lib/src/ui/handler/drag_pan.dart +++ b/maplibre_gl_web/lib/src/ui/handler/drag_pan.dart @@ -1,5 +1,3 @@ -library maplibre.ui.handler.drag_pan; - import 'dart:html'; import 'package:maplibre_gl_web/src/interop/interop.dart'; diff --git a/maplibre_gl_web/lib/src/ui/handler/drag_rotate.dart b/maplibre_gl_web/lib/src/ui/handler/drag_rotate.dart index c7adac83f..f936bc128 100644 --- a/maplibre_gl_web/lib/src/ui/handler/drag_rotate.dart +++ b/maplibre_gl_web/lib/src/ui/handler/drag_rotate.dart @@ -1,5 +1,3 @@ -library maplibre.ui.handler.drag_rotate; - import 'dart:html'; import 'package:maplibre_gl_web/src/interop/interop.dart'; diff --git a/maplibre_gl_web/lib/src/ui/handler/keyboard.dart b/maplibre_gl_web/lib/src/ui/handler/keyboard.dart index ed4b02eec..2f709a641 100644 --- a/maplibre_gl_web/lib/src/ui/handler/keyboard.dart +++ b/maplibre_gl_web/lib/src/ui/handler/keyboard.dart @@ -1,5 +1,3 @@ -library maplibre.ui.handler.keyboard; - import 'package:maplibre_gl_web/src/interop/interop.dart'; class KeyboardHandler extends JsObjectWrapper { diff --git a/maplibre_gl_web/lib/src/ui/handler/scroll_zoom.dart b/maplibre_gl_web/lib/src/ui/handler/scroll_zoom.dart index 95f2ebb02..53ac7453a 100644 --- a/maplibre_gl_web/lib/src/ui/handler/scroll_zoom.dart +++ b/maplibre_gl_web/lib/src/ui/handler/scroll_zoom.dart @@ -1,5 +1,3 @@ -library maplibre.ui.handler.scroll_zoom; - import 'dart:html'; import 'package:maplibre_gl_web/src/interop/interop.dart'; diff --git a/maplibre_gl_web/lib/src/ui/handler/touch_zoom_rotate.dart b/maplibre_gl_web/lib/src/ui/handler/touch_zoom_rotate.dart index 9ba5a74e1..8380c6cba 100644 --- a/maplibre_gl_web/lib/src/ui/handler/touch_zoom_rotate.dart +++ b/maplibre_gl_web/lib/src/ui/handler/touch_zoom_rotate.dart @@ -1,5 +1,3 @@ -library maplibre.ui.handler.touch_zoom_rotate; - import 'dart:html'; import 'package:maplibre_gl_web/src/interop/interop.dart'; diff --git a/maplibre_gl_web/lib/src/ui/map.dart b/maplibre_gl_web/lib/src/ui/map.dart index 4e462392b..27f29395c 100644 --- a/maplibre_gl_web/lib/src/ui/map.dart +++ b/maplibre_gl_web/lib/src/ui/map.dart @@ -1,5 +1,3 @@ -library maplibre.ui.map; - import 'dart:html'; import 'package:js/js_util.dart'; import 'package:maplibre_gl_web/src/geo/geojson.dart'; @@ -581,7 +579,7 @@ class MapLibreMap extends Camera { /// @see [Animate a point](https://maplibre.org/maplibre-gl-js/docs/examples/animate-point-along-line/) /// @see [Add live realtime data](https://maplibre.org/maplibre-gl-js/docs/examples/live-geojson/) dynamic getSource(String id) { - var source = jsObject.getSource(id); + final source = jsObject.getSource(id); if (source is GeoJsonSourceJsImpl) { return GeoJsonSource.fromJsObject(source); } diff --git a/maplibre_gl_web/lib/src/ui/marker.dart b/maplibre_gl_web/lib/src/ui/marker.dart index 57e1b9c28..8359ea7eb 100644 --- a/maplibre_gl_web/lib/src/ui/marker.dart +++ b/maplibre_gl_web/lib/src/ui/marker.dart @@ -1,5 +1,3 @@ -library maplibre.ui.marker; - import 'dart:html'; import 'package:maplibre_gl_web/src/geo/lng_lat.dart'; import 'package:maplibre_gl_web/src/interop/interop.dart'; diff --git a/maplibre_gl_web/lib/src/ui/popup.dart b/maplibre_gl_web/lib/src/ui/popup.dart index 14f895679..2777ea130 100644 --- a/maplibre_gl_web/lib/src/ui/popup.dart +++ b/maplibre_gl_web/lib/src/ui/popup.dart @@ -1,5 +1,3 @@ -library maplibre.ui.popup; - import 'dart:html'; import 'package:maplibre_gl_web/src/geo/lng_lat.dart'; import 'package:maplibre_gl_web/src/interop/interop.dart'; diff --git a/maplibre_gl_web/lib/src/util/evented.dart b/maplibre_gl_web/lib/src/util/evented.dart index 4c7d4f0f2..395fe7176 100644 --- a/maplibre_gl_web/lib/src/util/evented.dart +++ b/maplibre_gl_web/lib/src/util/evented.dart @@ -1,5 +1,3 @@ -library maplibre.util.evented; - import 'dart:js'; import 'package:maplibre_gl_web/src/geo/geojson.dart'; diff --git a/maplibre_gl_web/lib/src/utils.dart b/maplibre_gl_web/lib/src/utils.dart index b500b2582..62a86b277 100644 --- a/maplibre_gl_web/lib/src/utils.dart +++ b/maplibre_gl_web/lib/src/utils.dart @@ -26,9 +26,9 @@ bool _isBasicType(Object? value) { } Map dartifyMap(Object? jsObject) { - var keys = js.objectKeys(jsObject); - var map = {}; - for (var key in keys) { + final keys = js.objectKeys(jsObject); + final map = {}; + for (final key in keys) { map[key] = dartify(util.getProperty(jsObject!, key)); } return map; diff --git a/maplibre_gl_web/pubspec.yaml b/maplibre_gl_web/pubspec.yaml index 57a9b300b..2f320e9e3 100644 --- a/maplibre_gl_web/pubspec.yaml +++ b/maplibre_gl_web/pubspec.yaml @@ -16,14 +16,14 @@ flutter: fileName: maplibre_gl_web.dart dependencies: - js: ">=0.6.7 <0.8.0" flutter: sdk: flutter flutter_web_plugins: sdk: flutter - meta: ^1.3.0 - maplibre_gl_platform_interface: ^0.20.0 image: ^4.0.17 + js: ">=0.6.7 <0.8.0" + maplibre_gl_platform_interface: ^0.19.0+2 + meta: ^1.3.0 dev_dependencies: very_good_analysis: ^5.0.0 diff --git a/scripts/lib/generate.dart b/scripts/lib/generate.dart index 9bf85d17a..9d6f8b0cb 100644 --- a/scripts/lib/generate.dart +++ b/scripts/lib/generate.dart @@ -7,7 +7,7 @@ import 'package:recase/recase.dart'; import 'conversions.dart'; main() async { - var styleJson = + final styleJson = jsonDecode(await File('scripts/input/style.json').readAsString()); final layerTypes = [ @@ -31,7 +31,7 @@ main() async { final renderContext = { "layerTypes": [ - for (var type in layerTypes) + for (final type in layerTypes) { "type": type, "typePascal": ReCase(type).pascalCase, @@ -41,7 +41,7 @@ main() async { }, ], "sourceTypes": [ - for (var type in sourceTypes) + for (final type in sourceTypes) { "type": type.replaceAll("_", "-"), "typePascal": ReCase(type).pascalCase, @@ -66,7 +66,7 @@ main() async { "maplibre_gl_platform_interface/lib/src/source_properties.dart", ]; - for (var template in templates) { + for (final template in templates) { await render(renderContext, template); } } @@ -80,11 +80,11 @@ Future render( final outputPath = pathItems.join("/"); print("Rendering $filename"); - var templateFile = + final templateFile = await File('./scripts/templates/$filename.template').readAsString(); - var template = Template(templateFile); - var outputFile = File('$outputPath/$filename'); + final template = Template(templateFile); + final outputFile = File('$outputPath/$filename'); outputFile.writeAsString(template.renderString(renderContext)); } @@ -168,8 +168,8 @@ List buildDocSplit(Map item) { if (maxValue != null) result.add(" maximum: $maxValue"); if (values != null) { result.add("Options:"); - for (var value in values.entries) { - result.add(" \"${value.key}\""); + for (final value in values.entries) { + result.add(' "${value.key}"'); result.addAll( splitIntoChunks("${value.value["doc"]}", 70, prefix: " ")); } @@ -197,8 +197,8 @@ List splitIntoChunks(String input, int lineLength, final words = input.split(" "); final chunks = []; - String chunk = ""; - for (var word in words) { + var chunk = ""; + for (final word in words) { final nextChunk = chunk.isEmpty ? prefix + word : "$chunk $word"; if (nextChunk.length > lineLength || chunk.endsWith("\n")) { chunks.add(chunk.replaceAll("\n", ""));