Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #894 from josxha/issues/829-nullsafety
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
Showing
4 changed files
with
53 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters