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 all 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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Expand Up @@ -4,8 +4,10 @@ This version has support for sound null safety. For this purpose, some inactive
- 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 and johnpryan for this release!
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,
Expand Down
46 changes: 46 additions & 0 deletions lib/src/layer/tile_provider/network_image_with_retry.dart
@@ -0,0 +1,46 @@
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
4 changes: 2 additions & 2 deletions pubspec.yaml
Expand Up @@ -12,7 +12,7 @@ dependencies:
collection: ^1.15.0
flutter:
sdk: flutter
flutter_image: ^4.0.1
http: ^0.13.2
intl: ^0.17.0
latlong2: ^0.8.0
positioned_tap_detector_2: ^1.0.0
Expand All @@ -27,4 +27,4 @@ dev_dependencies:
location: ^4.1.1
mockito: ^5.0.2
pedantic: ^1.11.0
test: ^1.16.5
test: ^1.16.5