Deprecate describeEnum
. (#125016)
Final part of https://github.com/flutter/flutter/issues/123346.
This commit is contained in:
parent
f5ceaf9810
commit
6da6fbf5a8
@ -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`.
|
/// [HitTestBehavior.deferToChild] is shown as `deferToChild`.
|
||||||
///
|
///
|
||||||
/// This class can be used with classes that appear like enums but are not
|
/// This class can be used with enums and returns the enum's name getter. It
|
||||||
/// "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
|
|
||||||
/// can also be used with nullable properties; the null value is represented as
|
/// can also be used with nullable properties; the null value is represented as
|
||||||
/// `null`.
|
/// `null`.
|
||||||
///
|
///
|
||||||
@ -2277,7 +2275,7 @@ class IterableProperty<T> extends DiagnosticsProperty<Iterable<T>> {
|
|||||||
///
|
///
|
||||||
/// * [DiagnosticsProperty] which documents named parameters common to all
|
/// * [DiagnosticsProperty] which documents named parameters common to all
|
||||||
/// [DiagnosticsProperty].
|
/// [DiagnosticsProperty].
|
||||||
class EnumProperty<T> extends DiagnosticsProperty<T> {
|
class EnumProperty<T extends Enum?> extends DiagnosticsProperty<T> {
|
||||||
/// Create a diagnostics property that displays an enum.
|
/// Create a diagnostics property that displays an enum.
|
||||||
///
|
///
|
||||||
/// The [level] argument must also not be null.
|
/// The [level] argument must also not be null.
|
||||||
@ -2293,7 +2291,7 @@ class EnumProperty<T> extends DiagnosticsProperty<T> {
|
|||||||
if (value == null) {
|
if (value == null) {
|
||||||
return value.toString();
|
return value.toString();
|
||||||
}
|
}
|
||||||
return describeEnum(value!);
|
return value!.name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2975,11 +2973,16 @@ String describeIdentity(Object? object) => '${objectRuntimeType(object, '<optimi
|
|||||||
///
|
///
|
||||||
/// void validateDescribeEnum() {
|
/// void validateDescribeEnum() {
|
||||||
/// assert(Day.monday.toString() == 'Day.monday');
|
/// assert(Day.monday.toString() == 'Day.monday');
|
||||||
|
/// // ignore: deprecated_member_use
|
||||||
/// assert(describeEnum(Day.monday) == 'monday');
|
/// assert(describeEnum(Day.monday) == 'monday');
|
||||||
/// assert(Day.monday.name == 'monday'); // preferred for real enums
|
/// assert(Day.monday.name == 'monday'); // preferred for real enums
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
/// {@end-tool}
|
/// {@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) {
|
String describeEnum(Object enumEntry) {
|
||||||
if (enumEntry is Enum) {
|
if (enumEntry is Enum) {
|
||||||
return enumEntry.name;
|
return enumEntry.name;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user