diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml new file mode 100644 index 000000000..ee1a64359 --- /dev/null +++ b/.github/workflows/stale.yml @@ -0,0 +1,19 @@ +name: 'Close stale issues and PR' +on: + schedule: + - cron: '30 1 * * *' + +jobs: + stale: + runs-on: ubuntu-latest + steps: + - uses: actions/stale@v3 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.' + stale-pr-message: 'This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.' + close-issue-message: 'This issue was closed because it has been stalled for 5 days with no activity.' + days-before-stale: 30 + days-before-close: 5 + days-before-pr-close: -1 + diff --git a/example/lib/pages/animated_map_controller.dart b/example/lib/pages/animated_map_controller.dart index e5d9eab46..4deb55ce1 100644 --- a/example/lib/pages/animated_map_controller.dart +++ b/example/lib/pages/animated_map_controller.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_map/flutter_map.dart'; -import 'package:latlong/latlong.dart'; +import 'package:latlong2/latlong.dart'; import '../widgets/drawer.dart'; @@ -29,7 +29,7 @@ class AnimatedMapControllerPageState extends State static LatLng paris = LatLng(48.8566, 2.3522); static LatLng dublin = LatLng(53.3498, -6.2603); - MapController mapController; + late MapController mapController; @override void initState() { diff --git a/example/lib/pages/circle.dart b/example/lib/pages/circle.dart index 723776bf2..01eb386c7 100644 --- a/example/lib/pages/circle.dart +++ b/example/lib/pages/circle.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_map/flutter_map.dart'; -import 'package:latlong/latlong.dart'; +import 'package:latlong2/latlong.dart'; import '../widgets/drawer.dart'; diff --git a/example/lib/pages/custom_crs/custom_crs.dart b/example/lib/pages/custom_crs/custom_crs.dart index f37ab02d7..0cc0e8682 100644 --- a/example/lib/pages/custom_crs/custom_crs.dart +++ b/example/lib/pages/custom_crs/custom_crs.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_map/flutter_map.dart'; import 'package:flutter_map/plugin_api.dart'; -import 'package:latlong/latlong.dart'; +import 'package:latlong2/latlong.dart'; import 'package:proj4dart/proj4dart.dart' as proj4; import '../../widgets/drawer.dart'; @@ -14,30 +14,31 @@ class CustomCrsPage extends StatefulWidget { } class _CustomCrsPageState extends State { - Proj4Crs epsg3413CRS; + late Proj4Crs epsg3413CRS; - double maxZoom; + double? maxZoom; // Define start center proj4.Point point = proj4.Point(x: 65.05166470332148, y: -19.171744826394896); String initText = 'Map centered to'; - proj4.Projection epsg4326; + late proj4.Projection epsg4326; - proj4.Projection epsg3413; + late proj4.Projection epsg3413; @override void initState() { super.initState(); // EPSG:4326 is a predefined projection ships with proj4dart - epsg4326 = proj4.Projection('EPSG:4326'); + epsg4326 = proj4.Projection.get('EPSG:4326')!; // EPSG:3413 is a user-defined projection from a valid Proj4 definition string // From: http://epsg.io/3413, proj definition: http://epsg.io/3413.proj4 // Find Projection by name or define it if not exists - epsg3413 = proj4.Projection('EPSG:3413') ?? + // TODO the warning here will go away as soon as proj4 is migrated to null safety + epsg3413 = proj4.Projection.get('EPSG:3413') ?? proj4.Projection.add('EPSG:3413', '+proj=stere +lat_0=90 +lat_ts=70 +lon_0=-45 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs'); diff --git a/example/lib/pages/esri.dart b/example/lib/pages/esri.dart index d316b0b88..7976e133e 100644 --- a/example/lib/pages/esri.dart +++ b/example/lib/pages/esri.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_map/flutter_map.dart'; -import 'package:latlong/latlong.dart'; +import 'package:latlong2/latlong.dart'; import '../widgets/drawer.dart'; diff --git a/example/lib/pages/home.dart b/example/lib/pages/home.dart index 621a3fbc3..9e4146ed3 100644 --- a/example/lib/pages/home.dart +++ b/example/lib/pages/home.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_map/flutter_map.dart'; -import 'package:latlong/latlong.dart'; +import 'package:latlong2/latlong.dart'; import '../widgets/drawer.dart'; diff --git a/example/lib/pages/interactive_test_page.dart b/example/lib/pages/interactive_test_page.dart index f76af65c9..7bc127622 100644 --- a/example/lib/pages/interactive_test_page.dart +++ b/example/lib/pages/interactive_test_page.dart @@ -2,7 +2,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_map/flutter_map.dart'; -import 'package:latlong/latlong.dart'; +import 'package:latlong2/latlong.dart'; import '../widgets/drawer.dart'; @@ -16,12 +16,12 @@ class InteractiveTestPage extends StatefulWidget { } class _InteractiveTestPageState extends State { - MapController mapController; + late MapController mapController; // Enable pinchZoom and doubleTapZoomBy by default int flags = InteractiveFlag.pinchZoom | InteractiveFlag.doubleTapZoom; - StreamSubscription subscription; + late StreamSubscription subscription; @override void initState() { @@ -159,7 +159,7 @@ class _InteractiveTestPageState extends State { } return Text( - 'Current event: ${snapshot.data.runtimeType}\nSource: ${snapshot.data.source}', + 'Current event: ${snapshot.data.runtimeType}\nSource: ${snapshot.data!.source}', textAlign: TextAlign.center, ); }, diff --git a/example/lib/pages/live_location.dart b/example/lib/pages/live_location.dart index 707208aa6..1566131d1 100644 --- a/example/lib/pages/live_location.dart +++ b/example/lib/pages/live_location.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_map/flutter_map.dart'; -import 'package:latlong/latlong.dart'; +import 'package:latlong2/latlong.dart'; import 'package:location/location.dart'; import '../widgets/drawer.dart'; @@ -14,13 +14,13 @@ class LiveLocationPage extends StatefulWidget { } class _LiveLocationPageState extends State { - LocationData _currentLocation; - MapController _mapController; + LocationData? _currentLocation; + late MapController _mapController; bool _liveUpdate = false; bool _permission = false; - String _serviceError = ''; + String? _serviceError = ''; var interActiveFlags = InteractiveFlag.all; @@ -35,11 +35,11 @@ class _LiveLocationPageState extends State { void initLocationService() async { await _locationService.changeSettings( - accuracy: LocationAccuracy.HIGH, + accuracy: LocationAccuracy.high, interval: 1000, ); - LocationData location; + LocationData? location; bool serviceEnabled; bool serviceRequestResult; @@ -48,13 +48,12 @@ class _LiveLocationPageState extends State { if (serviceEnabled) { var permission = await _locationService.requestPermission(); - _permission = permission == PermissionStatus.GRANTED; + _permission = permission == PermissionStatus.granted; if (_permission) { location = await _locationService.getLocation(); _currentLocation = location; - _locationService - .onLocationChanged() + _locationService.onLocationChanged .listen((LocationData result) async { if (mounted) { setState(() { @@ -63,8 +62,8 @@ class _LiveLocationPageState extends State { // If Live Update is enabled, move map center if (_liveUpdate) { _mapController.move( - LatLng(_currentLocation.latitude, - _currentLocation.longitude), + LatLng(_currentLocation!.latitude!, + _currentLocation!.longitude!), _mapController.zoom); } }); @@ -97,7 +96,7 @@ class _LiveLocationPageState extends State { // by default or store previous location value to show. if (_currentLocation != null) { currentLatLng = - LatLng(_currentLocation.latitude, _currentLocation.longitude); + LatLng(_currentLocation!.latitude!, _currentLocation!.longitude!); } else { currentLatLng = LatLng(0, 0); } @@ -125,7 +124,7 @@ class _LiveLocationPageState extends State { children: [ Padding( padding: EdgeInsets.only(top: 8.0, bottom: 8.0), - child: _serviceError.isEmpty + child: _serviceError!.isEmpty ? Text('This is a map that is showing ' '(${currentLatLng.latitude}, ${currentLatLng.longitude}).') : Text( diff --git a/example/lib/pages/map_controller.dart b/example/lib/pages/map_controller.dart index b21f360c3..433084247 100644 --- a/example/lib/pages/map_controller.dart +++ b/example/lib/pages/map_controller.dart @@ -2,7 +2,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_map/flutter_map.dart'; -import 'package:latlong/latlong.dart'; +import 'package:latlong2/latlong.dart'; import 'package:location/location.dart'; import '../widgets/drawer.dart'; @@ -21,7 +21,7 @@ class MapControllerPageState extends State { static LatLng paris = LatLng(48.8566, 2.3522); static LatLng dublin = LatLng(53.3498, -6.2603); - MapController mapController; + late MapController mapController; double rotation = 0.0; @override @@ -119,7 +119,7 @@ class MapControllerPageState extends State { Builder(builder: (BuildContext context) { return MaterialButton( onPressed: () { - final bounds = mapController.bounds; + final bounds = mapController.bounds!; ScaffoldMessenger.of(context).showSnackBar(SnackBar( content: Text( @@ -178,8 +178,8 @@ class MapControllerPageState extends State { class CurrentLocation extends StatefulWidget { const CurrentLocation({ - Key key, - @required this.mapController, + Key? key, + required this.mapController, }) : super(key: key); final MapController mapController; @@ -192,7 +192,7 @@ class _CurrentLocationState extends State { int _eventKey = 0; var icon = Icons.gps_not_fixed; - StreamSubscription mapEventSubscription; + late StreamSubscription mapEventSubscription; @override void initState() { @@ -229,7 +229,7 @@ class _CurrentLocationState extends State { try { var currentLocation = await location.getLocation(); var moved = widget.mapController.move( - LatLng(currentLocation.latitude, currentLocation.longitude), + LatLng(currentLocation.latitude!, currentLocation.longitude!), 18, id: _eventKey.toString(), ); diff --git a/example/lib/pages/marker_anchor.dart b/example/lib/pages/marker_anchor.dart index 522abf71a..8f5c4e482 100644 --- a/example/lib/pages/marker_anchor.dart +++ b/example/lib/pages/marker_anchor.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_map/flutter_map.dart'; -import 'package:latlong/latlong.dart'; +import 'package:latlong2/latlong.dart'; import '../widgets/drawer.dart'; @@ -13,7 +13,7 @@ class MarkerAnchorPage extends StatefulWidget { } class MarkerAnchorPageState extends State { - AnchorPos anchorPos; + late AnchorPos anchorPos; @override void initState() { diff --git a/example/lib/pages/moving_markers.dart b/example/lib/pages/moving_markers.dart index 8719d4e65..f92046bf3 100644 --- a/example/lib/pages/moving_markers.dart +++ b/example/lib/pages/moving_markers.dart @@ -2,7 +2,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_map/flutter_map.dart'; -import 'package:latlong/latlong.dart'; +import 'package:latlong2/latlong.dart'; import '../widgets/drawer.dart'; @@ -16,8 +16,8 @@ class MovingMarkersPage extends StatefulWidget { } class _MovingMarkersPageState extends State { - Marker _marker; - Timer _timer; + Marker? _marker; + late Timer _timer; int _markerIndex = 0; @override @@ -62,7 +62,7 @@ class _MovingMarkersPageState extends State { urlTemplate: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', subdomains: ['a', 'b', 'c']), - MarkerLayerOptions(markers: [_marker]) + MarkerLayerOptions(markers: [_marker!]) ], ), ), diff --git a/example/lib/pages/offline_map.dart b/example/lib/pages/offline_map.dart index c2e75a496..868bde97d 100644 --- a/example/lib/pages/offline_map.dart +++ b/example/lib/pages/offline_map.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_map/flutter_map.dart'; -import 'package:latlong/latlong.dart'; +import 'package:latlong2/latlong.dart'; import '../widgets/drawer.dart'; diff --git a/example/lib/pages/on_tap.dart b/example/lib/pages/on_tap.dart index 557a7b7a7..8aba3db83 100644 --- a/example/lib/pages/on_tap.dart +++ b/example/lib/pages/on_tap.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_map/flutter_map.dart'; -import 'package:latlong/latlong.dart'; +import 'package:latlong2/latlong.dart'; import '../widgets/drawer.dart'; diff --git a/example/lib/pages/overlay_image.dart b/example/lib/pages/overlay_image.dart index 38ce7615d..79816db2b 100644 --- a/example/lib/pages/overlay_image.dart +++ b/example/lib/pages/overlay_image.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_map/flutter_map.dart'; -import 'package:latlong/latlong.dart'; +import 'package:latlong2/latlong.dart'; import '../widgets/drawer.dart'; diff --git a/example/lib/pages/plugin_api.dart b/example/lib/pages/plugin_api.dart index 50af71834..7c87fe600 100644 --- a/example/lib/pages/plugin_api.dart +++ b/example/lib/pages/plugin_api.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_map/plugin_api.dart'; -import 'package:latlong/latlong.dart'; +import 'package:latlong2/latlong.dart'; import '../widgets/drawer.dart'; @@ -46,9 +46,9 @@ class PluginPage extends StatelessWidget { class MyCustomPluginOptions extends LayerOptions { final String text; MyCustomPluginOptions({ - Key key, + Key? key, this.text = '', - Stream rebuild, + Stream? rebuild, }) : super(key: key, rebuild: rebuild); } diff --git a/example/lib/pages/plugin_scalebar.dart b/example/lib/pages/plugin_scalebar.dart index cfcb8c2e6..2780456b6 100644 --- a/example/lib/pages/plugin_scalebar.dart +++ b/example/lib/pages/plugin_scalebar.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_map/plugin_api.dart'; -import 'package:latlong/latlong.dart'; +import 'package:latlong2/latlong.dart'; import '../widgets/drawer.dart'; import 'scale_layer_plugin_option.dart'; diff --git a/example/lib/pages/plugin_zoombuttons.dart b/example/lib/pages/plugin_zoombuttons.dart index e48886668..e2b24686b 100644 --- a/example/lib/pages/plugin_zoombuttons.dart +++ b/example/lib/pages/plugin_zoombuttons.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_map/plugin_api.dart'; -import 'package:latlong/latlong.dart'; +import 'package:latlong2/latlong.dart'; import '../widgets/drawer.dart'; import 'zoombuttons_plugin_option.dart'; diff --git a/example/lib/pages/polyline.dart b/example/lib/pages/polyline.dart index 8fd1ee355..5d17a336b 100644 --- a/example/lib/pages/polyline.dart +++ b/example/lib/pages/polyline.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_map/flutter_map.dart'; -import 'package:latlong/latlong.dart'; +import 'package:latlong2/latlong.dart'; import '../widgets/drawer.dart'; diff --git a/example/lib/pages/scale_layer_plugin_option.dart b/example/lib/pages/scale_layer_plugin_option.dart index 14bdf1201..99e83025f 100644 --- a/example/lib/pages/scale_layer_plugin_option.dart +++ b/example/lib/pages/scale_layer_plugin_option.dart @@ -8,18 +8,18 @@ import 'package:flutter_map/plugin_api.dart'; import './scalebar_utils.dart' as util; class ScaleLayerPluginOption extends LayerOptions { - TextStyle textStyle; + TextStyle? textStyle; Color lineColor; double lineWidth; - final EdgeInsets padding; + final EdgeInsets? padding; ScaleLayerPluginOption({ - Key key, + Key? key, this.textStyle, this.lineColor = Colors.white, this.lineWidth = 2, this.padding, - Stream rebuild, + Stream? rebuild, }) : super(key: key, rebuild: rebuild); } @@ -84,7 +84,7 @@ class ScaleLayer extends StatelessWidget { var displayDistance = distance > 999 ? '${(distance / 1000).toStringAsFixed(0)} km' : '${distance.toStringAsFixed(0)} m'; - double width = (end.x - start.x); + var width = (end.x - (start.x as double)); return CustomPaint( painter: ScalePainter( @@ -103,36 +103,38 @@ class ScalePainter extends CustomPainter { ScalePainter(this.width, this.text, {this.padding, this.textStyle, this.lineWidth, this.lineColor}); final double width; - final EdgeInsets padding; + final EdgeInsets? padding; final String text; - TextStyle textStyle; - double lineWidth; - Color lineColor; + TextStyle? textStyle; + double? lineWidth; + Color? lineColor; @override void paint(ui.Canvas canvas, ui.Size size) { final paint = Paint() - ..color = lineColor + ..color = lineColor! ..strokeCap = StrokeCap.square - ..strokeWidth = lineWidth; + ..strokeWidth = lineWidth!; var sizeForStartEnd = 4; - var paddingLeft = padding == null ? 0 : padding.left + sizeForStartEnd / 2; - var paddingTop = padding == null ? 0 : padding.top; + var paddingLeft = padding == null ? 0 : padding!.left + sizeForStartEnd / 2; + var paddingTop = padding == null ? 0 : padding!.top; var textSpan = TextSpan(style: textStyle, text: text); var textPainter = TextPainter(text: textSpan, textDirection: TextDirection.ltr)..layout(); - textPainter.paint(canvas, - Offset(width / 2 - textPainter.width / 2 + paddingLeft, paddingTop)); + textPainter.paint( + canvas, + Offset(width / 2 - textPainter.width / 2 + paddingLeft, + paddingTop as double)); paddingTop += textPainter.height; - var p1 = Offset(paddingLeft, sizeForStartEnd + paddingTop); + var p1 = Offset(paddingLeft as double, sizeForStartEnd + paddingTop); var p2 = Offset(paddingLeft + width, sizeForStartEnd + paddingTop); // draw start line canvas.drawLine(Offset(paddingLeft, paddingTop), Offset(paddingLeft, sizeForStartEnd + paddingTop), paint); // draw middle line - var middleX = width / 2 + paddingLeft - lineWidth / 2; + var middleX = width / 2 + paddingLeft - lineWidth! / 2; canvas.drawLine(Offset(middleX, paddingTop + sizeForStartEnd / 2), Offset(middleX, sizeForStartEnd + paddingTop), paint); // draw end line diff --git a/example/lib/pages/scalebar_utils.dart b/example/lib/pages/scalebar_utils.dart index 1f7b232e8..f888e2e8d 100644 --- a/example/lib/pages/scalebar_utils.dart +++ b/example/lib/pages/scalebar_utils.dart @@ -1,7 +1,8 @@ import 'dart:math'; -import 'package:latlong/latlong.dart'; -const double piOver180 = PI / 180.0; +import 'package:latlong2/latlong.dart'; + +const double piOver180 = pi / 180.0; double toDegrees(double radians) { return radians / piOver180; } diff --git a/example/lib/pages/sliding_map.dart b/example/lib/pages/sliding_map.dart index 249578dd3..d9286803c 100644 --- a/example/lib/pages/sliding_map.dart +++ b/example/lib/pages/sliding_map.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_map/flutter_map.dart'; -import 'package:latlong/latlong.dart'; +import 'package:latlong2/latlong.dart'; import '../widgets/drawer.dart'; diff --git a/example/lib/pages/tap_to_add.dart b/example/lib/pages/tap_to_add.dart index 81ec190b0..0cfbdd0ac 100644 --- a/example/lib/pages/tap_to_add.dart +++ b/example/lib/pages/tap_to_add.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_map/flutter_map.dart'; -import 'package:latlong/latlong.dart'; +import 'package:latlong2/latlong.dart'; import '../widgets/drawer.dart'; diff --git a/example/lib/pages/tile_builder_example.dart b/example/lib/pages/tile_builder_example.dart index 2dc974440..bdf5f5b55 100644 --- a/example/lib/pages/tile_builder_example.dart +++ b/example/lib/pages/tile_builder_example.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_map/flutter_map.dart'; -import 'package:latlong/latlong.dart'; +import 'package:latlong2/latlong.dart'; import '../widgets/drawer.dart'; @@ -43,7 +43,7 @@ class _TileBuilderPageState extends State { tile.loaded == null ? 'Loading' // sometimes result is negative which shouldn't happen, abs() corrects it - : '${(tile.loaded.millisecond - tile.loadStarted.millisecond).abs()} ms', + : '${(tile.loaded!.millisecond - tile.loadStarted.millisecond).abs()} ms', style: Theme.of(context).textTheme.headline5, ), ], diff --git a/example/lib/pages/tile_loading_error_handle.dart b/example/lib/pages/tile_loading_error_handle.dart index 85d39ad39..03c2392c0 100644 --- a/example/lib/pages/tile_loading_error_handle.dart +++ b/example/lib/pages/tile_loading_error_handle.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_map/flutter_map.dart'; -import 'package:latlong/latlong.dart'; +import 'package:latlong2/latlong.dart'; import '../widgets/drawer.dart'; @@ -48,7 +48,7 @@ class _TileLoadingErrorHandleState extends State { tileProvider: NonCachingNetworkTileProvider(), errorTileCallback: (Tile tile, error) { if (_needLoadingError) { - WidgetsBinding.instance.addPostFrameCallback((_) { + WidgetsBinding.instance!.addPostFrameCallback((_) { ScaffoldMessenger.of(context).showSnackBar(SnackBar( duration: Duration(seconds: 1), content: Text( diff --git a/example/lib/pages/widgets.dart b/example/lib/pages/widgets.dart index a72d7f23f..458a26a10 100644 --- a/example/lib/pages/widgets.dart +++ b/example/lib/pages/widgets.dart @@ -2,7 +2,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_map/plugin_api.dart'; -import 'package:latlong/latlong.dart'; +import 'package:latlong2/latlong.dart'; import '../pages/zoombuttons_plugin_option.dart'; import '../widgets/drawer.dart'; @@ -74,8 +74,8 @@ class MovingWithoutRefreshAllMapMarkers extends StatefulWidget { class _MovingWithoutRefreshAllMapMarkersState extends State { - Marker _marker; - Timer _timer; + Marker? _marker; + Timer? _timer; int _markerIndex = 0; @override @@ -99,7 +99,7 @@ class _MovingWithoutRefreshAllMapMarkersState @override Widget build(BuildContext context) { return MarkerLayerWidget( - options: MarkerLayerOptions(markers: [_marker]), + options: MarkerLayerOptions(markers: [_marker!]), ); } } diff --git a/example/lib/pages/wms_tile_layer.dart b/example/lib/pages/wms_tile_layer.dart index 70bf91130..480103f7e 100644 --- a/example/lib/pages/wms_tile_layer.dart +++ b/example/lib/pages/wms_tile_layer.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_map/flutter_map.dart'; -import 'package:latlong/latlong.dart'; +import 'package:latlong2/latlong.dart'; import '../widgets/drawer.dart'; diff --git a/example/lib/pages/zoombuttons_plugin_option.dart b/example/lib/pages/zoombuttons_plugin_option.dart index 9f27b7021..944324ce6 100644 --- a/example/lib/pages/zoombuttons_plugin_option.dart +++ b/example/lib/pages/zoombuttons_plugin_option.dart @@ -8,15 +8,15 @@ class ZoomButtonsPluginOption extends LayerOptions { final bool mini; final double padding; final Alignment alignment; - final Color zoomInColor; - final Color zoomInColorIcon; - final Color zoomOutColor; - final Color zoomOutColorIcon; + final Color? zoomInColor; + final Color? zoomInColorIcon; + final Color? zoomOutColor; + final Color? zoomOutColorIcon; final IconData zoomInIcon; final IconData zoomOutIcon; ZoomButtonsPluginOption({ - Key key, + Key? key, this.minZoom = 1, this.maxZoom = 18, this.mini = true, @@ -28,7 +28,7 @@ class ZoomButtonsPluginOption extends LayerOptions { this.zoomOutColor, this.zoomOutColorIcon, this.zoomOutIcon = Icons.zoom_out, - Stream rebuild, + Stream? rebuild, }) : super(key: key, rebuild: rebuild); } @@ -76,13 +76,14 @@ class ZoomButtons extends StatelessWidget { backgroundColor: zoomButtonsOpts.zoomInColor ?? Theme.of(context).primaryColor, onPressed: () { - var bounds = map.getBounds(); + var bounds = map.getBounds()!; var centerZoom = map.getBoundsCenterZoom(bounds, options); var zoom = centerZoom.zoom + 1; if (zoom < zoomButtonsOpts.minZoom) { zoom = zoomButtonsOpts.minZoom as double; } else { - map.move(centerZoom.center, zoom); + map.move(centerZoom.center, zoom, + source: MapEventSource.custom); } }, child: Icon(zoomButtonsOpts.zoomInIcon, @@ -98,13 +99,14 @@ class ZoomButtons extends StatelessWidget { backgroundColor: zoomButtonsOpts.zoomOutColor ?? Theme.of(context).primaryColor, onPressed: () { - var bounds = map.getBounds(); + var bounds = map.getBounds()!; var centerZoom = map.getBoundsCenterZoom(bounds, options); var zoom = centerZoom.zoom - 1; if (zoom > zoomButtonsOpts.maxZoom) { zoom = zoomButtonsOpts.maxZoom as double; } else { - map.move(centerZoom.center, zoom); + map.move(centerZoom.center, zoom, + source: MapEventSource.custom); } }, child: Icon(zoomButtonsOpts.zoomOutIcon, diff --git a/example/lib/test_app.dart b/example/lib/test_app.dart index 86a0a2456..830cb98b9 100644 --- a/example/lib/test_app.dart +++ b/example/lib/test_app.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_map/flutter_map.dart'; -import 'package:latlong/latlong.dart'; +import 'package:latlong2/latlong.dart'; void main() { runApp(TestApp()); diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 1589dd712..1f6fcc7db 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -18,7 +18,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev version: 1.0.0+1 environment: - sdk: ">=2.7.0 <3.0.0" + sdk: '>=2.12.0 <3.0.0' dependencies: flutter: @@ -28,7 +28,7 @@ dependencies: cupertino_icons: ^1.0.2 flutter_map: path: ../ - location: ^2.5.0 + location: ^4.1.1 dev_dependencies: pedantic: ^1.11.0 diff --git a/flutter_map.iml b/flutter_map.iml index 6048a33bd..e9a86d25d 100644 --- a/flutter_map.iml +++ b/flutter_map.iml @@ -16,4 +16,4 @@ - \ No newline at end of file + diff --git a/lib/flutter_map.dart b/lib/flutter_map.dart index d6bf937e0..4679b5ac1 100644 --- a/lib/flutter_map.dart +++ b/lib/flutter_map.dart @@ -12,7 +12,7 @@ import 'package:flutter_map/src/gestures/multi_finger_gesture.dart'; import 'package:flutter_map/src/map/flutter_map_state.dart'; import 'package:flutter_map/src/map/map.dart'; import 'package:flutter_map/src/plugins/plugin.dart'; -import 'package:latlong/latlong.dart'; +import 'package:latlong2/latlong.dart'; export 'package:flutter_map/src/core/point.dart'; export 'package:flutter_map/src/geo/crs/crs.dart'; @@ -66,18 +66,17 @@ class FlutterMap extends StatefulWidget { final MapOptions options; /// A [MapController], used to control the map. - final MapControllerImpl _mapController; + final MapControllerImpl? _mapController; FlutterMap({ - Key key, - @required this.options, + Key? key, + required this.options, this.layers = const [], this.nonRotatedLayers = const [], this.children = const [], this.nonRotatedChildren = const [], - MapController mapController, - }) : assert(options != null, 'MapOptions cannot be null!'), - _mapController = mapController, + MapController? mapController, + }) : _mapController = mapController as MapControllerImpl?, super(key: key); @override @@ -101,7 +100,7 @@ abstract class MapController { /// returns `true` if move was success (for example it won't be success if /// navigating to same place with same zoom or if center is out of bounds and /// [MapOptions.slideOnBoundaries] isn't enabled) - bool move(LatLng center, double zoom, {String id}); + bool move(LatLng center, double zoom, {String? id}); /// Sets the map rotation to a certain degrees angle (in decimal). /// @@ -112,16 +111,16 @@ abstract class MapController { /// /// returns `true` if rotate was success (it won't be success if rotate is /// same as the old rotate) - bool rotate(double degree, {String id}); + bool rotate(double degree, {String? id}); /// Calls [move] and [rotate] together however layers will rebuild just once /// instead of twice MoveAndRotateResult moveAndRotate(LatLng center, double zoom, double degree, - {String id}); + {String? id}); /// Fits the map bounds. Optional constraints can be defined /// through the [options] parameter. - void fitBounds(LatLngBounds bounds, {FitBoundsOptions options}); + void fitBounds(LatLngBounds bounds, {FitBoundsOptions? options}); bool get ready; @@ -129,7 +128,7 @@ abstract class MapController { LatLng get center; - LatLngBounds get bounds; + LatLngBounds? get bounds; double get zoom; @@ -219,38 +218,38 @@ class MapOptions { /// gestures will take effect see [MultiFingerGesture] for custom settings final int pinchMoveWinGestures; - final double minZoom; - final double maxZoom; + final double? minZoom; + final double? maxZoom; @deprecated final bool debug; // TODO no usage outside of constructor. Marked for removal? @Deprecated('use interactiveFlags instead') - final bool interactive; + final bool? interactive; /// see [InteractiveFlag] for custom settings final int interactiveFlags; final bool allowPanning; - final TapCallback onTap; - final LongPressCallback onLongPress; - final PositionCallback onPositionChanged; + final TapCallback? onTap; + final LongPressCallback? onLongPress; + final PositionCallback? onPositionChanged; final List plugins; final bool slideOnBoundaries; - final Size screenSize; + final Size? screenSize; final bool adaptiveBoundaries; - final MapController controller; + final MapController? controller; final LatLng center; - final LatLngBounds bounds; + final LatLngBounds? bounds; final FitBoundsOptions boundsOptions; - final LatLng swPanBoundary; - final LatLng nePanBoundary; + final LatLng? swPanBoundary; + final LatLng? nePanBoundary; - _SafeArea _safeAreaCache; - double _safeAreaZoom; + _SafeArea? _safeAreaCache; + double? _safeAreaZoom; MapOptions({ this.crs = const Epsg3857(), - LatLng center, + LatLng? center, this.bounds, this.boundsOptions = const FitBoundsOptions(), this.zoom = 13.0, @@ -272,7 +271,7 @@ class MapOptions { // TODO: Change when [interactive] is removed. // Change this to [this.interactiveFlags = InteractiveFlag.all] and remove // [interactiveFlags] from initializer list - int interactiveFlags, + int? interactiveFlags, this.allowPanning = true, this.onTap, this.onLongPress, @@ -300,18 +299,18 @@ class MapOptions { } //if there is a pan boundary, do not cross - bool isOutOfBounds(LatLng center) { + bool isOutOfBounds(LatLng? center) { if (adaptiveBoundaries) { - return !_safeArea.contains(center); + return !_safeArea!.contains(center); } if (swPanBoundary != null && nePanBoundary != null) { if (center == null) { return true; - } else if (center.latitude < swPanBoundary.latitude || - center.latitude > nePanBoundary.latitude) { + } else if (center.latitude < swPanBoundary!.latitude || + center.latitude > nePanBoundary!.latitude) { return true; - } else if (center.longitude < swPanBoundary.longitude || - center.longitude > nePanBoundary.longitude) { + } else if (center.longitude < swPanBoundary!.longitude || + center.longitude > nePanBoundary!.longitude) { return true; } } @@ -320,25 +319,26 @@ class MapOptions { LatLng containPoint(LatLng point, LatLng fallback) { if (adaptiveBoundaries) { - return _safeArea.containPoint(point, fallback); + return _safeArea!.containPoint(point, fallback); } else { return LatLng( - point.latitude.clamp(swPanBoundary.latitude, nePanBoundary.latitude), - point.longitude.clamp(swPanBoundary.longitude, nePanBoundary.longitude), + point.latitude.clamp(swPanBoundary!.latitude, nePanBoundary!.latitude), + point.longitude + .clamp(swPanBoundary!.longitude, nePanBoundary!.longitude), ); } } - _SafeArea get _safeArea { + _SafeArea? get _safeArea { final controllerZoom = _getControllerZoom(); if (controllerZoom != _safeAreaZoom || _safeAreaCache == null) { _safeAreaZoom = controllerZoom; final halfScreenHeight = _calculateScreenHeightInDegrees() / 2; final halfScreenWidth = _calculateScreenWidthInDegrees() / 2; - final southWestLatitude = swPanBoundary.latitude + halfScreenHeight; - final southWestLongitude = swPanBoundary.longitude + halfScreenWidth; - final northEastLatitude = nePanBoundary.latitude - halfScreenHeight; - final northEastLongitude = nePanBoundary.longitude - halfScreenWidth; + final southWestLatitude = swPanBoundary!.latitude + halfScreenHeight; + final southWestLongitude = swPanBoundary!.longitude + halfScreenWidth; + final northEastLatitude = nePanBoundary!.latitude - halfScreenHeight; + final northEastLongitude = nePanBoundary!.longitude - halfScreenWidth; _safeAreaCache = _SafeArea( LatLng( southWestLatitude, @@ -356,19 +356,19 @@ class MapOptions { double _calculateScreenWidthInDegrees() { final zoom = _getControllerZoom(); final degreesPerPixel = 360 / pow(2, zoom + 8); - return screenSize.width * degreesPerPixel; + return screenSize!.width * degreesPerPixel; } double _calculateScreenHeightInDegrees() => - screenSize.height * 170.102258 / pow(2, _getControllerZoom() + 8); + screenSize!.height * 170.102258 / pow(2, _getControllerZoom() + 8); - double _getControllerZoom() => controller.ready ? controller.zoom : zoom; + double _getControllerZoom() => controller!.ready ? controller!.zoom : zoom; } class FitBoundsOptions { final EdgeInsets padding; final double maxZoom; - final double zoom; + final double? zoom; const FitBoundsOptions({ this.padding = const EdgeInsets.all(0.0), @@ -379,9 +379,9 @@ class FitBoundsOptions { /// Position's type for [PositionCallback]. class MapPosition { - final LatLng center; - final LatLngBounds bounds; - final double zoom; + final LatLng? center; + final LatLngBounds? bounds; + final double? zoom; final bool hasGesture; MapPosition({this.center, this.bounds, this.zoom, this.hasGesture = false}); diff --git a/lib/src/core/bounds.dart b/lib/src/core/bounds.dart index 5111ac3d7..4801b1b8f 100644 --- a/lib/src/core/bounds.dart +++ b/lib/src/core/bounds.dart @@ -1,4 +1,5 @@ import 'dart:math' as math; + import 'package:flutter_map/src/core/point.dart'; /// Rectangular bound delimited by orthogonal lines passing through two @@ -18,20 +19,16 @@ class Bounds { /// Creates a new [Bounds] obtained by expanding the current ones with a new /// point. Bounds extend(CustomPoint point) { - CustomPoint newMin; - CustomPoint newMax; - if (min == null && max == null) { - newMin = point; - newMax = point; - } else { - var minX = math.min(point.x, min.x); - var maxX = math.max(point.x, max.x); - var minY = math.min(point.y, min.y); - var maxY = math.max(point.y, max.y); - newMin = CustomPoint(minX, minY); - newMax = CustomPoint(maxX, maxY); - } - return Bounds._(newMin, newMax); + return Bounds._( + CustomPoint( + math.min(point.x, min.x), + math.min(point.y, min.y), + ), + CustomPoint( + math.max(point.x, max.x), + math.max(point.y, max.y), + ), + ); } /// This [Bounds] cental point. diff --git a/lib/src/core/center_zoom.dart b/lib/src/core/center_zoom.dart index a725d6fe8..527768d47 100644 --- a/lib/src/core/center_zoom.dart +++ b/lib/src/core/center_zoom.dart @@ -1,7 +1,7 @@ -import 'package:latlong/latlong.dart'; +import 'package:latlong2/latlong.dart'; class CenterZoom { final LatLng center; final double zoom; - CenterZoom({this.center, this.zoom}); + CenterZoom({required this.center, required this.zoom}); } diff --git a/lib/src/core/point.dart b/lib/src/core/point.dart index de28370b1..19b6cef0e 100644 --- a/lib/src/core/point.dart +++ b/lib/src/core/point.dart @@ -1,7 +1,7 @@ import 'dart:math' as math; class CustomPoint extends math.Point { - const CustomPoint(num x, num y) : super(x, y); + const CustomPoint(num x, num y) : super(x as T, y as T); CustomPoint operator /(num /*T|int*/ factor) { return CustomPoint(x / factor, y / factor); @@ -39,8 +39,8 @@ class CustomPoint extends math.Point { } CustomPoint round() { - var x = this.x is double ? this.x.round() : this.x; - var y = this.y is double ? this.y.round() : this.y; + final x = this.x is double ? this.x.round() : this.x; + final y = this.y is double ? this.y.round() : this.y; return CustomPoint(x, y); } diff --git a/lib/src/core/util.dart b/lib/src/core/util.dart index 004a281b7..c670a459c 100644 --- a/lib/src/core/util.dart +++ b/lib/src/core/util.dart @@ -9,7 +9,7 @@ var _templateRe = RegExp(r'\{ *([\w_-]+) *\}'); /// Throws an [Exception] if any placeholder remains unresolved. String template(String str, Map data) { return str.replaceAllMapped(_templateRe, (Match match) { - var value = data[match.group(1)]; + var value = data[match.group(1)!]; if (value == null) { throw Exception('No value provided for variable ${match.group(1)}'); } else { @@ -18,7 +18,7 @@ String template(String str, Map data) { }); } -double wrapNum(double x, Tuple2 range, [bool includeMax]) { +double wrapNum(double x, Tuple2 range, [bool? includeMax]) { var max = range.item2; var min = range.item1; var d = max - min; @@ -26,18 +26,18 @@ double wrapNum(double x, Tuple2 range, [bool includeMax]) { } StreamTransformer throttleStreamTransformerWithTrailingCall( - Duration duration) { - Timer timer; + Duration? duration) { + Timer? timer; T recentData; var trailingCall = false; - void Function(T data, EventSink sink) throttleHandler; + late void Function(T data, EventSink sink) throttleHandler; throttleHandler = (T data, EventSink sink) { recentData = data; if (timer == null) { sink.add(recentData); - timer = Timer(duration, () { + timer = Timer(duration!, () { timer = null; if (trailingCall) { diff --git a/lib/src/geo/crs/crs.dart b/lib/src/geo/crs/crs.dart index 024f779e4..fad20c1be 100644 --- a/lib/src/geo/crs/crs.dart +++ b/lib/src/geo/crs/crs.dart @@ -2,7 +2,7 @@ import 'dart:math' as math; import 'package:flutter_map/src/core/bounds.dart'; import 'package:flutter_map/src/core/point.dart'; -import 'package:latlong/latlong.dart'; +import 'package:latlong2/latlong.dart'; import 'package:meta/meta.dart'; import 'package:proj4dart/proj4dart.dart' as proj4; import 'package:tuple/tuple.dart'; @@ -34,7 +34,7 @@ abstract class Crs { } /// Converts a map point to the sphere coordinate (at a certain zoom). - LatLng pointToLatLng(CustomPoint point, double zoom) { + LatLng? pointToLatLng(CustomPoint point, double zoom) { var scale = this.scale(zoom); var untransformedPoint = transformation.untransform(point, scale.toDouble()); @@ -56,10 +56,10 @@ abstract class Crs { } /// Rescales the bounds to a given zoom value. - Bounds getProjectedBounds(double zoom) { + Bounds? getProjectedBounds(double zoom) { if (infinite) return null; - var b = projection.bounds; + var b = projection.bounds!; var s = scale(zoom); var min = transformation.transform(b.min, s.toDouble()); var max = transformation.transform(b.max, s.toDouble()); @@ -68,9 +68,9 @@ abstract class Crs { bool get infinite; - Tuple2 get wrapLng; + Tuple2? get wrapLng; - Tuple2 get wrapLat; + Tuple2? get wrapLat; } // Custom CRS for non geographical maps @@ -93,10 +93,10 @@ class CrsSimple extends Crs { bool get infinite => false; @override - Tuple2 get wrapLat => null; + Tuple2? get wrapLat => null; @override - Tuple2 get wrapLng => null; + Tuple2? get wrapLng => null; } abstract class Earth extends Crs { @@ -107,7 +107,7 @@ abstract class Earth extends Crs { final Tuple2 wrapLng = const Tuple2(-180.0, 180.0); @override - final Tuple2 wrapLat = null; + final Tuple2? wrapLat = null; const Earth() : super(); } @@ -167,42 +167,37 @@ class Proj4Crs extends Crs { final bool infinite; @override - final Tuple2 wrapLat = null; + final Tuple2? wrapLat = null; @override - final Tuple2 wrapLng = null; + final Tuple2? wrapLng = null; - final List _transformations; + final List? _transformations; final List _scales; Proj4Crs._({ - @required this.code, - @required this.projection, - @required this.transformation, - @required this.infinite, - @required List transformations, - @required List scales, - }) : assert(null != code), - assert(null != projection), - assert(null != transformation || null != transformations), - assert(null != infinite), - assert(null != scales), - _transformations = transformations, + required this.code, + required this.projection, + required this.transformation, + required this.infinite, + List? transformations, + required List scales, + }) : _transformations = transformations, _scales = scales; factory Proj4Crs.fromFactory({ - @required String code, - @required proj4.Projection proj4Projection, - Transformation transformation, - List origins, - Bounds bounds, - List scales, - List resolutions, + required String code, + required proj4.Projection proj4Projection, + Transformation? transformation, + List? origins, + Bounds? bounds, + List? scales, + List? resolutions, }) { final projection = _Proj4Projection(proj4Projection: proj4Projection, bounds: bounds); - List transformations; + List? transformations; var infinite = null == bounds; List finalScales; @@ -231,7 +226,7 @@ class Proj4Crs extends Crs { return Proj4Crs._( code: code, projection: projection, - transformation: transformation, + transformation: transformation!, infinite: infinite, transformations: transformations, scales: finalScales, @@ -255,7 +250,7 @@ class Proj4Crs extends Crs { /// Converts a map point to the sphere coordinate (at a certain zoom). @override - LatLng pointToLatLng(CustomPoint point, double zoom) { + LatLng? pointToLatLng(CustomPoint point, double zoom) { var scale = this.scale(zoom); var transformation = _getTransformationByZoom(zoom); @@ -270,10 +265,10 @@ class Proj4Crs extends Crs { /// Rescales the bounds to a given zoom value. @override - Bounds getProjectedBounds(double zoom) { + Bounds? getProjectedBounds(double zoom) { if (infinite) return null; - var b = projection.bounds; + var b = projection.bounds!; var s = scale(zoom); var transformation = _getTransformationByZoom(zoom); @@ -304,27 +299,25 @@ class Proj4Crs extends Crs { num zoom(double scale) { // Find closest number in _scales, down var downScale = _closestElement(_scales, scale); + if (downScale == null) { + return double.negativeInfinity; + } var downZoom = _scales.indexOf(downScale); // Check if scale is downScale => return array index if (scale == downScale) { return downZoom; } - if (downScale == null) { - return double.negativeInfinity; - } // Interpolate var nextZoom = downZoom + 1; var nextScale = _scales[nextZoom]; - if (nextScale == null) { - return double.infinity; - } + var scaleDiff = nextScale - downScale; return (scale - downScale) / scaleDiff + downZoom; } /// Get the closest lowest element in an array - double _closestElement(List array, double element) { - double low; + double? _closestElement(List array, double element) { + double? low; for (var i = array.length - 1; i >= 0; i--) { var curr = array[i]; @@ -342,24 +335,24 @@ class Proj4Crs extends Crs { } var iZoom = zoom.round(); - var lastIdx = _transformations.length - 1; + var lastIdx = _transformations!.length - 1; - return _transformations[iZoom > lastIdx ? lastIdx : iZoom]; + return _transformations![iZoom > lastIdx ? lastIdx : iZoom]; } } abstract class Projection { const Projection(); - Bounds get bounds; + Bounds? get bounds; CustomPoint project(LatLng latlng); LatLng unproject(CustomPoint point); double _inclusive(Comparable start, Comparable end, double value) { - if (value.compareTo(start) < 0) return start; - if (value.compareTo(end) > 0) return end; + if (value.compareTo(start as num) < 0) return start as double; + if (value.compareTo(end as num) > 0) return end as double; return value; } @@ -391,7 +384,8 @@ class _LonLat extends Projection { @override LatLng unproject(CustomPoint point) { - return LatLng(inclusiveLat(point.y), inclusiveLng(point.x)); + return LatLng( + inclusiveLat(point.y as double), inclusiveLng(point.x as double)); } } @@ -436,13 +430,12 @@ class _Proj4Projection extends Projection { final proj4.Projection proj4Projection; @override - final Bounds bounds; + final Bounds? bounds; _Proj4Projection({ - @required this.proj4Projection, - @required this.bounds, - }) : assert(null != proj4Projection), - epsg4326 = proj4.Projection.WGS84; + required this.proj4Projection, + this.bounds, + }) : epsg4326 = proj4.Projection.WGS84; @override CustomPoint project(LatLng latlng) { @@ -455,7 +448,7 @@ class _Proj4Projection extends Projection { @override LatLng unproject(CustomPoint point) { var point2 = proj4Projection.transform( - epsg4326, proj4.Point(x: point.x, y: point.y)); + epsg4326, proj4.Point(x: point.x as double, y: point.y as double)); return LatLng(inclusiveLat(point2.y), inclusiveLng(point2.x)); } @@ -469,14 +462,14 @@ class Transformation { const Transformation(this.a, this.b, this.c, this.d); - CustomPoint transform(CustomPoint point, double scale) { + CustomPoint transform(CustomPoint point, double? scale) { scale ??= 1.0; var x = scale * (a * point.x + b); var y = scale * (c * point.y + d); return CustomPoint(x, y); } - CustomPoint untransform(CustomPoint point, double scale) { + CustomPoint untransform(CustomPoint point, double? scale) { scale ??= 1.0; var x = (point.x / scale - b) / a; var y = (point.y / scale - d) / c; diff --git a/lib/src/geo/latlng_bounds.dart b/lib/src/geo/latlng_bounds.dart index 143366755..b27e8b324 100644 --- a/lib/src/geo/latlng_bounds.dart +++ b/lib/src/geo/latlng_bounds.dart @@ -1,21 +1,22 @@ import 'dart:math' as math; -import 'package:latlong/latlong.dart'; + +import 'package:latlong2/latlong.dart'; class LatLngBounds { - LatLng _sw; - LatLng _ne; + LatLng? _sw; + LatLng? _ne; - LatLngBounds([LatLng corner1, LatLng corner2]) { + LatLngBounds([LatLng? corner1, LatLng? corner2]) { extend(corner1); extend(corner2); } LatLngBounds.fromPoints(List points) { - if (points != null && points.isNotEmpty) { - num minX; - num maxX; - num minY; - num maxY; + if (points.isNotEmpty) { + num? minX; + num? maxX; + num? minY; + num? maxY; for (var point in points) { num x = point.longitudeInRad; @@ -38,12 +39,12 @@ class LatLngBounds { } } - _sw = LatLng(radianToDeg(minY), radianToDeg(minX)); - _ne = LatLng(radianToDeg(maxY), radianToDeg(maxX)); + _sw = LatLng(radianToDeg(minY as double), radianToDeg(minX as double)); + _ne = LatLng(radianToDeg(maxY as double), radianToDeg(maxX as double)); } } - void extend(LatLng latlng) { + void extend(LatLng? latlng) { if (latlng == null) { return; } @@ -54,25 +55,25 @@ class LatLngBounds { _extend(bounds._sw, bounds._ne); } - void _extend(LatLng sw2, LatLng ne2) { + void _extend(LatLng? sw2, LatLng? ne2) { if (_sw == null && _ne == null) { - _sw = LatLng(sw2.latitude, sw2.longitude); - _ne = LatLng(ne2.latitude, ne2.longitude); + _sw = LatLng(sw2!.latitude, sw2.longitude); + _ne = LatLng(ne2!.latitude, ne2.longitude); } else { - _sw.latitude = math.min(sw2.latitude, _sw.latitude); - _sw.longitude = math.min(sw2.longitude, _sw.longitude); - _ne.latitude = math.max(ne2.latitude, _ne.latitude); - _ne.longitude = math.max(ne2.longitude, _ne.longitude); + _sw!.latitude = math.min(sw2!.latitude, _sw!.latitude); + _sw!.longitude = math.min(sw2.longitude, _sw!.longitude); + _ne!.latitude = math.max(ne2!.latitude, _ne!.latitude); + _ne!.longitude = math.max(ne2.longitude, _ne!.longitude); } } - double get west => southWest.longitude; - double get south => southWest.latitude; - double get east => northEast.longitude; - double get north => northEast.latitude; + double get west => southWest!.longitude; + double get south => southWest!.latitude; + double get east => northEast!.longitude; + double get north => northEast!.latitude; - LatLng get southWest => _sw; - LatLng get northEast => _ne; + LatLng? get southWest => _sw; + LatLng? get northEast => _ne; LatLng get northWest => LatLng(north, west); LatLng get southEast => LatLng(south, east); @@ -80,7 +81,7 @@ class LatLngBounds { return _sw != null && _ne != null; } - bool contains(LatLng point) { + bool contains(LatLng? point) { if (!isValid) { return false; } @@ -90,34 +91,34 @@ class LatLngBounds { } bool containsBounds(LatLngBounds bounds) { - var sw2 = bounds._sw; + var sw2 = bounds._sw!; var ne2 = bounds._ne; - return (sw2.latitude >= _sw.latitude) && - (ne2.latitude <= _ne.latitude) && - (sw2.longitude >= _sw.longitude) && - (ne2.longitude <= _ne.longitude); + return (sw2.latitude >= _sw!.latitude) && + (ne2!.latitude <= _ne!.latitude) && + (sw2.longitude >= _sw!.longitude) && + (ne2.longitude <= _ne!.longitude); } - bool isOverlapping(LatLngBounds bounds) { + bool isOverlapping(LatLngBounds? bounds) { if (!isValid) { return false; } // check if bounding box rectangle is outside the other, if it is then it's // considered not overlapping - if (_sw.latitude > bounds._ne.latitude || - _ne.latitude < bounds._sw.latitude || - _ne.longitude < bounds._sw.longitude || - _sw.longitude > bounds._ne.longitude) { + if (_sw!.latitude > bounds!._ne!.latitude || + _ne!.latitude < bounds._sw!.latitude || + _ne!.longitude < bounds._sw!.longitude || + _sw!.longitude > bounds._ne!.longitude) { return false; } return true; } void pad(double bufferRatio) { - var heightBuffer = (_sw.latitude - _ne.latitude).abs() * bufferRatio; - var widthBuffer = (_sw.longitude - _ne.longitude).abs() * bufferRatio; + var heightBuffer = (_sw!.latitude - _ne!.latitude).abs() * bufferRatio; + var widthBuffer = (_sw!.longitude - _ne!.longitude).abs() * bufferRatio; - _sw = LatLng(_sw.latitude - heightBuffer, _sw.longitude - widthBuffer); - _ne = LatLng(_ne.latitude + heightBuffer, _ne.longitude + widthBuffer); + _sw = LatLng(_sw!.latitude - heightBuffer, _sw!.longitude - widthBuffer); + _ne = LatLng(_ne!.latitude + heightBuffer, _ne!.longitude + widthBuffer); } } diff --git a/lib/src/gestures/gestures.dart b/lib/src/gestures/gestures.dart index d491efc6d..bc81176a5 100644 --- a/lib/src/gestures/gestures.dart +++ b/lib/src/gestures/gestures.dart @@ -6,7 +6,7 @@ import 'package:flutter_map/flutter_map.dart'; import 'package:flutter_map/src/gestures/interactive_flag.dart'; import 'package:flutter_map/src/gestures/latlng_tween.dart'; import 'package:flutter_map/src/map/map.dart'; -import 'package:latlong/latlong.dart'; +import 'package:latlong2/latlong.dart'; import 'package:positioned_tap_detector_2/positioned_tap_detector_2.dart'; abstract class MapGestureMixin extends State @@ -30,25 +30,25 @@ abstract class MapGestureMixin extends State // Helps to reset ScaleUpdateDetails.scale back to 1.0 when a multi finger // gesture wins - double _scaleCorrector; + late double _scaleCorrector; - double _lastRotation; - double _lastScale; - Offset _lastFocalLocal; + late double _lastRotation; + late double _lastScale; + late Offset _lastFocalLocal; - LatLng _mapCenterStart; - double _mapZoomStart; - Offset _focalStartLocal; + late LatLng _mapCenterStart; + late double _mapZoomStart; + late Offset _focalStartLocal; - AnimationController _flingController; - Animation _flingAnimation; + late AnimationController _flingController; + late Animation _flingAnimation; - AnimationController _doubleTapController; - Animation _doubleTapZoomAnimation; - Animation _doubleTapCenterAnimation; + late AnimationController _doubleTapController; + late Animation _doubleTapZoomAnimation; + late Animation _doubleTapCenterAnimation; int _tapUpCounter = 0; - Timer _doubleTapHoldMaxDelay; + Timer? _doubleTapHoldMaxDelay; @override FlutterMap get widget; @@ -161,7 +161,7 @@ abstract class MapGestureMixin extends State } } - int _getMultiFingerGestureFlags({int gestureWinner, MapOptions mapOptions}) { + int _getMultiFingerGestureFlags({int? gestureWinner, MapOptions? mapOptions}) { gestureWinner ??= _gestureWinner; mapOptions ??= options; @@ -480,7 +480,7 @@ abstract class MapGestureMixin extends State var direction = details.velocity.pixelsPerSecond / magnitude; var distance = - (Offset.zero & Size(mapState.originalSize.x, mapState.originalSize.y)) + (Offset.zero & Size(mapState.originalSize!.x as double, mapState.originalSize!.y as double)) .shortestSide; var _flingOffset = _focalStartLocal - _lastFocalLocal; @@ -498,10 +498,10 @@ abstract class MapGestureMixin extends State closeFlingAnimationController(MapEventSource.tap); closeDoubleTapController(MapEventSource.tap); - final latlng = _offsetToCrs(position.relative); + final latlng = _offsetToCrs(position.relative!); if (options.onTap != null) { // emit the event - options.onTap(latlng); + options.onTap!(latlng); } mapState.emitMapEvent( @@ -520,10 +520,10 @@ abstract class MapGestureMixin extends State closeFlingAnimationController(MapEventSource.longPress); closeDoubleTapController(MapEventSource.longPress); - final latlng = _offsetToCrs(position.relative); + final latlng = _offsetToCrs(position.relative!); if (options.onLongPress != null) { // emit the event - options.onLongPress(latlng); + options.onLongPress!(latlng); } mapState.emitMapEvent( @@ -538,7 +538,7 @@ abstract class MapGestureMixin extends State LatLng _offsetToCrs(Offset offset) { final focalStartPt = mapState.project(mapState.center, mapState.zoom); - final point = (_offsetToPoint(offset) - (mapState.originalSize / 2.0)) + final point = (_offsetToPoint(offset) - (mapState.originalSize! / 2.0)) .rotate(mapState.rotationRad); var newCenterPt = focalStartPt + point; @@ -557,10 +557,10 @@ abstract class MapGestureMixin extends State if (InteractiveFlag.hasFlag( options.interactiveFlags, InteractiveFlag.doubleTapZoom)) { - final centerPos = _pointToOffset(mapState.originalSize) / 2.0; + final centerPos = _pointToOffset(mapState.originalSize!) / 2.0; final newZoom = _getZoomForScale(mapState.zoom, 2.0); final focalDelta = _getDoubleTapFocalDelta( - centerPos, tapPosition.relative, newZoom - mapState.zoom); + centerPos, tapPosition.relative!, newZoom - mapState.zoom); final newCenter = _offsetToCrs(centerPos + focalDelta); _startDoubleTapAnimation(newZoom, newCenter); } diff --git a/lib/src/gestures/latlng_tween.dart b/lib/src/gestures/latlng_tween.dart index f1e376b15..145778da8 100644 --- a/lib/src/gestures/latlng_tween.dart +++ b/lib/src/gestures/latlng_tween.dart @@ -1,14 +1,13 @@ import 'package:flutter/animation.dart'; -import 'package:flutter/foundation.dart'; -import 'package:latlong/latlong.dart'; +import 'package:latlong2/latlong.dart'; class LatLngTween extends Tween { - LatLngTween({@required LatLng begin, @required LatLng end}) + LatLngTween({required LatLng begin, required LatLng end}) : super(begin: begin, end: end); @override LatLng lerp(double t) => LatLng( - begin.latitude + (end.latitude - begin.latitude) * t, - begin.longitude + (end.longitude - begin.longitude) * t, + begin!.latitude + (end!.latitude - begin!.latitude) * t, + begin!.longitude + (end!.longitude - begin!.longitude) * t, ); } diff --git a/lib/src/gestures/map_events.dart b/lib/src/gestures/map_events.dart index 3ab472844..084b8c178 100644 --- a/lib/src/gestures/map_events.dart +++ b/lib/src/gestures/map_events.dart @@ -1,4 +1,4 @@ -import 'package:latlong/latlong.dart'; +import 'package:latlong2/latlong.dart'; enum MapEventSource { mapController, @@ -15,6 +15,9 @@ enum MapEventSource { flingAnimationController, doubleTapZoomAnimationController, interactiveFlagsChanged, + fitBounds, + initialization, + custom } abstract class MapEvent { @@ -25,7 +28,7 @@ abstract class MapEvent { // current zoom when event is emitted final double zoom; - MapEvent({this.source, this.center, this.zoom}); + MapEvent({required this.source, required this.center, required this.zoom}); } abstract class MapEventWithMove extends MapEvent { @@ -33,11 +36,11 @@ abstract class MapEventWithMove extends MapEvent { final double targetZoom; MapEventWithMove({ - this.targetCenter, - this.targetZoom, - MapEventSource source, - LatLng center, - double zoom, + required this.targetCenter, + required this.targetZoom, + required MapEventSource source, + required LatLng center, + required double zoom, }) : super(source: source, center: center, zoom: zoom); } @@ -45,10 +48,10 @@ class MapEventTap extends MapEvent { final LatLng tapPosition; MapEventTap({ - this.tapPosition, - MapEventSource source, - LatLng center, - double zoom, + required this.tapPosition, + required MapEventSource source, + required LatLng center, + required double zoom, }) : super(source: source, center: center, zoom: zoom); } @@ -56,23 +59,23 @@ class MapEventLongPress extends MapEvent { final LatLng tapPosition; MapEventLongPress({ - this.tapPosition, - MapEventSource source, - LatLng center, - double zoom, + required this.tapPosition, + required MapEventSource source, + required LatLng center, + required double zoom, }) : super(source: source, center: center, zoom: zoom); } class MapEventMove extends MapEventWithMove { - final String id; + final String? id; MapEventMove({ this.id, - LatLng targetCenter, - double targetZoom, - MapEventSource source, - LatLng center, - double zoom, + required LatLng targetCenter, + required double targetZoom, + required MapEventSource source, + required LatLng center, + required double zoom, }) : super( targetCenter: targetCenter, targetZoom: targetZoom, @@ -83,22 +86,28 @@ class MapEventMove extends MapEventWithMove { } class MapEventMoveStart extends MapEvent { - MapEventMoveStart({MapEventSource source, LatLng center, double zoom}) + MapEventMoveStart( + {required MapEventSource source, + required LatLng center, + required double zoom}) : super(source: source, center: center, zoom: zoom); } class MapEventMoveEnd extends MapEvent { - MapEventMoveEnd({MapEventSource source, LatLng center, double zoom}) + MapEventMoveEnd( + {required MapEventSource source, + required LatLng center, + required double zoom}) : super(source: source, center: center, zoom: zoom); } class MapEventFlingAnimation extends MapEventWithMove { MapEventFlingAnimation({ - LatLng targetCenter, - double targetZoom, - MapEventSource source, - LatLng center, - double zoom, + required LatLng targetCenter, + required double targetZoom, + required MapEventSource source, + required LatLng center, + required double zoom, }) : super( targetCenter: targetCenter, targetZoom: targetZoom, @@ -112,28 +121,35 @@ class MapEventFlingAnimation extends MapEventWithMove { /// to start fling animation class MapEventFlingAnimationNotStarted extends MapEvent { MapEventFlingAnimationNotStarted( - {MapEventSource source, LatLng center, double zoom}) + {required MapEventSource source, + required LatLng center, + required double zoom}) : super(source: source, center: center, zoom: zoom); } class MapEventFlingAnimationStart extends MapEvent { MapEventFlingAnimationStart( - {MapEventSource source, LatLng center, double zoom}) + {required MapEventSource source, + required LatLng center, + required double zoom}) : super(source: source, center: center, zoom: zoom); } class MapEventFlingAnimationEnd extends MapEvent { - MapEventFlingAnimationEnd({MapEventSource source, LatLng center, double zoom}) + MapEventFlingAnimationEnd( + {required MapEventSource source, + required LatLng center, + required double zoom}) : super(source: source, center: center, zoom: zoom); } class MapEventDoubleTapZoom extends MapEventWithMove { MapEventDoubleTapZoom({ - LatLng targetCenter, - double targetZoom, - MapEventSource source, - LatLng center, - double zoom, + required LatLng targetCenter, + required double targetZoom, + required MapEventSource source, + required LatLng center, + required double zoom, }) : super( targetCenter: targetCenter, targetZoom: targetZoom, @@ -145,36 +161,47 @@ class MapEventDoubleTapZoom extends MapEventWithMove { class MapEventDoubleTapZoomStart extends MapEvent { MapEventDoubleTapZoomStart( - {MapEventSource source, LatLng center, double zoom}) + {required MapEventSource source, + required LatLng center, + required double zoom}) : super(source: source, center: center, zoom: zoom); } class MapEventDoubleTapZoomEnd extends MapEvent { - MapEventDoubleTapZoomEnd({MapEventSource source, LatLng center, double zoom}) + MapEventDoubleTapZoomEnd( + {required MapEventSource source, + required LatLng center, + required double zoom}) : super(source: source, center: center, zoom: zoom); } class MapEventRotate extends MapEvent { - final String id; + final String? id; final double currentRotation; final double targetRotation; MapEventRotate({ - this.id, - this.currentRotation, - this.targetRotation, - MapEventSource source, - LatLng center, - double zoom, + required this.id, + required this.currentRotation, + required this.targetRotation, + required MapEventSource source, + required LatLng center, + required double zoom, }) : super(source: source, center: center, zoom: zoom); } class MapEventRotateStart extends MapEvent { - MapEventRotateStart({MapEventSource source, LatLng center, double zoom}) + MapEventRotateStart( + {required MapEventSource source, + required LatLng center, + required double zoom}) : super(source: source, center: center, zoom: zoom); } class MapEventRotateEnd extends MapEvent { - MapEventRotateEnd({MapEventSource source, LatLng center, double zoom}) + MapEventRotateEnd( + {required MapEventSource source, + required LatLng center, + required double zoom}) : super(source: source, center: center, zoom: zoom); } diff --git a/lib/src/layer/circle_layer.dart b/lib/src/layer/circle_layer.dart index 0f79d95f0..8f7c14804 100644 --- a/lib/src/layer/circle_layer.dart +++ b/lib/src/layer/circle_layer.dart @@ -3,14 +3,14 @@ import 'dart:ui'; import 'package:flutter/widgets.dart'; import 'package:flutter_map/flutter_map.dart'; import 'package:flutter_map/src/map/map.dart'; -import 'package:latlong/latlong.dart' hide Path; +import 'package:latlong2/latlong.dart' hide Path; class CircleLayerOptions extends LayerOptions { final List circles; CircleLayerOptions({ - Key key, + Key? key, this.circles = const [], - Stream rebuild, + Stream? rebuild, }) : super(key: key, rebuild: rebuild); } @@ -24,8 +24,8 @@ class CircleMarker { Offset offset = Offset.zero; num realRadius = 0; CircleMarker({ - this.point, - this.radius, + required this.point, + required this.radius, this.useRadiusInMeter = false, this.color = const Color(0xFF00FF00), this.borderStrokeWidth = 0.0, @@ -36,11 +36,11 @@ class CircleMarker { class CircleLayerWidget extends StatelessWidget { final CircleLayerOptions options; - CircleLayerWidget({Key key, @required this.options}) : super(key: key); + CircleLayerWidget({Key? key, required this.options}) : super(key: key); @override Widget build(BuildContext context) { - final mapState = MapState.of(context); + final mapState = MapState.maybeOf(context)!; return CircleLayer(options, mapState, mapState.onMoved); } } @@ -48,7 +48,7 @@ class CircleLayerWidget extends StatelessWidget { class CircleLayer extends StatelessWidget { final CircleLayerOptions circleOpts; final MapState map; - final Stream stream; + final Stream? stream; CircleLayer(this.circleOpts, this.map, this.stream) : super(key: circleOpts.key); @@ -112,8 +112,11 @@ class CirclePainter extends CustomPainter { ..style = PaintingStyle.fill ..color = circle.color; - _paintCircle(canvas, circle.offset, - circle.useRadiusInMeter ? circle.realRadius : circle.radius, paint); + _paintCircle( + canvas, + circle.offset, + circle.useRadiusInMeter ? circle.realRadius as double : circle.radius, + paint); if (circle.borderStrokeWidth > 0) { final paint = Paint() @@ -121,8 +124,11 @@ class CirclePainter extends CustomPainter { ..color = circle.borderColor ..strokeWidth = circle.borderStrokeWidth; - _paintCircle(canvas, circle.offset, - circle.useRadiusInMeter ? circle.realRadius : circle.radius, paint); + _paintCircle( + canvas, + circle.offset, + circle.useRadiusInMeter ? circle.realRadius as double : circle.radius, + paint); } } diff --git a/lib/src/layer/group_layer.dart b/lib/src/layer/group_layer.dart index 91cbe36bc..68b79761a 100644 --- a/lib/src/layer/group_layer.dart +++ b/lib/src/layer/group_layer.dart @@ -7,20 +7,20 @@ class GroupLayerOptions extends LayerOptions { List group = []; GroupLayerOptions({ - Key key, - this.group, - Stream rebuild, + required Key key, + required this.group, + required Stream rebuild, }) : super(key: key, rebuild: rebuild); } class GroupLayerWidget extends StatelessWidget { final GroupLayerOptions options; - GroupLayerWidget({Key key, @required this.options}) : super(key: key); + GroupLayerWidget({Key? key, required this.options}) : super(key: key); @override Widget build(BuildContext context) { - final mapState = MapState.of(context); + final mapState = MapState.maybeOf(context)!; return GroupLayer(options, mapState, mapState.onMoved); } } diff --git a/lib/src/layer/layer.dart b/lib/src/layer/layer.dart index 7105fd0eb..cf4cb0801 100644 --- a/lib/src/layer/layer.dart +++ b/lib/src/layer/layer.dart @@ -5,7 +5,7 @@ import 'package:flutter/foundation.dart'; /// All LayerOptions have access to a stream that notifies when the map needs /// rebuilding. class LayerOptions { - final Key key; - final Stream rebuild; + final Key? key; + final Stream? rebuild; LayerOptions({this.key, this.rebuild}); } diff --git a/lib/src/layer/marker_layer.dart b/lib/src/layer/marker_layer.dart index c23978fab..426c0317c 100644 --- a/lib/src/layer/marker_layer.dart +++ b/lib/src/layer/marker_layer.dart @@ -2,14 +2,14 @@ import 'package:flutter/widgets.dart'; import 'package:flutter_map/flutter_map.dart'; import 'package:flutter_map/src/core/bounds.dart'; import 'package:flutter_map/src/map/map.dart'; -import 'package:latlong/latlong.dart'; +import 'package:latlong2/latlong.dart'; class MarkerLayerOptions extends LayerOptions { final List markers; MarkerLayerOptions({ - Key key, + Key? key, this.markers = const [], - Stream rebuild, + Stream? rebuild, }) : super(key: key, rebuild: rebuild); } @@ -51,8 +51,8 @@ class Anchor { } } - factory Anchor.forPos(AnchorPos pos, double width, double height) { - if (pos == null) return Anchor._(width, height, null); + factory Anchor.forPos(AnchorPos? pos, double width, double height) { + if (pos == null) return Anchor._(width, height, AnchorAlign.none); if (pos.value is AnchorAlign) return Anchor._(width, height, pos.value); if (pos.value is Anchor) return pos.value; throw Exception('Unsupported AnchorPos value type: ${pos.runtimeType}.'); @@ -67,6 +67,7 @@ class AnchorPos { } enum AnchorAlign { + none, left, right, top, @@ -82,22 +83,22 @@ class Marker { final Anchor anchor; Marker({ - this.point, - this.builder, + required this.point, + required this.builder, this.width = 30.0, this.height = 30.0, - AnchorPos anchorPos, + AnchorPos? anchorPos, }) : anchor = Anchor.forPos(anchorPos, width, height); } class MarkerLayerWidget extends StatelessWidget { final MarkerLayerOptions options; - MarkerLayerWidget({Key key, @required this.options}) : super(key: key); + MarkerLayerWidget({Key? key, required this.options}) : super(key: key); @override Widget build(BuildContext context) { - final mapState = MapState.of(context); + final mapState = MapState.maybeOf(context)!; return MarkerLayer(options, mapState, mapState.onMoved); } } @@ -105,7 +106,7 @@ class MarkerLayerWidget extends StatelessWidget { class MarkerLayer extends StatelessWidget { final MarkerLayerOptions markerOpts; final MapState map; - final Stream stream; + final Stream? stream; MarkerLayer(this.markerOpts, this.map, this.stream) : super(key: markerOpts.key); @@ -123,9 +124,9 @@ class MarkerLayer extends StatelessWidget { @override Widget build(BuildContext context) { - return StreamBuilder( + return StreamBuilder( stream: stream, // a Stream or null - builder: (BuildContext context, AsyncSnapshot snapshot) { + builder: (BuildContext context, AsyncSnapshot snapshot) { var markers = []; for (var markerOpt in markerOpts.markers) { var pos = map.project(markerOpt.point); diff --git a/lib/src/layer/overlay_image_layer.dart b/lib/src/layer/overlay_image_layer.dart index a753c6aab..137c63155 100644 --- a/lib/src/layer/overlay_image_layer.dart +++ b/lib/src/layer/overlay_image_layer.dart @@ -9,9 +9,9 @@ class OverlayImageLayerOptions extends LayerOptions { final List overlayImages; OverlayImageLayerOptions({ - Key key, + Key? key, this.overlayImages = const [], - Stream rebuild, + Stream? rebuild, }) : super(key: key, rebuild: rebuild); } @@ -22,8 +22,8 @@ class OverlayImage { final bool gaplessPlayback; OverlayImage({ - this.bounds, - this.imageProvider, + required this.bounds, + required this.imageProvider, this.opacity = 1.0, this.gaplessPlayback = false, }); @@ -32,11 +32,11 @@ class OverlayImage { class OverlayImageLayerWidget extends StatelessWidget { final OverlayImageLayerOptions options; - OverlayImageLayerWidget({Key key, @required this.options}) : super(key: key); + OverlayImageLayerWidget({Key? key, required this.options}) : super(key: key); @override Widget build(BuildContext context) { - final mapState = MapState.of(context); + final mapState = MapState.maybeOf(context)!; return OverlayImageLayer(options, mapState, mapState.onMoved); } } @@ -44,7 +44,7 @@ class OverlayImageLayerWidget extends StatelessWidget { class OverlayImageLayer extends StatelessWidget { final OverlayImageLayerOptions overlayImageOpts; final MapState map; - final Stream stream; + final Stream? stream; OverlayImageLayer(this.overlayImageOpts, this.map, this.stream) : super(key: overlayImageOpts.key); diff --git a/lib/src/layer/polygon_layer.dart b/lib/src/layer/polygon_layer.dart index 40739677e..7284aec53 100644 --- a/lib/src/layer/polygon_layer.dart +++ b/lib/src/layer/polygon_layer.dart @@ -4,7 +4,7 @@ import 'dart:ui'; import 'package:flutter/widgets.dart'; import 'package:flutter_map/flutter_map.dart'; import 'package:flutter_map/src/map/map.dart'; -import 'package:latlong/latlong.dart' hide Path; // conflict with Path from UI +import 'package:latlong2/latlong.dart' hide Path; // conflict with Path from UI class PolygonLayerOptions extends LayerOptions { final List polygons; @@ -12,10 +12,10 @@ class PolygonLayerOptions extends LayerOptions { /// screen space culling of polygons based on bounding box PolygonLayerOptions({ - Key key, + Key? key, this.polygons = const [], this.polygonCulling = false, - Stream rebuild, + Stream? rebuild, }) : super(key: key, rebuild: rebuild) { if (polygonCulling) { for (var polygon in polygons) { @@ -28,17 +28,17 @@ class PolygonLayerOptions extends LayerOptions { class Polygon { final List points; final List offsets = []; - final List> holePointsList; - final List> holeOffsetsList; + final List>? holePointsList; + final List>? holeOffsetsList; final Color color; final double borderStrokeWidth; final Color borderColor; final bool disableHolesBorder; final bool isDotted; - LatLngBounds boundingBox; + late LatLngBounds boundingBox; Polygon({ - this.points, + required this.points, this.holePointsList, this.color = const Color(0xFF00FF00), this.borderStrokeWidth = 0.0, @@ -52,11 +52,11 @@ class Polygon { class PolygonLayerWidget extends StatelessWidget { final PolygonLayerOptions options; - PolygonLayerWidget({Key key, @required this.options}) : super(key: key); + PolygonLayerWidget({Key? key, required this.options}) : super(key: key); @override Widget build(BuildContext context) { - final mapState = MapState.of(context); + final mapState = MapState.maybeOf(context)!; return PolygonLayer(options, mapState, mapState.onMoved); } } @@ -64,7 +64,7 @@ class PolygonLayerWidget extends StatelessWidget { class PolygonLayer extends StatelessWidget { final PolygonLayerOptions polygonOpts; final MapState map; - final Stream stream; + final Stream? stream; PolygonLayer(this.polygonOpts, this.map, this.stream) : super(key: polygonOpts.key); @@ -89,7 +89,7 @@ class PolygonLayer extends StatelessWidget { polygon.offsets.clear(); if (null != polygon.holeOffsetsList) { - for (var offsets in polygon.holeOffsetsList) { + for (var offsets in polygon.holeOffsetsList!) { offsets.clear(); } } @@ -103,9 +103,11 @@ class PolygonLayer extends StatelessWidget { _fillOffsets(polygon.offsets, polygon.points); if (null != polygon.holePointsList) { - for (var i = 0, len = polygon.holePointsList.length; i < len; ++i) { + for (var i = 0, len = polygon.holePointsList!.length; + i < len; + ++i) { _fillOffsets( - polygon.holeOffsetsList[i], polygon.holePointsList[i]); + polygon.holeOffsetsList![i], polygon.holePointsList![i]); } } @@ -170,7 +172,7 @@ class PolygonPainter extends CustomPainter { if (!polygonOpt.disableHolesBorder && null != polygonOpt.holeOffsetsList) { - for (var offsets in polygonOpt.holeOffsetsList) { + for (var offsets in polygonOpt.holeOffsetsList!) { _paintDottedLine( canvas, offsets, borderRadius, spacing, borderPaint); } @@ -180,7 +182,7 @@ class PolygonPainter extends CustomPainter { if (!polygonOpt.disableHolesBorder && null != polygonOpt.holeOffsetsList) { - for (var offsets in polygonOpt.holeOffsetsList) { + for (var offsets in polygonOpt.holeOffsetsList!) { _paintLine(canvas, offsets, borderRadius, borderPaint); } } @@ -225,7 +227,7 @@ class PolygonPainter extends CustomPainter { canvas.saveLayer(rect, paint); paint.style = PaintingStyle.fill; - for (var offsets in polygonOpt.holeOffsetsList) { + for (var offsets in polygonOpt.holeOffsetsList!) { var path = Path(); path.addPolygon(offsets, true); canvas.drawPath(path, paint); diff --git a/lib/src/layer/polyline_layer.dart b/lib/src/layer/polyline_layer.dart index b5d286bae..b114748bb 100644 --- a/lib/src/layer/polyline_layer.dart +++ b/lib/src/layer/polyline_layer.dart @@ -4,17 +4,17 @@ import 'dart:ui' as ui; import 'package:flutter/widgets.dart'; import 'package:flutter_map/flutter_map.dart'; import 'package:flutter_map/src/map/map.dart'; -import 'package:latlong/latlong.dart'; +import 'package:latlong2/latlong.dart'; class PolylineLayerOptions extends LayerOptions { final List polylines; final bool polylineCulling; PolylineLayerOptions({ - Key key, + Key? key, this.polylines = const [], this.polylineCulling = false, - Stream rebuild, + Stream? rebuild, }) : super(key: key, rebuild: rebuild) { if (polylineCulling) { for (var polyline in polylines) { @@ -30,14 +30,14 @@ class Polyline { final double strokeWidth; final Color color; final double borderStrokeWidth; - final Color borderColor; - final List gradientColors; - final List colorsStop; + final Color? borderColor; + final List? gradientColors; + final List? colorsStop; final bool isDotted; - LatLngBounds boundingBox; + late LatLngBounds boundingBox; Polyline({ - this.points, + required this.points, this.strokeWidth = 1.0, this.color = const Color(0xFF00FF00), this.borderStrokeWidth = 0.0, @@ -50,11 +50,11 @@ class Polyline { class PolylineLayerWidget extends StatelessWidget { final PolylineLayerOptions options; - PolylineLayerWidget({Key key, @required this.options}) : super(key: key); + PolylineLayerWidget({Key? key, required this.options}) : super(key: key); @override Widget build(BuildContext context) { - final mapState = MapState.of(context); + final mapState = MapState.maybeOf(context)!; return PolylineLayer(options, mapState, mapState.onMoved); } } @@ -62,7 +62,7 @@ class PolylineLayerWidget extends StatelessWidget { class PolylineLayer extends StatelessWidget { final PolylineLayerOptions polylineOpts; final MapState map; - final Stream stream; + final Stream? stream; PolylineLayer(this.polylineOpts, this.map, this.stream) : super(key: polylineOpts.key); @@ -145,15 +145,15 @@ class PolylinePainter extends CustomPainter { if (polylineOpt.gradientColors == null) { paint.color = polylineOpt.color; } else { - polylineOpt.gradientColors.isNotEmpty + polylineOpt.gradientColors!.isNotEmpty ? paint.shader = _paintGradient() : paint.color = polylineOpt.color; } - Paint filterPaint; + Paint? filterPaint; if (polylineOpt.borderColor != null) { filterPaint = Paint() - ..color = polylineOpt.borderColor.withAlpha(255) + ..color = polylineOpt.borderColor!.withAlpha(255) ..strokeWidth = polylineOpt.strokeWidth ..strokeCap = StrokeCap.round ..strokeJoin = StrokeJoin.round @@ -162,7 +162,7 @@ class PolylinePainter extends CustomPainter { final borderPaint = polylineOpt.borderStrokeWidth > 0.0 ? (Paint() - ..color = polylineOpt.borderColor + ..color = polylineOpt.borderColor ?? Color(0x00000000) ..strokeWidth = polylineOpt.strokeWidth + polylineOpt.borderStrokeWidth ..strokeCap = StrokeCap.round @@ -174,7 +174,7 @@ class PolylinePainter extends CustomPainter { if (polylineOpt.isDotted) { var spacing = polylineOpt.strokeWidth * 1.5; canvas.saveLayer(rect, Paint()); - if (borderPaint != null) { + if (borderPaint != null && filterPaint != null) { _paintDottedLine( canvas, polylineOpt.offsets, borderRadius, spacing, borderPaint); _paintDottedLine( @@ -185,12 +185,10 @@ class PolylinePainter extends CustomPainter { } else { paint.style = PaintingStyle.stroke; canvas.saveLayer(rect, Paint()); - if (borderPaint != null) { - if (filterPaint != null) { - filterPaint.style = PaintingStyle.stroke; - _paintLine(canvas, polylineOpt.offsets, borderPaint); - } - borderPaint?.style = PaintingStyle.stroke; + if (borderPaint != null && filterPaint != null) { + borderPaint.style = PaintingStyle.stroke; + _paintLine(canvas, polylineOpt.offsets, borderPaint); + filterPaint.style = PaintingStyle.stroke; _paintLine(canvas, polylineOpt.offsets, filterPaint); } _paintLine(canvas, polylineOpt.offsets, paint); @@ -234,18 +232,18 @@ class PolylinePainter extends CustomPainter { } ui.Gradient _paintGradient() => ui.Gradient.linear(polylineOpt.offsets.first, - polylineOpt.offsets.last, polylineOpt.gradientColors, _getColorsStop()); + polylineOpt.offsets.last, polylineOpt.gradientColors!, _getColorsStop()); - List _getColorsStop() => (polylineOpt.colorsStop != null && - polylineOpt.colorsStop.length == polylineOpt.gradientColors.length) + List? _getColorsStop() => (polylineOpt.colorsStop != null && + polylineOpt.colorsStop!.length == polylineOpt.gradientColors!.length) ? polylineOpt.colorsStop : _calculateColorsStop(); List _calculateColorsStop() { - final colorsStopInterval = 1.0 / polylineOpt.gradientColors.length; - return polylineOpt.gradientColors + final colorsStopInterval = 1.0 / polylineOpt.gradientColors!.length; + return polylineOpt.gradientColors! .map((gradientColor) => - polylineOpt.gradientColors.indexOf(gradientColor) * + polylineOpt.gradientColors!.indexOf(gradientColor) * colorsStopInterval) .toList(); } diff --git a/lib/src/layer/tile_layer.dart b/lib/src/layer/tile_layer.dart index 8033578ce..134dc92f4 100644 --- a/lib/src/layer/tile_layer.dart +++ b/lib/src/layer/tile_layer.dart @@ -11,7 +11,7 @@ import 'package:flutter_map/src/geo/crs/crs.dart'; import 'package:flutter_map/src/layer/tile_builder/tile_builder.dart'; import 'package:flutter_map/src/layer/tile_provider/tile_provider.dart'; import 'package:flutter_map/src/map/map.dart'; -import 'package:latlong/latlong.dart'; +import 'package:latlong2/latlong.dart'; import 'package:tuple/tuple.dart'; import 'layer.dart'; @@ -49,14 +49,14 @@ class TileLayerOptions extends LayerOptions { /// Is translated to this: /// /// https://a.tile.openstreetmap.org/12/2177/1259.png - final String urlTemplate; + final String? urlTemplate; /// If `true`, inverses Y axis numbering for tiles (turn this on for /// [TMS](https://en.wikipedia.org/wiki/Tile_Map_Service) services). final bool tms; /// If not `null`, then tiles will pull's WMS protocol requests - final WMSTileLayerOptions wmsOptions; + final WMSTileLayerOptions? wmsOptions; /// Size for the tile. /// Default is 256 @@ -73,12 +73,12 @@ class TileLayerOptions extends LayerOptions { /// Minimum zoom number the tile source has available. If it is specified, the /// tiles on all zoom levels lower than minNativeZoom will be loaded from /// minNativeZoom level and auto-scaled. - final double minNativeZoom; + final double? minNativeZoom; /// Maximum zoom number the tile source has available. If it is specified, the /// tiles on all zoom levels higher than maxNativeZoom will be loaded from /// maxNativeZoom level and auto-scaled. - final double maxNativeZoom; + final double? maxNativeZoom; /// If set to true, the zoom number used in tile URLs will be reversed /// (`maxZoom - zoom` instead of `zoom`) @@ -141,10 +141,10 @@ class TileLayerOptions extends LayerOptions { final int keepBuffer; /// Placeholder to show until tile images are fetched by the provider. - final ImageProvider placeholderImage; + final ImageProvider? placeholderImage; /// Tile image to show in place of the tile that failed to load. - final ImageProvider errorImage; + final ImageProvider? errorImage; /// Static informations that should replace placeholders in the [urlTemplate]. /// Applying API keys is a good example on how to use this parameter. @@ -170,11 +170,11 @@ class TileLayerOptions extends LayerOptions { /// loading tiles every frame when panning / zooming, flutter is fast) This /// can save some fps and even bandwidth (ie. when fast panning / animating /// between long distances in short time) - final Duration updateInterval; + final Duration? updateInterval; /// Tiles fade in duration in milliseconds (default 100). This can be null to /// avoid fade in. - final Duration tileFadeInDuration; + final Duration? tileFadeInDuration; /// Opacity start value when Tile starts fade in (0.0 - 1.0) Takes effect if /// `tileFadeInDuration` is not null @@ -210,17 +210,17 @@ class TileLayerOptions extends LayerOptions { final bool retinaMode; /// This callback will be execute if some errors occur when fetching tiles. - final ErrorTileCallBack errorTileCallback; + final ErrorTileCallBack? errorTileCallback; final TemplateFunction templateFunction; /// Function which may Wrap Tile with custom Widget /// There are predefined examples in 'tile_builder.dart' - final TileBuilder tileBuilder; + final TileBuilder? tileBuilder; /// Function which may wrap Tiles Container with custom Widget /// There are predefined examples in 'tile_builder.dart' - final TilesContainerBuilder tilesContainerBuilder; + final TilesContainerBuilder? tilesContainerBuilder; // If a Tile was loaded with error and if strategy isn't `none` then TileProvider // will be asked to evict Image based on current strategy @@ -228,7 +228,7 @@ class TileLayerOptions extends LayerOptions { final EvictErrorTileStrategy evictErrorTileStrategy; TileLayerOptions({ - Key key, + Key? key, this.urlTemplate, double tileSize = 256.0, double minZoom = 0.0, @@ -237,7 +237,7 @@ class TileLayerOptions extends LayerOptions { this.maxNativeZoom, this.zoomReverse = false, double zoomOffset = 0.0, - Map additionalOptions, + Map? additionalOptions, this.subdomains = const [], this.keepBuffer = 2, this.backgroundColor = const Color(0xFFE0E0E0), @@ -264,7 +264,7 @@ class TileLayerOptions extends LayerOptions { this.overrideTilesWhenUrlChanges = false, this.retinaMode = false, this.errorTileCallback, - Stream rebuild, + Stream? rebuild, this.templateFunction = util.template, this.tileBuilder, this.tilesContainerBuilder, @@ -328,12 +328,12 @@ class WMSTileLayerOptions { /// other request parameters final Map otherParameters; - String _encodedBaseUrl; + late String _encodedBaseUrl; - double _versionNumber; + late double _versionNumber; WMSTileLayerOptions({ - @required this.baseUrl, + required this.baseUrl, this.layers = const [], this.styles = const [], this.format = 'image/png', @@ -366,8 +366,8 @@ class WMSTileLayerOptions { final tileSizePoint = CustomPoint(tileSize, tileSize); final nvPoint = coords.scaleBy(tileSizePoint); final sePoint = nvPoint + tileSizePoint; - final nvCoords = crs.pointToLatLng(nvPoint, coords.z); - final seCoords = crs.pointToLatLng(sePoint, coords.z); + final nvCoords = crs.pointToLatLng(nvPoint, coords.z as double)!; + final seCoords = crs.pointToLatLng(sePoint, coords.z as double)!; final nv = crs.projection.project(nvCoords); final se = crs.projection.project(seCoords); final bounds = Bounds(nv, se); @@ -386,11 +386,11 @@ class WMSTileLayerOptions { class TileLayerWidget extends StatelessWidget { final TileLayerOptions options; - TileLayerWidget({Key key, @required this.options}) : super(key: key); + TileLayerWidget({Key? key, required this.options}) : super(key: key); @override Widget build(BuildContext context) { - final mapState = MapState.of(context); + final mapState = MapState.maybeOf(context)!; return TileLayer( mapState: mapState, @@ -406,9 +406,9 @@ class TileLayer extends StatefulWidget { final Stream stream; TileLayer({ - this.options, - this.mapState, - this.stream, + required this.options, + required this.mapState, + required this.stream, }) : super(key: options.key); @override @@ -421,16 +421,16 @@ class _TileLayerState extends State with TickerProviderStateMixin { MapState get map => widget.mapState; TileLayerOptions get options => widget.options; - Bounds _globalTileRange; - Tuple2 _wrapX; - Tuple2 _wrapY; - double _tileZoom; + late Bounds _globalTileRange; + Tuple2? _wrapX; + Tuple2? _wrapY; + double? _tileZoom; //ignore: unused_field - Level _level; - StreamSubscription _moveSub; - StreamController _throttleUpdate; - CustomPoint _tileSize; + Level? _level; + StreamSubscription? _moveSub; + StreamController? _throttleUpdate; + late CustomPoint _tileSize; final Map _tiles = {}; final Map _levels = {}; @@ -498,8 +498,8 @@ class _TileLayerState extends State with TickerProviderStateMixin { bool _isZoomOutsideMinMax() { for (var tile in _tiles.values) { - if (tile.level.zoom > (options.maxZoom ?? 1.0) || - tile.level.zoom < (options.minZoom ?? 20.0)) { + if (tile.level.zoom > (options.maxZoom) || + tile.level.zoom < (options.minZoom)) { return true; } } @@ -510,10 +510,10 @@ class _TileLayerState extends State with TickerProviderStateMixin { if (options.updateInterval == null) { _throttleUpdate = null; } else { - _throttleUpdate = StreamController(sync: true); - _throttleUpdate.stream + _throttleUpdate = StreamController(sync: true); + _throttleUpdate!.stream .transform( - util.throttleStreamTransformerWithTrailingCall( + util.throttleStreamTransformerWithTrailingCall( options.updateInterval, ), ) @@ -549,7 +549,7 @@ class _TileLayerState extends State with TickerProviderStateMixin { color: options.backgroundColor, child: options.tilesContainerBuilder == null ? tilesContainer - : options.tilesContainerBuilder( + : options.tilesContainerBuilder!( context, tilesContainer, tilesToRender, @@ -563,8 +563,8 @@ class _TileLayerState extends State with TickerProviderStateMixin { var level = tile.level; var tileSize = getTileSize(); var pos = (tilePos).multiplyBy(level.scale) + level.translatePoint; - var width = tileSize.x * level.scale; - var height = tileSize.y * level.scale; + num width = tileSize.x * level.scale; + num height = tileSize.y * level.scale; final Widget content = AnimatedTile( tile: tile, @@ -595,7 +595,7 @@ class _TileLayerState extends State with TickerProviderStateMixin { } for (var key in toRemove) { - var tile = _tiles[key]; + var tile = _tiles[key]!; tile.tileReady = null; tile.dispose(tile.loadError && @@ -618,7 +618,7 @@ class _TileLayerState extends State with TickerProviderStateMixin { return false; } - Level _updateLevels() { + Level? _updateLevels() { var zoom = _tileZoom; var maxZoom = options.maxZoom; @@ -647,8 +647,7 @@ class _TileLayerState extends State with TickerProviderStateMixin { if (level == null) { level = _levels[zoom] = Level(); level.zIndex = maxZoom; - level.origin = map.project(map.unproject(map.getPixelOrigin()), zoom) ?? - CustomPoint(0.0, 0.0); + level.origin = map.project(map.unproject(map.getPixelOrigin()), zoom); level.zoom = zoom; _setZoomTransform(level, map.center, map.zoom); @@ -658,6 +657,7 @@ class _TileLayerState extends State with TickerProviderStateMixin { } void _pruneTiles() { + // TODO this pretty sure isn't necessary anymore if (map == null) { return; } @@ -776,21 +776,20 @@ class _TileLayerState extends State with TickerProviderStateMixin { } double _clampZoom(double zoom) { - if (null != options.minNativeZoom && zoom < options.minNativeZoom) { - return options.minNativeZoom; + if (null != options.minNativeZoom && zoom < options.minNativeZoom!) { + return options.minNativeZoom!; } - if (null != options.maxNativeZoom && options.maxNativeZoom < zoom) { - return options.maxNativeZoom; + if (null != options.maxNativeZoom && options.maxNativeZoom! < zoom) { + return options.maxNativeZoom!; } return zoom; } void _setView(LatLng center, double zoom) { - var tileZoom = _clampZoom(zoom.roundToDouble()); - if ((options.maxZoom != null && tileZoom > options.maxZoom) || - (options.minZoom != null && tileZoom < options.minZoom)) { + double? tileZoom = _clampZoom(zoom.roundToDouble()); + if ((tileZoom > options.maxZoom) || (tileZoom < options.minZoom)) { tileZoom = null; } @@ -810,7 +809,7 @@ class _TileLayerState extends State with TickerProviderStateMixin { void _setZoomTransforms(LatLng center, double zoom) { for (var i in _levels.keys) { - _setZoomTransform(_levels[i], center, zoom); + _setZoomTransform(_levels[i]!, center, zoom); } } @@ -820,7 +819,7 @@ class _TileLayerState extends State with TickerProviderStateMixin { if (level.origin == null) { return; } - var translate = level.origin.multiplyBy(scale) - pixelOrigin; + var translate = level.origin!.multiplyBy(scale) - pixelOrigin; level.translatePoint = translate; level.scale = scale; } @@ -839,23 +838,23 @@ class _TileLayerState extends State with TickerProviderStateMixin { // wrapping _wrapX = crs.wrapLng; if (_wrapX != null) { - var first = - (map.project(LatLng(0.0, crs.wrapLng.item1), tileZoom).x / tileSize.x) - .floorToDouble(); - var second = - (map.project(LatLng(0.0, crs.wrapLng.item2), tileZoom).x / tileSize.y) - .ceilToDouble(); + var first = (map.project(LatLng(0.0, crs.wrapLng!.item1), tileZoom).x / + tileSize.x) + .floorToDouble(); + var second = (map.project(LatLng(0.0, crs.wrapLng!.item2), tileZoom).x / + tileSize.y) + .ceilToDouble(); _wrapX = Tuple2(first, second); } _wrapY = crs.wrapLat; if (_wrapY != null) { - var first = - (map.project(LatLng(crs.wrapLat.item1, 0.0), tileZoom).y / tileSize.x) - .floorToDouble(); - var second = - (map.project(LatLng(crs.wrapLat.item2, 0.0), tileZoom).y / tileSize.y) - .ceilToDouble(); + var first = (map.project(LatLng(crs.wrapLat!.item1, 0.0), tileZoom).y / + tileSize.x) + .floorToDouble(); + var second = (map.project(LatLng(crs.wrapLat!.item2, 0.0), tileZoom).y / + tileSize.y) + .ceilToDouble(); _wrapY = Tuple2(first, second); } } @@ -866,8 +865,7 @@ class _TileLayerState extends State with TickerProviderStateMixin { if (_tileZoom == null) { // if there is no _tileZoom available it means we are out within zoom level // we will restore fully via _setView call if we are back on trail - if ((options.maxZoom != null && tileZoom <= options.maxZoom) && - (options.minZoom != null && tileZoom >= options.minZoom)) { + if ((tileZoom <= options.maxZoom) && (tileZoom >= options.minZoom)) { _tileZoom = tileZoom; setState(() { _setView(map.center, tileZoom); @@ -877,7 +875,7 @@ class _TileLayerState extends State with TickerProviderStateMixin { } } else { setState(() { - if ((tileZoom - _tileZoom).abs() >= 1) { + if ((tileZoom - _tileZoom!).abs() >= 1) { // It was a zoom lvl change _setView(map.center, tileZoom); @@ -886,7 +884,7 @@ class _TileLayerState extends State with TickerProviderStateMixin { if (null == _throttleUpdate) { _update(null); } else { - _throttleUpdate.add(null); + _throttleUpdate!.add(null); } _setZoomTransforms(map.center, map.zoom); @@ -905,7 +903,8 @@ class _TileLayerState extends State with TickerProviderStateMixin { // Private method to load tiles in the grid's active zoom level according to // map bounds - void _update(LatLng center) { + void _update(LatLng? center) { + // TODO can we safely remove the null check for map if (map == null || _tileZoom == null) { return; } @@ -916,7 +915,7 @@ class _TileLayerState extends State with TickerProviderStateMixin { var pixelBounds = _getTiledPixelBounds(center); var tileRange = _pxBoundsToTileRange(pixelBounds); var tileCenter = tileRange.getCenter(); - var queue = >[]; + final queue = >[]; var margin = options.keepBuffer; var noPruneRange = Bounds( tileRange.bottomLeft - CustomPoint(margin, -margin), @@ -935,7 +934,7 @@ class _TileLayerState extends State with TickerProviderStateMixin { // _update just loads more tiles. If the tile zoom level differs too much // from the map's, let _setView reset levels and prune old tiles. - if ((zoom - _tileZoom).abs() > 1) { + if ((zoom - _tileZoom!).abs() > 1) { _setView(center, zoom); return; } @@ -943,8 +942,8 @@ class _TileLayerState extends State with TickerProviderStateMixin { // create a queue of coordinates to load tiles from for (var j = tileRange.min.y; j <= tileRange.max.y; j++) { for (var i = tileRange.min.x; i <= tileRange.max.x; i++) { - var coords = Coords(i.toDouble(), j.toDouble()); - coords.z = _tileZoom; + final coords = Coords(i.toDouble(), j.toDouble()); + coords.z = _tileZoom!; if (!_isValidTile(coords)) { continue; @@ -966,7 +965,7 @@ class _TileLayerState extends State with TickerProviderStateMixin { (a.distanceTo(tileCenter) - b.distanceTo(tileCenter)).toInt()); for (var i = 0; i < queue.length; i++) { - _addTile(queue[i]); + _addTile(queue[i] as Coords); } } @@ -1018,7 +1017,7 @@ class _TileLayerState extends State with TickerProviderStateMixin { coordsKey: tileCoordsToKey, tilePos: _getTilePos(coords), current: true, - level: _levels[coords.z], + level: _levels[coords.z]!, imageProvider: options.tileProvider.getImage(_wrapCoords(coords), options), tileReady: _tileReady, @@ -1040,7 +1039,7 @@ class _TileLayerState extends State with TickerProviderStateMixin { } for (var key in toRemove) { - var tile = _tiles[key]; + var tile = _tiles[key]!; tile.dispose(true); _tiles.remove(key); @@ -1059,7 +1058,7 @@ class _TileLayerState extends State with TickerProviderStateMixin { } for (var key in toRemove) { - var tile = _tiles[key]; + var tile = _tiles[key]!; tile.dispose(true); _tiles.remove(key); @@ -1067,17 +1066,17 @@ class _TileLayerState extends State with TickerProviderStateMixin { } } - void _tileReady(Coords coords, dynamic error, Tile tile) { + void _tileReady(Coords coords, dynamic error, Tile? tile) { if (null != error) { print(error); - tile.loadError = true; + tile!.loadError = true; if (options.errorTileCallback != null) { - options.errorTileCallback(tile, error); + options.errorTileCallback!(tile, error); } } else { - tile.loadError = false; + tile!.loadError = false; } var key = _tileCoordsToKey(coords); @@ -1096,7 +1095,7 @@ class _TileLayerState extends State with TickerProviderStateMixin { tile.active = true; } else { tile.startFadeInAnimation( - options.tileFadeInDuration, + options.tileFadeInDuration!, this, from: fadeInStart, ); @@ -1111,7 +1110,7 @@ class _TileLayerState extends State with TickerProviderStateMixin { // fade-in) to trigger a pruning. Future.delayed( options.tileFadeInDuration != null - ? options.tileFadeInDuration + const Duration(milliseconds: 50) + ? options.tileFadeInDuration! + const Duration(milliseconds: 50) : const Duration(milliseconds: 50), () { if (mounted) { @@ -1123,17 +1122,17 @@ class _TileLayerState extends State with TickerProviderStateMixin { } CustomPoint _getTilePos(Coords coords) { - var level = _levels[coords.z]; - return coords.scaleBy(getTileSize()) - level.origin; + var level = _levels[coords.z as double]!; + return coords.scaleBy(getTileSize()) - level.origin!; } Coords _wrapCoords(Coords coords) { var newCoords = Coords( _wrapX != null - ? util.wrapNum(coords.x.toDouble(), _wrapX) + ? util.wrapNum(coords.x.toDouble(), _wrapX!) : coords.x.toDouble(), _wrapY != null - ? util.wrapNum(coords.y.toDouble(), _wrapY) + ? util.wrapNum(coords.y.toDouble(), _wrapY!) : coords.y.toDouble(), ); newCoords.z = coords.z.toDouble(); @@ -1172,29 +1171,29 @@ class Tile implements Comparable { bool retain; bool active; bool loadError; - DateTime loaded; - DateTime loadStarted; + DateTime? loaded; + late DateTime loadStarted; - AnimationController animationController; + AnimationController? animationController; double get opacity => animationController == null ? (active ? 1.0 : 0.0) - : animationController.value; + : animationController!.value; // callback when tile is ready / error occurred // it maybe be null forinstance when download aborted - TileReady tileReady; - ImageInfo imageInfo; - ImageStream _imageStream; - ImageStreamListener _listener; + TileReady? tileReady; + ImageInfo? imageInfo; + ImageStream? _imageStream; + late ImageStreamListener _listener; Tile({ - this.coordsKey, - this.coords, - this.tilePos, - this.imageProvider, + required this.coordsKey, + required this.coords, + required this.tilePos, + required this.imageProvider, this.tileReady, - this.level, + required this.level, this.current = false, this.active = false, this.retain = false, @@ -1208,11 +1207,11 @@ class Tile implements Comparable { final oldImageStream = _imageStream; _imageStream = imageProvider.resolve(ImageConfiguration()); - if (_imageStream.key != oldImageStream?.key) { + if (_imageStream!.key != oldImageStream?.key) { oldImageStream?.removeListener(_listener); _listener = ImageStreamListener(_tileOnLoad, onError: _tileOnError); - _imageStream.addListener(_listener); + _imageStream!.addListener(_listener); } } catch (e, s) { // make sure all exception is handled - #444 / #536 @@ -1222,8 +1221,9 @@ class Tile implements Comparable { // call this before GC! void dispose([bool evict = false]) { - if (evict && imageProvider != null) { + if (evict) { try { + // ignore: return_type_invalid_for_catch_error imageProvider.evict().catchError(print); } catch (e) { // this may be never called because catchError will handle errors, however @@ -1238,13 +1238,13 @@ class Tile implements Comparable { } void startFadeInAnimation(Duration duration, TickerProvider vsync, - {double from}) { + {double? from}) { animationController?.removeStatusListener(_onAnimateEnd); animationController = AnimationController(duration: duration, vsync: vsync) ..addStatusListener(_onAnimateEnd); - animationController.forward(from: from); + animationController!.forward(from: from); } void _onAnimateEnd(AnimationStatus status) { @@ -1256,13 +1256,13 @@ class Tile implements Comparable { void _tileOnLoad(ImageInfo imageInfo, bool synchronousCall) { if (null != tileReady) { this.imageInfo = imageInfo; - tileReady(coords, null, this); + tileReady!(coords, null, this); } } - void _tileOnError(dynamic exception, StackTrace stackTrace) { + void _tileOnError(dynamic exception, StackTrace? stackTrace) { if (null != tileReady) { - tileReady( + tileReady!( coords, exception ?? 'Unknown exception during loadTileImage', this); } } @@ -1290,16 +1290,15 @@ class Tile implements Comparable { class AnimatedTile extends StatefulWidget { final Tile tile; - final ImageProvider errorImage; - final TileBuilder tileBuilder; + final ImageProvider? errorImage; + final TileBuilder? tileBuilder; AnimatedTile({ - Key key, - @required this.tile, + Key? key, + required this.tile, this.errorImage, - @required this.tileBuilder, - }) : assert(null != tile), - super(key: key); + required this.tileBuilder, + }) : super(key: key); @override _AnimatedTileState createState() => _AnimatedTileState(); @@ -1312,7 +1311,7 @@ class _AnimatedTileState extends State { Widget build(BuildContext context) { final tileWidget = (widget.tile.loadError && widget.errorImage != null) ? Image( - image: widget.errorImage, + image: widget.errorImage!, fit: BoxFit.fill, ) : RawImage( @@ -1324,7 +1323,7 @@ class _AnimatedTileState extends State { opacity: widget.tile.opacity, child: widget.tileBuilder == null ? tileWidget - : widget.tileBuilder(context, tileWidget, widget.tile), + : widget.tileBuilder!(context, tileWidget, widget.tile), ); } @@ -1333,7 +1332,7 @@ class _AnimatedTileState extends State { super.initState(); if (null != widget.tile.animationController) { - widget.tile.animationController.addListener(_handleChange); + widget.tile.animationController!.addListener(_handleChange); listenerAttached = true; } } @@ -1352,7 +1351,7 @@ class _AnimatedTileState extends State { super.didUpdateWidget(oldWidget); if (!listenerAttached && null != widget.tile.animationController) { - widget.tile.animationController.addListener(_handleChange); + widget.tile.animationController!.addListener(_handleChange); listenerAttached = true; } } @@ -1365,15 +1364,15 @@ class _AnimatedTileState extends State { } class Level { - double zIndex; - CustomPoint origin; - double zoom; - CustomPoint translatePoint; - double scale; + late double zIndex; + CustomPoint? origin; + late double zoom; + late CustomPoint translatePoint; + late double scale; } class Coords extends CustomPoint { - T z; + late T z; Coords(T x, T y) : super(x, y); diff --git a/lib/src/layer/tile_provider/tile_provider.dart b/lib/src/layer/tile_provider/tile_provider.dart index 8aa0d4676..62fc0dd1f 100644 --- a/lib/src/layer/tile_provider/tile_provider.dart +++ b/lib/src/layer/tile_provider/tile_provider.dart @@ -13,7 +13,7 @@ abstract class TileProvider { String getTileUrl(Coords coords, TileLayerOptions options) { var urlTemplate = (options.wmsOptions != null) - ? options.wmsOptions + ? options.wmsOptions! .getUrl(coords, options.tileSize.toInt(), options.retinaMode) : options.urlTemplate; @@ -31,7 +31,7 @@ abstract class TileProvider { } var allOpts = Map.from(data) ..addAll(options.additionalOptions); - return options.templateFunction(urlTemplate, allOpts); + return options.templateFunction(urlTemplate!, allOpts); } double _getZoomForUrl(Coords coords, TileLayerOptions options) { @@ -91,7 +91,7 @@ class FileTileProvider extends TileProvider { class CustomTileProvider extends TileProvider { final String Function(Coords coors, TileLayerOptions options) customTileUrl; - const CustomTileProvider({@required this.customTileUrl}); + const CustomTileProvider({required this.customTileUrl}); @override String getTileUrl(Coords coords, TileLayerOptions options) { diff --git a/lib/src/map/flutter_map_state.dart b/lib/src/map/flutter_map_state.dart index 0b5503f80..770c39326 100644 --- a/lib/src/map/flutter_map_state.dart +++ b/lib/src/map/flutter_map_state.dart @@ -19,10 +19,11 @@ class FlutterMapState extends MapGestureMixin { MapOptions get options => widget.options; @override - MapState mapState; + late MapState mapState; - FlutterMapState(MapController mapController) - : mapController = mapController ?? MapController(); + FlutterMapState(MapController? mapController) + : mapController = mapController as MapControllerImpl? ?? + MapController() as MapControllerImpl; @override void didUpdateWidget(FlutterMap oldWidget) { @@ -58,11 +59,11 @@ class FlutterMapState extends MapGestureMixin { } Stream _merge(LayerOptions options) { - if (options?.rebuild == null) return mapState.onMoved; + if (options.rebuild == null) return mapState.onMoved; var group = StreamGroup(); group.add(mapState.onMoved); - group.add(options.rebuild); + group.add(options.rebuild!); groups.add(group); return group.stream; } @@ -98,19 +99,16 @@ class FlutterMapState extends MapGestureMixin { child: Stack( children: [ OverflowBox( - minWidth: size.x, - maxWidth: size.x, - minHeight: size.y, - maxHeight: size.y, + minWidth: size.x as double?, + maxWidth: size.x as double?, + minHeight: size.y as double?, + maxHeight: size.y as double?, child: Transform.rotate( angle: mapState.rotationRad, child: Stack( children: [ - if (widget.children != null && - widget.children.isNotEmpty) - ...widget.children, - if (widget.layers != null && - widget.layers.isNotEmpty) + if (widget.children.isNotEmpty) ...widget.children, + if (widget.layers.isNotEmpty) ...widget.layers.map( (layer) => _createLayer(layer, options.plugins), ) @@ -120,11 +118,9 @@ class FlutterMapState extends MapGestureMixin { ), Stack( children: [ - if (widget.nonRotatedChildren != null && - widget.nonRotatedChildren.isNotEmpty) + if (widget.nonRotatedChildren.isNotEmpty) ...widget.nonRotatedChildren, - if (widget.nonRotatedLayers != null && - widget.nonRotatedLayers.isNotEmpty) + if (widget.nonRotatedLayers.isNotEmpty) ...widget.nonRotatedLayers.map( (layer) => _createLayer(layer, options.plugins), ) @@ -168,10 +164,9 @@ class FlutterMapState extends MapGestureMixin { if (options is OverlayImageLayerOptions) { return OverlayImageLayer(options, mapState, _merge(options)); } - assert(false, """ + throw (StateError(""" Can't find correct layer for $options. Perhaps when you create your FlutterMap you need something like this: - options: new MapOptions(plugins: [MyFlutterMapPlugin()])"""); - return null; + options: new MapOptions(plugins: [MyFlutterMapPlugin()])""")); } } diff --git a/lib/src/map/map.dart b/lib/src/map/map.dart index a9c01bf50..cd7440188 100644 --- a/lib/src/map/map.dart +++ b/lib/src/map/map.dart @@ -7,13 +7,13 @@ import 'package:flutter_map/src/core/bounds.dart'; import 'package:flutter_map/src/core/center_zoom.dart'; import 'package:flutter_map/src/core/point.dart'; import 'package:flutter_map/src/map/map_state_widget.dart'; -import 'package:latlong/latlong.dart'; +import 'package:latlong2/latlong.dart'; class MapControllerImpl implements MapController { final Completer _readyCompleter = Completer(); final StreamController _mapEventSink = StreamController.broadcast(); StreamSink get mapEventSink => _mapEventSink.sink; - MapState _state; + late MapState _state; @override Future get onReady => _readyCompleter.future; @@ -31,13 +31,13 @@ class MapControllerImpl implements MapController { @override MoveAndRotateResult moveAndRotate(LatLng center, double zoom, double degree, - {String id}) { + {String? id}) { return _state.moveAndRotate(center, zoom, degree, - source: MapEventSource.mapController, id: id); + source: MapEventSource.mapController, id: id!); } @override - bool move(LatLng center, double zoom, {String id}) { + bool move(LatLng center, double zoom, {String? id}) { return _state.move(center, zoom, id: id, source: MapEventSource.mapController); } @@ -45,20 +45,21 @@ class MapControllerImpl implements MapController { @override void fitBounds( LatLngBounds bounds, { - FitBoundsOptions options = + FitBoundsOptions? options = const FitBoundsOptions(padding: EdgeInsets.all(12.0)), }) { - _state.fitBounds(bounds, options); + _state.fitBounds(bounds, options!); } @override + // TODO could it happen at all that _state isn't set here? bool get ready => _state != null; @override LatLng get center => _state.center; @override - LatLngBounds get bounds => _state.bounds; + LatLngBounds? get bounds => _state.bounds; @override double get zoom => _state.zoom; @@ -67,7 +68,7 @@ class MapControllerImpl implements MapController { double get rotation => _state.rotation; @override - bool rotate(double degree, {String id}) { + bool rotate(double degree, {String? id}) { return _state.rotate(degree, id: id, source: MapEventSource.mapController); } @@ -95,10 +96,10 @@ class MapState { double get rotationRad => _rotationRad; - LatLng _lastCenter; - LatLngBounds _lastBounds; - Bounds _lastPixelBounds; - CustomPoint _pixelOrigin; + LatLng? _lastCenter; + LatLngBounds? _lastBounds; + Bounds? _lastPixelBounds; + late CustomPoint _pixelOrigin; bool _initialized = false; MapState(this.options, this.onRotationChanged, this._mapEventSink) @@ -110,15 +111,15 @@ class MapState { Stream get onMoved => _onMoveSink.stream; // Original size of the map where rotation isn't calculated - CustomPoint _originalSize; + CustomPoint? _originalSize; - CustomPoint get originalSize => _originalSize; + CustomPoint? get originalSize => _originalSize; void setOriginalSize(double width, double height) { final isCurrSizeNull = _originalSize == null; if (isCurrSizeNull || - _originalSize.x != width || - _originalSize.y != height) { + _originalSize!.x != width || + _originalSize!.y != height) { _originalSize = CustomPoint(width, height); _updateSizeByOriginalSizeAndRotation(); @@ -131,19 +132,21 @@ class MapState { } // Extended size of the map where rotation is calculated - CustomPoint _size; + CustomPoint? _size; CustomPoint get size => _size ?? CustomPoint(0.0, 0.0); void _updateSizeByOriginalSizeAndRotation() { - final originalWidth = _originalSize.x; - final originalHeight = _originalSize.y; + final originalWidth = _originalSize!.x; + final originalHeight = _originalSize!.y; if (_rotation != 0.0) { final cosAngle = math.cos(_rotationRad).abs(); final sinAngle = math.sin(_rotationRad).abs(); - final width = (originalWidth * cosAngle) + (originalHeight * sinAngle); - final height = (originalHeight * cosAngle) + (originalWidth * sinAngle); + final num width = + (originalWidth * cosAngle) + (originalHeight * sinAngle); + final num height = + (originalHeight * cosAngle) + (originalWidth * sinAngle); _size = CustomPoint(width, height); } else { @@ -155,29 +158,29 @@ class MapState { _initialized = true; } - _pixelOrigin = getNewPixelOrigin(_lastCenter); + _pixelOrigin = getNewPixelOrigin(_lastCenter!); } LatLng get center => getCenter() ?? options.center; - LatLngBounds get bounds => getBounds(); + LatLngBounds? get bounds => getBounds(); Bounds get pixelBounds => getLastPixelBounds(); void _init() { if (options.bounds != null) { - fitBounds(options.bounds, options.boundsOptions); + fitBounds(options.bounds!, options.boundsOptions); } else { - move(options.center, zoom); + move(options.center, zoom, source: MapEventSource.initialization); } } void _handleMoveEmit(LatLng targetCenter, double targetZoom, hasGesture, - MapEventSource source, String id) { + MapEventSource source, String? id) { if (source == MapEventSource.flingAnimationController) { emitMapEvent( MapEventFlingAnimation( - center: _lastCenter, + center: _lastCenter!, zoom: _zoom, targetCenter: targetCenter, targetZoom: targetZoom, @@ -187,7 +190,7 @@ class MapState { } else if (source == MapEventSource.doubleTapZoomAnimationController) { emitMapEvent( MapEventDoubleTapZoom( - center: _lastCenter, + center: _lastCenter!, zoom: _zoom, targetCenter: targetCenter, targetZoom: targetZoom, @@ -198,7 +201,7 @@ class MapState { source == MapEventSource.onMultiFinger) { emitMapEvent( MapEventMove( - center: _lastCenter, + center: _lastCenter!, zoom: _zoom, targetCenter: targetCenter, targetZoom: targetZoom, @@ -209,7 +212,7 @@ class MapState { emitMapEvent( MapEventMove( id: id, - center: _lastCenter, + center: _lastCenter!, zoom: _zoom, targetCenter: targetCenter, targetZoom: targetZoom, @@ -236,8 +239,8 @@ class MapState { double degree, { hasGesture = false, callOnMoveSink = true, - MapEventSource source, - String id, + required MapEventSource source, + String? id, }) { if (degree != _rotation) { var oldRotation = _rotation; @@ -251,7 +254,7 @@ class MapState { id: id, currentRotation: oldRotation, targetRotation: _rotation, - center: _lastCenter, + center: _lastCenter!, zoom: _zoom, source: source, ), @@ -268,7 +271,7 @@ class MapState { } MoveAndRotateResult moveAndRotate(LatLng center, double zoom, double degree, - {MapEventSource source, String id}) { + {required MapEventSource source, required String id}) { final moveSucc = move(center, zoom, id: id, source: source, callOnMoveSink: false); final rotateSucc = @@ -284,12 +287,12 @@ class MapState { bool move(LatLng center, double zoom, {hasGesture = false, callOnMoveSink = true, - MapEventSource source, - String id}) { + required MapEventSource source, + String? id}) { zoom = fitZoomToBounds(zoom); final mapMoved = center != _lastCenter || zoom != _zoom; - if (_lastCenter != null && (!mapMoved || !bounds.isValid)) { + if (_lastCenter != null && (!mapMoved || !bounds!.isValid)) { return false; } @@ -315,20 +318,20 @@ class MapState { var mapPosition = MapPosition( center: center, bounds: bounds, zoom: zoom, hasGesture: hasGesture); - options.onPositionChanged(mapPosition, hasGesture); + options.onPositionChanged!(mapPosition, hasGesture); } return true; } - double fitZoomToBounds(double zoom) { + double fitZoomToBounds(double? zoom) { zoom ??= _zoom; // Abide to min/max zoom if (options.maxZoom != null) { - zoom = (zoom > options.maxZoom) ? options.maxZoom : zoom; + zoom = (zoom > options.maxZoom!) ? options.maxZoom! : zoom; } if (options.minZoom != null) { - zoom = (zoom < options.minZoom) ? options.minZoom : zoom; + zoom = (zoom < options.minZoom!) ? options.minZoom! : zoom; } return zoom; } @@ -338,17 +341,17 @@ class MapState { throw Exception('Bounds are not valid.'); } var target = getBoundsCenterZoom(bounds, options); - move(target.center, target.zoom); + move(target.center, target.zoom, source: MapEventSource.fitBounds); } - LatLng getCenter() { + LatLng? getCenter() { if (_lastCenter != null) { return _lastCenter; } return layerPointToLatLng(_centerLayerPoint); } - LatLngBounds getBounds() { + LatLngBounds? getBounds() { if (_lastBounds != null) { return _lastBounds; } @@ -358,7 +361,7 @@ class MapState { Bounds getLastPixelBounds() { if (_lastPixelBounds != null) { - return _lastPixelBounds; + return _lastPixelBounds!; } return getPixelBounds(zoom); @@ -385,8 +388,8 @@ class MapState { zoom = math.min(options.maxZoom, zoom); var paddingOffset = (paddingBR - paddingTL) / 2; - var swPoint = project(bounds.southWest, zoom); - var nePoint = project(bounds.northEast, zoom); + var swPoint = project(bounds.southWest!, zoom); + var nePoint = project(bounds.northEast!, zoom); var center = unproject((swPoint + nePoint) / 2 + paddingOffset, zoom); return CenterZoom( center: center, @@ -396,7 +399,7 @@ class MapState { double getBoundsZoom(LatLngBounds bounds, CustomPoint padding, {bool inside = false}) { - var zoom = this.zoom ?? 0.0; + var zoom = this.zoom; var min = options.minZoom ?? 0.0; var max = options.maxZoom ?? double.infinity; var nw = bounds.northWest; @@ -414,14 +417,14 @@ class MapState { return math.max(min, math.min(max, zoom)); } - CustomPoint project(LatLng latlng, [double zoom]) { + CustomPoint project(LatLng latlng, [double? zoom]) { zoom ??= _zoom; return options.crs.latLngToPoint(latlng, zoom); } - LatLng unproject(CustomPoint point, [double zoom]) { + LatLng unproject(CustomPoint point, [double? zoom]) { zoom ??= _zoom; - return options.crs.pointToLatLng(point, zoom); + return options.crs.pointToLatLng(point, zoom)!; } LatLng layerPointToLatLng(CustomPoint point) { @@ -432,19 +435,19 @@ class MapState { return size / 2; } - double getZoomScale(double toZoom, double fromZoom) { + double getZoomScale(double toZoom, double? fromZoom) { var crs = options.crs; fromZoom = fromZoom ?? _zoom; return crs.scale(toZoom) / crs.scale(fromZoom); } - double getScaleZoom(double scale, double fromZoom) { + double getScaleZoom(double scale, double? fromZoom) { var crs = options.crs; fromZoom = fromZoom ?? _zoom; - return crs.zoom(scale * crs.scale(fromZoom)); + return crs.zoom(scale * crs.scale(fromZoom)) as double; } - Bounds getPixelWorldBounds(double zoom) { + Bounds? getPixelWorldBounds(double? zoom) { return options.crs.getProjectedBounds(zoom ?? _zoom); } @@ -452,7 +455,7 @@ class MapState { return _pixelOrigin; } - CustomPoint getNewPixelOrigin(LatLng center, [double zoom]) { + CustomPoint getNewPixelOrigin(LatLng center, [double? zoom]) { var viewHalf = size / 2.0; return (project(center, zoom) - viewHalf).round(); } @@ -465,9 +468,7 @@ class MapState { return Bounds(pixelCenter - halfSize, pixelCenter + halfSize); } - static MapState of(BuildContext context, {bool nullOk = false}) { - assert(context != null); - assert(nullOk != null); + static MapState? maybeOf(BuildContext context, {bool nullOk = false}) { final widget = context.dependOnInheritedWidgetOfExactType(); if (nullOk || widget != null) { diff --git a/lib/src/map/map_state_widget.dart b/lib/src/map/map_state_widget.dart index 9e97d05ea..661409229 100644 --- a/lib/src/map/map_state_widget.dart +++ b/lib/src/map/map_state_widget.dart @@ -6,9 +6,9 @@ class MapStateInheritedWidget extends InheritedWidget { final MapState mapState; MapStateInheritedWidget({ - Key key, - @required this.mapState, - @required Widget child, + Key? key, + required this.mapState, + required Widget child, }) : super(key: key, child: child); @override @@ -19,7 +19,7 @@ class MapStateInheritedWidget extends InheritedWidget { return true; } - static MapStateInheritedWidget of(BuildContext context) { + static MapStateInheritedWidget? maybeOf(BuildContext context) { return context .dependOnInheritedWidgetOfExactType(); } diff --git a/pubspec.yaml b/pubspec.yaml index 473f541e3..96eede055 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,27 +4,32 @@ version: 0.12.0 repository: https://github.com/johnpryan/flutter_map environment: - sdk: ">=2.7.0 <3.0.0" + sdk: '>=2.12.0 <3.0.0' flutter: ">=2.0.0" dependencies: flutter: sdk: flutter - tuple: ^1.0.2 - latlong: ^0.6.1 + tuple: ^2.0.0 + latlong2: ^0.8.0 positioned_tap_detector_2: ^1.0.0 - transparent_image: ^1.0.0 + transparent_image: ^2.0.0 async: ^2.1.0 - flutter_image: ^3.0.0 - vector_math: ^2.0.0 - proj4dart: ^1.0.4 - meta: ^1.1.0 - collection: ^1.14.0 + flutter_image: any + vector_math: ^2.1.0 + proj4dart: ^2.0.0 + collection: ^1.15.0 dev_dependencies: pedantic: ^1.11.0 - location: ^2.5.0 + location: ^4.1.1 flutter_test: sdk: flutter - test: ^1.9.0 - mockito: ^4.1.4 + test: ^1.16.5 + mockito: ^5.0.2 + +dependency_overrides: + flutter_image: + git: + url: "https://github.com/flutter/flutter_image" + ref: null-safety \ No newline at end of file diff --git a/test/flutter_map_test.dart b/test/flutter_map_test.dart index 81a9d2118..d33a1b292 100644 --- a/test/flutter_map_test.dart +++ b/test/flutter_map_test.dart @@ -4,7 +4,7 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter_map/flutter_map.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:latlong/latlong.dart'; +import 'package:latlong2/latlong.dart'; import 'package:mockito/mockito.dart'; class MockHttpClientResponse extends Mock implements HttpClientResponse { @@ -18,8 +18,8 @@ class MockHttpClientResponse extends Mock implements HttpClientResponse { HttpClientResponseCompressionState.notCompressed; @override - StreamSubscription> listen(void Function(List event) onData, - {Function onError, void Function() onDone, bool cancelOnError}) { + StreamSubscription> listen(void Function(List event)? onData, + {Function? onError, void Function()? onDone, bool? cancelOnError}) { return _stream.listen(onData, onError: onError, onDone: onDone, cancelOnError: cancelOnError); } @@ -42,7 +42,7 @@ class MockClient extends Mock implements HttpClient { class MockHttpOverrides extends HttpOverrides { @override - HttpClient createHttpClient(SecurityContext securityContext) => MockClient(); + HttpClient createHttpClient(SecurityContext? securityContext) => MockClient(); } void main() {