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 2 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
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
10 changes: 2 additions & 8 deletions pubspec.yaml
Expand Up @@ -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