Skip to content

Commit

Permalink
ImageProvider.toString uses double.toStringAsFixed (#131348)
Browse files Browse the repository at this point in the history
This provides consistency for web vs VM (and is more consistent with how we do doubles everywhere else in toStrings).
  • Loading branch information
Hixie authored Aug 2, 2023
1 parent f5f36ec commit 9c471a9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/painting/_network_image_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,5 @@ class NetworkImage extends image_provider.ImageProvider<image_provider.NetworkIm
int get hashCode => Object.hash(url, scale);

@override
String toString() => '${objectRuntimeType(this, 'NetworkImage')}("$url", scale: $scale)';
String toString() => '${objectRuntimeType(this, 'NetworkImage')}("$url", scale: ${scale.toStringAsFixed(1)})';
}
3 changes: 1 addition & 2 deletions packages/flutter/lib/src/painting/_network_image_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,5 @@ class NetworkImage
int get hashCode => Object.hash(url, scale);

@override
String toString() =>
'${objectRuntimeType(this, 'NetworkImage')}("$url", scale: $scale)';
String toString() => '${objectRuntimeType(this, 'NetworkImage')}("$url", scale: ${scale.toStringAsFixed(1)})';
}
6 changes: 3 additions & 3 deletions packages/flutter/lib/src/painting/image_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1618,7 +1618,7 @@ class FileImage extends ImageProvider<FileImage> {
int get hashCode => Object.hash(file.path, scale);

@override
String toString() => '${objectRuntimeType(this, 'FileImage')}("${file.path}", scale: $scale)';
String toString() => '${objectRuntimeType(this, 'FileImage')}("${file.path}", scale: ${scale.toStringAsFixed(1)})';
}

/// Decodes the given [Uint8List] buffer as an image, associating it with the
Expand Down Expand Up @@ -1722,7 +1722,7 @@ class MemoryImage extends ImageProvider<MemoryImage> {
int get hashCode => Object.hash(bytes.hashCode, scale);

@override
String toString() => '${objectRuntimeType(this, 'MemoryImage')}(${describeIdentity(bytes)}, scale: $scale)';
String toString() => '${objectRuntimeType(this, 'MemoryImage')}(${describeIdentity(bytes)}, scale: ${scale.toStringAsFixed(1)})';
}

/// Fetches an image from an [AssetBundle], associating it with the given scale.
Expand Down Expand Up @@ -1863,7 +1863,7 @@ class ExactAssetImage extends AssetBundleImageProvider {
int get hashCode => Object.hash(keyName, scale, bundle);

@override
String toString() => '${objectRuntimeType(this, 'ExactAssetImage')}(name: "$keyName", scale: $scale, bundle: $bundle)';
String toString() => '${objectRuntimeType(this, 'ExactAssetImage')}(name: "$keyName", scale: ${scale.toStringAsFixed(1)}, bundle: $bundle)';
}

// A completer used when resolving an image fails sync.
Expand Down
6 changes: 6 additions & 0 deletions packages/flutter/test/painting/image_provider_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ void main() {
expect(imageCache.statusForKey(provider).untracked, false);
expect(imageCache.pendingImageCount, 1);
}, skip: kIsWeb); // [intended] The web cannot load files.

test('ImageProvider toStrings', () async {
expect(const NetworkImage('test', scale: 1.21).toString(), 'NetworkImage("test", scale: 1.2)');
expect(const ExactAssetImage('test', scale: 1.21).toString(), 'ExactAssetImage(name: "test", scale: 1.2, bundle: null)');
expect(MemoryImage(Uint8List(0), scale: 1.21).toString(), equalsIgnoringHashCodes('MemoryImage(Uint8List#00000, scale: 1.2)'));
});
}

class FakeCodec implements Codec {
Expand Down

0 comments on commit 9c471a9

Please sign in to comment.