Skip to content

Commit 1cc7761

Browse files
jacob314gspencergoog
authored andcommitted
Use defaultTargetPlatform instead of Platform.operatingSystem for ImageProvider. (flutter#10986)
* Use defaultTargetPlatform instead of Platform.operatingSystem for ImageProvider. Add convenience helper to make it easier to display a short string for an enums value. * Add comment linking to issue.
1 parent 3b9c881 commit 1cc7761

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

packages/flutter/lib/src/foundation/tree_diagnostics_mixin.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,30 @@ String shortHash(Object object) {
1616
String describeIdentity(Object object) =>
1717
'${object.runtimeType}#${shortHash(object)}';
1818

19+
// This method exists as a workaround for https://github.com/dart-lang/sdk/issues/30021
20+
/// Returns a short description of an enum value.
21+
///
22+
/// Strips off the enum class name from the `enumEntry.toString()`.
23+
///
24+
/// For example:
25+
///
26+
/// ```dart
27+
/// enum Day {
28+
/// monday, tuesday, wednesday, thursday, friday, saturday, sunday
29+
/// }
30+
///
31+
/// main() {
32+
/// assert(Day.monday.toString() == 'Day.monday');
33+
/// assert(describeEnum(Day.monday) == 'monday');
34+
/// }
35+
/// ```
36+
String describeEnum(Object enumEntry) {
37+
final String description = enumEntry.toString();
38+
final int indexOfDot = description.indexOf('.');
39+
assert(indexOfDot != -1 && indexOfDot < description.length - 1);
40+
return description.substring(indexOfDot + 1);
41+
}
42+
1943
/// A mixin that helps dump string representations of trees.
2044
abstract class TreeDiagnosticsMixin {
2145
// This class is intended to be used as a mixin, and should not be

packages/flutter/lib/src/services/image_provider.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ class ImageConfiguration {
7373
/// The size at which the image will be rendered.
7474
final Size size;
7575

76-
/// A string (same as [Platform.operatingSystem]) that represents the platform
77-
/// for which assets should be used. This allows images to be specified in a
78-
/// platform-neutral fashion yet use different assets on different platforms,
79-
/// to match local conventions e.g. for color matching or shadows.
80-
final String platform;
76+
/// The [TargetPlatform] for which assets should be used. This allows images
77+
/// to be specified in a platform-neutral fashion yet use different assets on
78+
/// different platforms, to match local conventions e.g. for color matching or
79+
/// shadows.
80+
final TargetPlatform platform;
8181

8282
/// An image configuration that provides no additional information.
8383
///
@@ -131,7 +131,7 @@ class ImageConfiguration {
131131
if (platform != null) {
132132
if (hasArguments)
133133
result.write(', ');
134-
result.write('platform: $platform');
134+
result.write('platform: ${describeEnum(platform)}');
135135
hasArguments = true;
136136
}
137137
result.write(')');

packages/flutter/lib/src/widgets/image.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import 'dart:io' show File, Platform;
5+
import 'dart:io' show File;
66
import 'dart:typed_data';
77

88
import 'package:flutter/foundation.dart';
@@ -40,7 +40,7 @@ ImageConfiguration createLocalImageConfiguration(BuildContext context, { Size si
4040
devicePixelRatio: MediaQuery.of(context, nullOk: true)?.devicePixelRatio ?? 1.0,
4141
// TODO(ianh): provide the locale
4242
size: size,
43-
platform: Platform.operatingSystem,
43+
platform: defaultTargetPlatform,
4444
);
4545
}
4646

0 commit comments

Comments
 (0)