This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[ios_platform_images] Made ios_platform_images set the correct image scale. #2414
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8f23ecb
Made ios_platform_images set the correct image scale.
gaaclarke 46cc95b
Update packages/ios_platform_images/CHANGELOG.md
gaaclarke 068827c
Update packages/ios_platform_images/CHANGELOG.md
gaaclarke ecf724d
made FutureMemoryImage private
gaaclarke 473988e
Merge branch 'image-scale' of github.com:gaaclarke/plugins into image…
gaaclarke cbb8277
switched version to 0.1.0
gaaclarke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Made ios_platform_images set the correct image scale.
- Loading branch information
commit 8f23ecb7e2b057c7ffc918f20a0bca29186a1da4
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -8,20 +8,54 @@ import 'package:flutter/painting.dart'; | |
| import 'package:flutter/foundation.dart' | ||
| show SynchronousFuture, describeIdentity; | ||
|
|
||
| class _FutureImageStreamCompleter extends ImageStreamCompleter { | ||
| final Future<double> futureScale; | ||
| final InformationCollector informationCollector; | ||
|
|
||
| _FutureImageStreamCompleter( | ||
| {Future<ui.Codec> codec, this.futureScale, this.informationCollector}) | ||
| : assert(codec != null), | ||
| assert(futureScale != null) { | ||
| codec.then<void>(_onCodecReady, onError: (dynamic error, StackTrace stack) { | ||
| reportError( | ||
| context: ErrorDescription('resolving a single-frame image stream'), | ||
| exception: error, | ||
| stack: stack, | ||
| informationCollector: informationCollector, | ||
| silent: true, | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| Future<void> _onCodecReady(ui.Codec codec) async { | ||
| try { | ||
| ui.FrameInfo nextFrame = await codec.getNextFrame(); | ||
| double scale = await futureScale; | ||
| setImage(ImageInfo(image: nextFrame.image, scale: scale)); | ||
| } catch (exception, stack) { | ||
| reportError( | ||
| context: ErrorDescription('resolving an image frame'), | ||
| exception: exception, | ||
| stack: stack, | ||
| informationCollector: this.informationCollector, | ||
| silent: true, | ||
| ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Performs exactly like a [MemoryImage] but instead of taking in bytes it takes | ||
| /// in a future that represents bytes. | ||
| class FutureMemoryImage extends ImageProvider<FutureMemoryImage> { | ||
| /// Constructor for FutureMemoryImage. [_futureBytes] is the bytes that will | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this class is private you probably don't need dartdoc comments here. If you do feel compelled to document
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I already went through the trouble documenting it. I know they aren't required now, but they are still useful. |
||
| /// be loaded into an image and [scale] is the scale that will be applied to | ||
| /// be loaded into an image and [_scale] is the scale that will be applied to | ||
collinjackson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// that image to account for high-resolution images. | ||
| const FutureMemoryImage(this._futureBytes, {this.scale = 1.0}) | ||
| const FutureMemoryImage(this._futureBytes, this._futureScale) | ||
| : assert(_futureBytes != null), | ||
| assert(scale != null); | ||
| assert(_futureScale != null); | ||
|
|
||
| final Future<Uint8List> _futureBytes; | ||
|
|
||
| /// The scale to place in the ImageInfo object of the image. | ||
| final double scale; | ||
| final Future<double> _futureScale; | ||
|
|
||
| /// See [ImageProvider.obtainKey]. | ||
| @override | ||
|
|
@@ -32,9 +66,9 @@ class FutureMemoryImage extends ImageProvider<FutureMemoryImage> { | |
| /// See [ImageProvider.load]. | ||
| @override | ||
| ImageStreamCompleter load(FutureMemoryImage key, DecoderCallback decode) { | ||
| return MultiFrameImageStreamCompleter( | ||
| return _FutureImageStreamCompleter( | ||
| codec: _loadAsync(key, decode), | ||
| scale: key.scale, | ||
| futureScale: _futureScale, | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -51,17 +85,18 @@ class FutureMemoryImage extends ImageProvider<FutureMemoryImage> { | |
| bool operator ==(dynamic other) { | ||
| if (other.runtimeType != runtimeType) return false; | ||
| final FutureMemoryImage typedOther = other; | ||
| return _futureBytes == typedOther._futureBytes && scale == typedOther.scale; | ||
| return _futureBytes == typedOther._futureBytes && | ||
| _futureScale == typedOther._futureScale; | ||
| } | ||
|
|
||
| /// See [ImageProvider.hashCode]. | ||
| @override | ||
| int get hashCode => hashValues(_futureBytes.hashCode, scale); | ||
| int get hashCode => hashValues(_futureBytes.hashCode, _futureScale); | ||
|
|
||
| /// See [ImageProvider.toString]. | ||
| @override | ||
| String toString() => | ||
| '$runtimeType(${describeIdentity(_futureBytes)}, scale: $scale)'; | ||
| '$runtimeType(${describeIdentity(_futureBytes)}, scale: $_futureScale)'; | ||
| } | ||
|
|
||
| /// Class to help loading of iOS platform images into Flutter. | ||
|
|
@@ -78,7 +113,14 @@ class IosPlatformImages { | |
| /// | ||
| /// See [https://developer.apple.com/documentation/uikit/uiimage/1624146-imagenamed?language=objc] | ||
| static FutureMemoryImage load(String name) { | ||
collinjackson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return FutureMemoryImage(_channel.invokeMethod('loadImage', name)); | ||
| Future<Map> loadInfo = _channel.invokeMethod('loadImage', name); | ||
| Completer<Uint8List> bytesCompleter = Completer<Uint8List>(); | ||
| Completer<double> scaleCompleter = Completer<double>(); | ||
| loadInfo.then((map) { | ||
| scaleCompleter.complete(map["scale"]); | ||
| bytesCompleter.complete(map["data"]); | ||
| }); | ||
| return FutureMemoryImage(bytesCompleter.future, scaleCompleter.future); | ||
| } | ||
|
|
||
| /// Resolves an URL for a resource. The equivalent would be: | ||
|
|
||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be 0.1.0 since you're removing a class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.