From 72786e66e82ef492fbb86a388db4e065d6e3a8e8 Mon Sep 17 00:00:00 2001 From: josxha <34318751+josxha@users.noreply.github.com> Date: Mon, 10 May 2021 12:16:32 +0200 Subject: [PATCH 1/7] use http.RetryClient instead of flutter_image --- .../network_image_with_retry.dart | 48 +++++++++++++++++++ .../layer/tile_provider/tile_provider.dart | 3 +- pubspec.yaml | 10 +--- 3 files changed, 52 insertions(+), 9 deletions(-) create mode 100644 lib/src/layer/tile_provider/network_image_with_retry.dart diff --git a/lib/src/layer/tile_provider/network_image_with_retry.dart b/lib/src/layer/tile_provider/network_image_with_retry.dart new file mode 100644 index 000000000..044088fff --- /dev/null +++ b/lib/src/layer/tile_provider/network_image_with_retry.dart @@ -0,0 +1,48 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter/painting.dart'; +import 'package:http/http.dart'; +import 'package:http/retry.dart'; + +class NetworkImageWithRetry extends ImageProvider { + /// The URL from which the image will be fetched. + final String url; + + /// The scale to place in the [ImageInfo] object of the image. + final double scale; + + /// The http RetryClient that is used for the requests + RetryClient retryClient = RetryClient(Client()); + + NetworkImageWithRetry(this.url, {this.scale = 1.0}); + + @override + ImageStreamCompleter load(NetworkImageWithRetry key, decode) { + return OneFrameImageStreamCompleter( + _loadWithRetry(key, decode), + informationCollector: () sync* { + yield ErrorDescription('Image provider: $this'); + yield ErrorDescription('Image key: $key'); + } + ); + } + + @override + Future obtainKey(ImageConfiguration configuration) { + return SynchronousFuture(this); + } + + Future _loadWithRetry(NetworkImageWithRetry key, DecoderCallback decode) async { + assert(key == this); + + final uri = Uri.parse(url); + final response = await retryClient.get(uri); + + final codec = await decode(response.bodyBytes); + final image = (await codec.getNextFrame()).image; + + return ImageInfo( + image: image, + scale: key.scale, + ); + } +} \ No newline at end of file diff --git a/lib/src/layer/tile_provider/tile_provider.dart b/lib/src/layer/tile_provider/tile_provider.dart index 62fc0dd1f..ab6adfc38 100644 --- a/lib/src/layer/tile_provider/tile_provider.dart +++ b/lib/src/layer/tile_provider/tile_provider.dart @@ -1,9 +1,10 @@ import 'dart:io'; import 'package:flutter/widgets.dart'; -import 'package:flutter_image/network.dart'; import 'package:flutter_map/flutter_map.dart'; +import 'network_image_with_retry.dart'; + abstract class TileProvider { const TileProvider(); diff --git a/pubspec.yaml b/pubspec.yaml index 96eede055..95036ce19 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,7 +15,7 @@ dependencies: positioned_tap_detector_2: ^1.0.0 transparent_image: ^2.0.0 async: ^2.1.0 - flutter_image: any + http: ^0.13.2 vector_math: ^2.1.0 proj4dart: ^2.0.0 collection: ^1.15.0 @@ -26,10 +26,4 @@ dev_dependencies: flutter_test: sdk: flutter 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 + mockito: ^5.0.2 \ No newline at end of file From a1496c517729bd6c893c36e3487c250de27ee6f7 Mon Sep 17 00:00:00 2001 From: josxha <34318751+josxha@users.noreply.github.com> Date: Mon, 10 May 2021 13:07:54 +0200 Subject: [PATCH 2/7] formatting --- lib/src/layer/tile_provider/network_image_with_retry.dart | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/src/layer/tile_provider/network_image_with_retry.dart b/lib/src/layer/tile_provider/network_image_with_retry.dart index 044088fff..134888f4c 100644 --- a/lib/src/layer/tile_provider/network_image_with_retry.dart +++ b/lib/src/layer/tile_provider/network_image_with_retry.dart @@ -11,7 +11,7 @@ class NetworkImageWithRetry extends ImageProvider { final double scale; /// The http RetryClient that is used for the requests - RetryClient retryClient = RetryClient(Client()); + final RetryClient retryClient = RetryClient(Client()); NetworkImageWithRetry(this.url, {this.scale = 1.0}); @@ -36,7 +36,6 @@ class NetworkImageWithRetry extends ImageProvider { final uri = Uri.parse(url); final response = await retryClient.get(uri); - final codec = await decode(response.bodyBytes); final image = (await codec.getNextFrame()).image; From 0c7462f6a3a1f6068d9abd4646e56b840828ca25 Mon Sep 17 00:00:00 2001 From: josxha <34318751+josxha@users.noreply.github.com> Date: Mon, 10 May 2021 15:06:16 +0200 Subject: [PATCH 3/7] add change notes --- CHANGELOG.md | 11 +++++++++++ pubspec.yaml | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ede305da3..dd1b83b10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +## [0.13.0] - x/xx/2021 +This version has support for sound null safety. For this purpose, some inactive packages were exchanged with active forks. + +- Sound null safety migration (#851, #870) + - requires flutter version 2.0.0 or higher + - latlong is replaced with latlong2 +- Remove the package flutter_image and add http instead (#894) + - http has to be version 0.13.2 or higher for this package (#894) + +Thanks to escamoteur, ThexXTURBOXx, Sata51, tazik561, kengu, passsy, Ahmed-gubara, johnpryan and josxha for this release! + ## [0.12.0] - 3/16/2021 TileLayerOptions now takes some additional options, templateFunction, tileBuilder, tilesContainerBuilder, and evictErrorTileStrategy diff --git a/pubspec.yaml b/pubspec.yaml index 95036ce19..025c25904 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_map description: A Dart implementation of Leaflet for Flutter apps -version: 0.12.0 +version: 0.13.0 repository: https://github.com/johnpryan/flutter_map environment: From 910f701fea14509fcc8456705dad2e96f0ec5c8c Mon Sep 17 00:00:00 2001 From: Nico Mexis Date: Wed, 19 May 2021 22:13:12 +0200 Subject: [PATCH 4/7] Update git repo link --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index d6e34a38c..713d59dbc 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: flutter_map description: A Dart implementation of Leaflet for Flutter apps version: 0.13.0 -repository: https://github.com/johnpryan/flutter_map +repository: https://github.com/fleaflet/flutter_map environment: sdk: '>=2.12.0 <3.0.0' From 079daafb28be5435193c2052b67e9dba8454f26a Mon Sep 17 00:00:00 2001 From: Nico Mexis Date: Wed, 19 May 2021 22:13:17 +0200 Subject: [PATCH 5/7] Fix typos --- lib/src/core/bounds.dart | 2 +- lib/src/layer/tile_layer.dart | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/src/core/bounds.dart b/lib/src/core/bounds.dart index 4801b1b8f..fbb204b17 100644 --- a/lib/src/core/bounds.dart +++ b/lib/src/core/bounds.dart @@ -31,7 +31,7 @@ class Bounds { ); } - /// This [Bounds] cental point. + /// This [Bounds] central point. CustomPoint getCenter() { //TODO should this be a getter? return CustomPoint( diff --git a/lib/src/layer/tile_layer.dart b/lib/src/layer/tile_layer.dart index bf11ba77d..34f6061eb 100644 --- a/lib/src/layer/tile_layer.dart +++ b/lib/src/layer/tile_layer.dart @@ -146,7 +146,7 @@ class TileLayerOptions extends LayerOptions { /// Tile image to show in place of the tile that failed to load. final ImageProvider? errorImage; - /// Static informations that should replace placeholders in the [urlTemplate]. + /// Static information that should replace placeholders in the [urlTemplate]. /// Applying API keys is a good example on how to use this parameter. /// /// Example: @@ -333,7 +333,7 @@ class WMSTileLayerOptions { /// Version of the WMS service to use final String version; - /// tile transperency flag + /// tile transparency flag final bool transparent; // TODO find a way to implicit pass of current map [Crs] @@ -1205,7 +1205,7 @@ class Tile implements Comparable { : animationController!.value; // callback when tile is ready / error occurred - // it maybe be null forinstance when download aborted + // it maybe be null for instance when download aborted TileReady? tileReady; ImageInfo? imageInfo; ImageStream? _imageStream; From 918d65b2dff353b2336ec1d3bcf486959d322c1e Mon Sep 17 00:00:00 2001 From: Nico Mexis Date: Wed, 19 May 2021 22:15:40 +0200 Subject: [PATCH 6/7] Sort dependencies --- analysis_options.yaml | 1 + example/pubspec.yaml | 6 +++--- pubspec.yaml | 18 +++++++++--------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index f2a12ab81..202093b55 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -36,6 +36,7 @@ linter: - prefer_null_aware_operators - prefer_single_quotes - prefer_typing_uninitialized_variables + - sort_pub_dependencies - test_types_in_equals - throw_in_finally - unnecessary_brace_in_string_interps diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 1f6fcc7db..78027d9c4 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -21,19 +21,19 @@ environment: sdk: '>=2.12.0 <3.0.0' dependencies: - flutter: - sdk: flutter # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.2 + flutter: + sdk: flutter flutter_map: path: ../ location: ^4.1.1 dev_dependencies: - pedantic: ^1.11.0 flutter_test: sdk: flutter + pedantic: ^1.11.0 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec diff --git a/pubspec.yaml b/pubspec.yaml index 713d59dbc..8ba25da9c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -8,23 +8,23 @@ environment: flutter: ">=2.0.0" dependencies: + async: ^2.1.0 + collection: ^1.15.0 flutter: sdk: flutter - tuple: ^2.0.0 + http: ^0.13.2 intl: ^0.17.0 latlong2: ^0.8.0 positioned_tap_detector_2: ^1.0.0 + proj4dart: ^2.0.0 transparent_image: ^2.0.0 - async: ^2.1.0 - http: ^0.13.2 + tuple: ^2.0.0 vector_math: ^2.1.0 - proj4dart: ^2.0.0 - collection: ^1.15.0 dev_dependencies: - pedantic: ^1.11.0 - location: ^4.1.1 flutter_test: sdk: flutter - test: ^1.16.5 - mockito: ^5.0.2 \ No newline at end of file + location: ^4.1.1 + mockito: ^5.0.2 + pedantic: ^1.11.0 + test: ^1.16.5 \ No newline at end of file From 8c3659127e4ae80ddc54db5e609bcdfa232f0458 Mon Sep 17 00:00:00 2001 From: Nico Mexis Date: Wed, 19 May 2021 22:23:06 +0200 Subject: [PATCH 7/7] Reformat and improve pub score --- README.md | 2 +- lib/src/geo/crs/crs.dart | 2 +- lib/src/gestures/gestures.dart | 12 +++-- lib/src/layer/polyline_layer.dart | 49 ++++++++++++------- .../network_image_with_retry.dart | 17 +++---- 5 files changed, 49 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 3cf88d907..e335ac5a0 100644 --- a/README.md +++ b/README.md @@ -286,6 +286,6 @@ Note that there is also `FileTileProvider()`, which you can use to load tiles fr For the latest roadmap, please see the [Issue Tracker] -[Leaflet]: http://leafletjs.com/ +[Leaflet]: https://leafletjs.com/ [Mapbox]: https://www.mapbox.com/ [Issue Tracker]: https://github.com/johnpryan/flutter_map/issues diff --git a/lib/src/geo/crs/crs.dart b/lib/src/geo/crs/crs.dart index fad20c1be..522701bd7 100644 --- a/lib/src/geo/crs/crs.dart +++ b/lib/src/geo/crs/crs.dart @@ -183,7 +183,7 @@ class Proj4Crs extends Crs { required this.infinite, List? transformations, required List scales, - }) : _transformations = transformations, + }) : _transformations = transformations, _scales = scales; factory Proj4Crs.fromFactory({ diff --git a/lib/src/gestures/gestures.dart b/lib/src/gestures/gestures.dart index 46dcc9d77..308e31196 100644 --- a/lib/src/gestures/gestures.dart +++ b/lib/src/gestures/gestures.dart @@ -2,13 +2,13 @@ import 'dart:async'; import 'dart:math' as math; import 'package:flutter/material.dart'; +import 'package:flutter/physics.dart'; 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:latlong2/latlong.dart'; import 'package:positioned_tap_detector_2/positioned_tap_detector_2.dart'; -import 'package:flutter/physics.dart'; abstract class MapGestureMixin extends State with TickerProviderStateMixin { @@ -162,7 +162,8 @@ abstract class MapGestureMixin extends State } } - int _getMultiFingerGestureFlags({int? gestureWinner, MapOptions? mapOptions}) { + int _getMultiFingerGestureFlags( + {int? gestureWinner, MapOptions? mapOptions}) { gestureWinner ??= _gestureWinner; mapOptions ??= options; @@ -480,9 +481,10 @@ abstract class MapGestureMixin extends State } var direction = details.velocity.pixelsPerSecond / magnitude; - var distance = - (Offset.zero & Size(mapState.originalSize!.x as double, mapState.originalSize!.y as double)) - .shortestSide; + var distance = (Offset.zero & + Size(mapState.originalSize!.x as double, + mapState.originalSize!.y as double)) + .shortestSide; var _flingOffset = _focalStartLocal - _lastFocalLocal; _flingAnimation = Tween( diff --git a/lib/src/layer/polyline_layer.dart b/lib/src/layer/polyline_layer.dart index 981060aa2..5d0127f18 100644 --- a/lib/src/layer/polyline_layer.dart +++ b/lib/src/layer/polyline_layer.dart @@ -50,6 +50,7 @@ class Polyline { class PolylineLayerWidget extends StatelessWidget { final PolylineLayerOptions options; + PolylineLayerWidget({Key? key, required this.options}) : super(key: key); @override @@ -64,7 +65,8 @@ class PolylineLayer extends StatelessWidget { final MapState map; final Stream? stream; - PolylineLayer(this.polylineOpts, this.map, this.stream) : super(key: polylineOpts.key); + PolylineLayer(this.polylineOpts, this.map, this.stream) + : super(key: polylineOpts.key); @override Widget build(BuildContext context) { @@ -85,7 +87,8 @@ class PolylineLayer extends StatelessWidget { for (var polylineOpt in polylineOpts.polylines) { polylineOpt.offsets.clear(); - if (polylineOpts.polylineCulling && !polylineOpt.boundingBox.isOverlapping(map.bounds)) { + if (polylineOpts.polylineCulling && + !polylineOpt.boundingBox.isOverlapping(map.bounds)) { // skip this polyline as it's offscreen continue; } @@ -112,7 +115,8 @@ class PolylineLayer extends StatelessWidget { var point = points[i]; var pos = map.project(point); - pos = pos.multiplyBy(map.getZoomScale(map.zoom, map.zoom)) - map.getPixelOrigin(); + pos = pos.multiplyBy(map.getZoomScale(map.zoom, map.zoom)) - + map.getPixelOrigin(); offsets.add(Offset(pos.x.toDouble(), pos.y.toDouble())); if (i > 0) { offsets.add(Offset(pos.x.toDouble(), pos.y.toDouble())); @@ -142,7 +146,9 @@ class PolylinePainter extends CustomPainter { if (polylineOpt.gradientColors == null) { paint.color = polylineOpt.color; } else { - polylineOpt.gradientColors!.isNotEmpty ? paint.shader = _paintGradient() : paint.color = polylineOpt.color; + polylineOpt.gradientColors!.isNotEmpty + ? paint.shader = _paintGradient() + : paint.color = polylineOpt.color; } Paint? filterPaint; @@ -158,7 +164,8 @@ class PolylinePainter extends CustomPainter { final borderPaint = polylineOpt.borderStrokeWidth > 0.0 ? (Paint() ..color = polylineOpt.borderColor ?? Color(0x00000000) - ..strokeWidth = polylineOpt.strokeWidth + polylineOpt.borderStrokeWidth + ..strokeWidth = + polylineOpt.strokeWidth + polylineOpt.borderStrokeWidth ..strokeCap = StrokeCap.round ..strokeJoin = StrokeJoin.round ..blendMode = BlendMode.srcOver) @@ -169,8 +176,10 @@ class PolylinePainter extends CustomPainter { var spacing = polylineOpt.strokeWidth * 1.5; canvas.saveLayer(rect, Paint()); if (borderPaint != null && filterPaint != null) { - _paintDottedLine(canvas, polylineOpt.offsets, borderRadius, spacing, borderPaint); - _paintDottedLine(canvas, polylineOpt.offsets, radius, spacing, filterPaint); + _paintDottedLine( + canvas, polylineOpt.offsets, borderRadius, spacing, borderPaint); + _paintDottedLine( + canvas, polylineOpt.offsets, radius, spacing, filterPaint); } _paintDottedLine(canvas, polylineOpt.offsets, radius, spacing, paint); canvas.restore(); @@ -188,7 +197,8 @@ class PolylinePainter extends CustomPainter { } } - void _paintDottedLine(Canvas canvas, List offsets, double radius, double stepLength, Paint paint) { + void _paintDottedLine(Canvas canvas, List offsets, double radius, + double stepLength, Paint paint) { final path = ui.Path(); var startDistance = 0.0; for (var i = 0; i < offsets.length - 1; i++) { @@ -203,9 +213,12 @@ class PolylinePainter extends CustomPainter { path.addOval(Rect.fromCircle(center: offset, radius: radius)); distance += stepLength; } - startDistance = distance < totalDistance ? stepLength - (totalDistance - distance) : distance - totalDistance; + startDistance = distance < totalDistance + ? stepLength - (totalDistance - distance) + : distance - totalDistance; } - path.addOval(Rect.fromCircle(center: polylineOpt.offsets.last, radius: radius)); + path.addOval( + Rect.fromCircle(center: polylineOpt.offsets.last, radius: radius)); canvas.drawPath(path, paint); } @@ -219,18 +232,20 @@ class PolylinePainter extends CustomPainter { } } - ui.Gradient _paintGradient() => ui.Gradient.linear( - polylineOpt.offsets.first, polylineOpt.offsets.last, polylineOpt.gradientColors!, _getColorsStop()); + ui.Gradient _paintGradient() => ui.Gradient.linear(polylineOpt.offsets.first, + polylineOpt.offsets.last, polylineOpt.gradientColors!, _getColorsStop()); - List? _getColorsStop() => - (polylineOpt.colorsStop != null && polylineOpt.colorsStop!.length == polylineOpt.gradientColors!.length) - ? polylineOpt.colorsStop - : _calculateColorsStop(); + 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! - .map((gradientColor) => polylineOpt.gradientColors!.indexOf(gradientColor) * colorsStopInterval) + .map((gradientColor) => + polylineOpt.gradientColors!.indexOf(gradientColor) * + colorsStopInterval) .toList(); } diff --git a/lib/src/layer/tile_provider/network_image_with_retry.dart b/lib/src/layer/tile_provider/network_image_with_retry.dart index 134888f4c..9b6094e92 100644 --- a/lib/src/layer/tile_provider/network_image_with_retry.dart +++ b/lib/src/layer/tile_provider/network_image_with_retry.dart @@ -9,7 +9,7 @@ class NetworkImageWithRetry extends ImageProvider { /// The scale to place in the [ImageInfo] object of the image. final double scale; - + /// The http RetryClient that is used for the requests final RetryClient retryClient = RetryClient(Client()); @@ -17,13 +17,11 @@ class NetworkImageWithRetry extends ImageProvider { @override ImageStreamCompleter load(NetworkImageWithRetry key, decode) { - return OneFrameImageStreamCompleter( - _loadWithRetry(key, decode), + return OneFrameImageStreamCompleter(_loadWithRetry(key, decode), informationCollector: () sync* { - yield ErrorDescription('Image provider: $this'); - yield ErrorDescription('Image key: $key'); - } - ); + yield ErrorDescription('Image provider: $this'); + yield ErrorDescription('Image key: $key'); + }); } @override @@ -31,7 +29,8 @@ class NetworkImageWithRetry extends ImageProvider { return SynchronousFuture(this); } - Future _loadWithRetry(NetworkImageWithRetry key, DecoderCallback decode) async { + Future _loadWithRetry( + NetworkImageWithRetry key, DecoderCallback decode) async { assert(key == this); final uri = Uri.parse(url); @@ -44,4 +43,4 @@ class NetworkImageWithRetry extends ImageProvider { scale: key.scale, ); } -} \ No newline at end of file +}