Skip to content

Commit

Permalink
Merge pull request #894 from josxha/issues/829-nullsafety
Browse files Browse the repository at this point in the history
Replace the flutter_image package with RetryClient from the http package 

* Use http.RetryClient instead of flutter_image
* Formatting
* Add change notes
* Update git repo link
* Fix typos
* Sort dependencies
* Reformat and improve pub score
  • Loading branch information
kengu committed May 22, 2021
2 parents 1882f32 + 252bbc4 commit d9674b5
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
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

0 comments on commit d9674b5

Please sign in to comment.