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

Pass the PictureConfiguration to obtainKey #118

Merged
merged 1 commit into from
Feb 21, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/src/picture_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ abstract class PictureProvider<T> {
// assert(picture != null);
final PictureStream stream = PictureStream();
T obtainedKey;
obtainKey().then<void>((T key) {
obtainKey(picture).then<void>((T key) {
obtainedKey = key;
stream.setCompleter(_cache.putIfAbsent(key, () => load(key)));
}).catchError((dynamic exception, StackTrace stack) async {
Expand Down Expand Up @@ -332,7 +332,7 @@ abstract class PictureProvider<T> {
/// '==' to each other (possibly by using a class for the key that itself
/// implements [==]).
@protected
Future<T> obtainKey();
Future<T> obtainKey(PictureConfiguration picture);

/// Converts a key into an [PictureStreamCompleter], and begins fetching the
/// picture.
Expand Down Expand Up @@ -457,7 +457,7 @@ class NetworkPicture extends PictureProvider<NetworkPicture> {
final ColorFilter colorFilter;

@override
Future<NetworkPicture> obtainKey() {
Future<NetworkPicture> obtainKey(PictureConfiguration picture) {
return SynchronousFuture<NetworkPicture>(this);
}

Expand Down Expand Up @@ -518,7 +518,7 @@ class FilePicture extends PictureProvider<FilePicture> {
final ColorFilter colorFilter;

@override
Future<FilePicture> obtainKey() {
Future<FilePicture> obtainKey(PictureConfiguration picture) {
return SynchronousFuture<FilePicture>(this);
}

Expand Down Expand Up @@ -588,7 +588,7 @@ class MemoryPicture extends PictureProvider<MemoryPicture> {
final Uint8List bytes;

@override
Future<MemoryPicture> obtainKey() {
Future<MemoryPicture> obtainKey(PictureConfiguration picture) {
return SynchronousFuture<MemoryPicture>(this);
}

Expand Down Expand Up @@ -647,7 +647,7 @@ class StringPicture extends PictureProvider<StringPicture> {
final String string;

@override
Future<StringPicture> obtainKey() {
Future<StringPicture> obtainKey(PictureConfiguration picture) {
return SynchronousFuture<StringPicture>(this);
}

Expand Down Expand Up @@ -794,10 +794,10 @@ class ExactAssetPicture extends AssetBundlePictureProvider {
final String package;

@override
Future<AssetBundlePictureKey> obtainKey() {
Future<AssetBundlePictureKey> obtainKey(PictureConfiguration picture) {
return SynchronousFuture<AssetBundlePictureKey>(
AssetBundlePictureKey(
bundle: bundle ?? rootBundle,
bundle: bundle ?? picture.bundle ?? rootBundle,
name: keyName,
colorFilter: colorFilter,
),
Expand Down
26 changes: 26 additions & 0 deletions test/widget_svg_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,32 @@ void main() {
await _checkWidgetAndGolden(key, 'flutter_logo.asset.png');
});

testWidgets('SvgPicture.asset DefaultAssetBundle',
(WidgetTester tester) async {
final MockAssetBundle mockAsset = MockAssetBundle();
when(mockAsset.loadString('test.svg'))
.thenAnswer((_) => Future<String>.value(svgStr));

final GlobalKey key = GlobalKey();
await tester.pumpWidget(
MediaQuery(
data: MediaQueryData.fromWindow(window),
child: DefaultAssetBundle(
bundle: mockAsset,
child: RepaintBoundary(
key: key,
child: SvgPicture.asset(
'test.svg',
semanticsLabel: 'Test SVG',
),
),
),
),
);
await tester.pumpAndSettle();
await _checkWidgetAndGolden(key, 'flutter_logo.asset.png');
});

final MockHttpClient mockHttpClient = MockHttpClient();
final MockHttpClientRequest mockRequest = MockHttpClientRequest();
final MockHttpClientResponse mockResponse = MockHttpClientResponse();
Expand Down