Unverified Commit 6da6fbf5 authored by Bernardo Ferrari's avatar Bernardo Ferrari Committed by GitHub

Deprecate `describeEnum`. (#125016)

Final part of https://github.com/flutter/flutter/issues/123346.
parent f5ceaf98
......@@ -2262,14 +2262,12 @@ class IterableProperty<T> extends DiagnosticsProperty<Iterable<T>> {
}
}
/// An property than displays enum values tersely.
/// [DiagnosticsProperty] that has an [Enum] as value.
///
/// The enum value is displayed with the class name stripped. For example:
/// The enum value is displayed with the enum name stripped. For example:
/// [HitTestBehavior.deferToChild] is shown as `deferToChild`.
///
/// This class can be used with classes that appear like enums but are not
/// "real" enums, so long as their `toString` implementation, in debug mode,
/// returns a string consisting of the class name followed by the value name. It
/// This class can be used with enums and returns the enum's name getter. It
/// can also be used with nullable properties; the null value is represented as
/// `null`.
///
......@@ -2277,7 +2275,7 @@ class IterableProperty<T> extends DiagnosticsProperty<Iterable<T>> {
///
/// * [DiagnosticsProperty] which documents named parameters common to all
/// [DiagnosticsProperty].
class EnumProperty<T> extends DiagnosticsProperty<T> {
class EnumProperty<T extends Enum?> extends DiagnosticsProperty<T> {
/// Create a diagnostics property that displays an enum.
///
/// The [level] argument must also not be null.
......@@ -2293,7 +2291,7 @@ class EnumProperty<T> extends DiagnosticsProperty<T> {
if (value == null) {
return value.toString();
}
return describeEnum(value!);
return value!.name;
}
}
......@@ -2975,11 +2973,16 @@ String describeIdentity(Object? object) => '${objectRuntimeType(object, '<optimi
///
/// void validateDescribeEnum() {
/// assert(Day.monday.toString() == 'Day.monday');
/// // ignore: deprecated_member_use
/// assert(describeEnum(Day.monday) == 'monday');
/// assert(Day.monday.name == 'monday'); // preferred for real enums
/// }
/// ```
/// {@end-tool}
@Deprecated(
'Use the `name` getter on enums instead. '
'This feature was deprecated after v3.10.0-1.1.pre.'
)
String describeEnum(Object enumEntry) {
if (enumEntry is Enum) {
return enumEntry.name;
......
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