Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Replace the flutter_image package with RetryClient from the http package #894

Merged
merged 13 commits into from May 22, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions 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
Expand Down
47 changes: 47 additions & 0 deletions lib/src/layer/tile_provider/network_image_with_retry.dart
@@ -0,0 +1,47 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/painting.dart';
import 'package:http/http.dart';
import 'package:http/retry.dart';

class NetworkImageWithRetry extends ImageProvider<NetworkImageWithRetry> {
/// 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
final 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<NetworkImageWithRetry> obtainKey(ImageConfiguration configuration) {
return SynchronousFuture<NetworkImageWithRetry>(this);
}

Future<ImageInfo> _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,
);
}
}
3 changes: 2 additions & 1 deletion 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();

Expand Down
12 changes: 3 additions & 9 deletions 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:
Expand All @@ -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
Expand All @@ -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
mockito: ^5.0.2