Commit 70d3a621 authored by Jacob Richman's avatar Jacob Richman Committed by GitHub

Use defaultTargetPlatform instead of Platform.operatingSystem for ImageProvider. (#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.
parent 86e6ffee
...@@ -16,6 +16,30 @@ String shortHash(Object object) { ...@@ -16,6 +16,30 @@ String shortHash(Object object) {
String describeIdentity(Object object) => String describeIdentity(Object object) =>
'${object.runtimeType}#${shortHash(object)}'; '${object.runtimeType}#${shortHash(object)}';
// This method exists as a workaround for https://github.com/dart-lang/sdk/issues/30021
/// Returns a short description of an enum value.
///
/// Strips off the enum class name from the `enumEntry.toString()`.
///
/// For example:
///
/// ```dart
/// enum Day {
/// monday, tuesday, wednesday, thursday, friday, saturday, sunday
/// }
///
/// main() {
/// assert(Day.monday.toString() == 'Day.monday');
/// assert(describeEnum(Day.monday) == 'monday');
/// }
/// ```
String describeEnum(Object enumEntry) {
final String description = enumEntry.toString();
final int indexOfDot = description.indexOf('.');
assert(indexOfDot != -1 && indexOfDot < description.length - 1);
return description.substring(indexOfDot + 1);
}
/// A mixin that helps dump string representations of trees. /// A mixin that helps dump string representations of trees.
abstract class TreeDiagnosticsMixin { abstract class TreeDiagnosticsMixin {
// This class is intended to be used as a mixin, and should not be // This class is intended to be used as a mixin, and should not be
......
...@@ -73,11 +73,11 @@ class ImageConfiguration { ...@@ -73,11 +73,11 @@ class ImageConfiguration {
/// The size at which the image will be rendered. /// The size at which the image will be rendered.
final Size size; final Size size;
/// A string (same as [Platform.operatingSystem]) that represents the platform /// The [TargetPlatform] for which assets should be used. This allows images
/// for which assets should be used. This allows images to be specified in a /// to be specified in a platform-neutral fashion yet use different assets on
/// platform-neutral fashion yet use different assets on different platforms, /// different platforms, to match local conventions e.g. for color matching or
/// to match local conventions e.g. for color matching or shadows. /// shadows.
final String platform; final TargetPlatform platform;
/// An image configuration that provides no additional information. /// An image configuration that provides no additional information.
/// ///
...@@ -131,7 +131,7 @@ class ImageConfiguration { ...@@ -131,7 +131,7 @@ class ImageConfiguration {
if (platform != null) { if (platform != null) {
if (hasArguments) if (hasArguments)
result.write(', '); result.write(', ');
result.write('platform: $platform'); result.write('platform: ${describeEnum(platform)}');
hasArguments = true; hasArguments = true;
} }
result.write(')'); result.write(')');
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:io' show File, Platform; import 'dart:io' show File;
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
...@@ -40,7 +40,7 @@ ImageConfiguration createLocalImageConfiguration(BuildContext context, { Size si ...@@ -40,7 +40,7 @@ ImageConfiguration createLocalImageConfiguration(BuildContext context, { Size si
devicePixelRatio: MediaQuery.of(context, nullOk: true)?.devicePixelRatio ?? 1.0, devicePixelRatio: MediaQuery.of(context, nullOk: true)?.devicePixelRatio ?? 1.0,
// TODO(ianh): provide the locale // TODO(ianh): provide the locale
size: size, size: size,
platform: Platform.operatingSystem, platform: defaultTargetPlatform,
); );
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment