Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
5ddc00cc
Unverified
Commit
5ddc00cc
authored
Dec 04, 2021
by
Ian Hickson
Committed by
GitHub
Dec 04, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use `EnumName.name` where possible. (#94496)
parent
c567f843
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
50 additions
and
33 deletions
+50
-33
focus_node.unfocus.0.dart
...s/api/lib/widgets/focus_manager/focus_node.unfocus.0.dart
+1
-1
diagnostics.dart
packages/flutter/lib/src/foundation/diagnostics.dart
+21
-4
image_provider.dart
packages/flutter/lib/src/painting/image_provider.dart
+1
-1
text_style.dart
packages/flutter/lib/src/painting/text_style.dart
+1
-1
media_query.dart
packages/flutter/lib/src/widgets/media_query.dart
+1
-1
text_field_test.dart
packages/flutter/test/cupertino/text_field_test.dart
+1
-1
diagnostics_test.dart
packages/flutter/test/foundation/diagnostics_test.dart
+2
-2
app_bar_test.dart
packages/flutter/test/material/app_bar_test.dart
+5
-5
slider_test.dart
packages/flutter/test/material/slider_test.dart
+4
-4
switch_list_tile_test.dart
packages/flutter/test/material/switch_list_tile_test.dart
+4
-4
switch_test.dart
packages/flutter/test/material/switch_test.dart
+6
-6
text_field_test.dart
packages/flutter/test/material/text_field_test.dart
+1
-1
editable_text_test.dart
packages/flutter/test/widgets/editable_text_test.dart
+1
-1
semantics_tester.dart
packages/flutter/test/widgets/semantics_tester.dart
+1
-1
No files found.
examples/api/lib/widgets/focus_manager/focus_node.unfocus.0.dart
View file @
5ddc00cc
...
...
@@ -74,7 +74,7 @@ class _MyStatefulWidgetState extends State<MyStatefulWidget> {
},
value:
UnfocusDisposition
.
values
[
index
],
),
Text
(
describeEnum
(
UnfocusDisposition
.
values
[
index
])
),
Text
(
UnfocusDisposition
.
values
[
index
].
name
),
],
);
}),
...
...
packages/flutter/lib/src/foundation/diagnostics.dart
View file @
5ddc00cc
...
...
@@ -1568,13 +1568,13 @@ abstract class DiagnosticsNode {
if
(!
showSeparator
)
'showSeparator'
:
showSeparator
,
if
(
level
!=
DiagnosticLevel
.
info
)
'level'
:
describeEnum
(
level
)
,
'level'
:
level
.
name
,
if
(
showName
==
false
)
'showName'
:
showName
,
if
(
emptyBodyDescription
!=
null
)
'emptyBodyDescription'
:
emptyBodyDescription
,
if
(
style
!=
DiagnosticsTreeStyle
.
sparse
)
'style'
:
describeEnum
(
style
!)
,
'style'
:
style
!.
name
,
if
(
allowTruncate
)
'allowTruncate'
:
allowTruncate
,
if
(
hasChildren
)
...
...
@@ -2303,6 +2303,12 @@ class IterableProperty<T> extends DiagnosticsProperty<Iterable<T>> {
/// The enum value is displayed with the class 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
/// can also be used with nullable properties; the null value is represented as
/// `null`.
///
/// See also:
///
/// * [DiagnosticsProperty] which documents named parameters common to all
...
...
@@ -2702,7 +2708,7 @@ class DiagnosticsProperty<T> extends DiagnosticsNode {
if
(
exception
!=
null
)
json
[
'exception'
]
=
exception
.
toString
();
json
[
'propertyType'
]
=
propertyType
.
toString
();
json
[
'defaultLevel'
]
=
describeEnum
(
_defaultLevel
)
;
json
[
'defaultLevel'
]
=
_defaultLevel
.
name
;
if
(
value
is
Diagnosticable
||
value
is
DiagnosticsNode
)
json
[
'isDiagnosticableValue'
]
=
true
;
if
(
v
is
num
)
...
...
@@ -3016,11 +3022,19 @@ String shortHash(Object? object) {
/// * [Object.runtimeType], the [Type] of an object.
String
describeIdentity
(
Object
?
object
)
=>
'
${objectRuntimeType(object, '<optimized out>')}
#
${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 real enums, this is redundant with calling the `name` getter on the enum
/// value (see [EnumName.name]), a feature that was added to Dart 2.15.
///
/// This function can also be used with classes whose `toString` return a value
/// in the same form as an enum (the class name, a dot, then the value name).
/// For example, it's used with [SemanticsAction], which is written to appear to
/// be an enum but is actually a bespoke class so that the index values can be
/// set as powers of two instead of as sequential integers.
///
/// {@tool snippet}
///
/// ```dart
...
...
@@ -3031,10 +3045,13 @@ String describeIdentity(Object? object) => '${objectRuntimeType(object, '<optimi
/// void validateDescribeEnum() {
/// assert(Day.monday.toString() == 'Day.monday');
/// assert(describeEnum(Day.monday) == 'monday');
/// assert(Day.monday.name == 'monday'); // preferred for real enums
/// }
/// ```
/// {@end-tool}
String
describeEnum
(
Object
enumEntry
)
{
if
(
enumEntry
is
Enum
)
return
enumEntry
.
name
;
final
String
description
=
enumEntry
.
toString
();
final
int
indexOfDot
=
description
.
indexOf
(
'.'
);
assert
(
...
...
packages/flutter/lib/src/painting/image_provider.dart
View file @
5ddc00cc
...
...
@@ -148,7 +148,7 @@ class ImageConfiguration {
if
(
platform
!=
null
)
{
if
(
hasArguments
)
result
.
write
(
', '
);
result
.
write
(
'platform:
${
describeEnum(platform!)
}
'
);
result
.
write
(
'platform:
${
platform!.name
}
'
);
hasArguments
=
true
;
}
result
.
write
(
')'
);
...
...
packages/flutter/lib/src/painting/text_style.dart
View file @
5ddc00cc
...
...
@@ -1378,7 +1378,7 @@ class TextStyle with Diagnosticable {
if
(
decoration
!=
null
||
decorationColor
!=
null
||
decorationStyle
!=
null
||
decorationThickness
!=
null
)
{
final
List
<
String
>
decorationDescription
=
<
String
>[];
if
(
decorationStyle
!=
null
)
decorationDescription
.
add
(
de
scribeEnum
(
decorationStyle
!)
);
decorationDescription
.
add
(
de
corationStyle
!.
name
);
// Hide decorationColor from the default text view as it is shown in the
// terse decoration summary as well.
...
...
packages/flutter/lib/src/widgets/media_query.dart
View file @
5ddc00cc
...
...
@@ -605,7 +605,7 @@ class MediaQueryData {
'disableAnimations:
$disableAnimations
'
,
'invertColors:
$invertColors
'
,
'boldText:
$boldText
'
,
'navigationMode:
${
describeEnum(navigationMode)
}
'
,
'navigationMode:
${
navigationMode.name
}
'
,
'gestureSettings:
$gestureSettings
'
,
];
return
'
${objectRuntimeType(this, 'MediaQueryData')}
(
${properties.join(', ')}
)'
;
...
...
packages/flutter/test/cupertino/text_field_test.dart
View file @
5ddc00cc
...
...
@@ -717,7 +717,7 @@ void main() {
await
expectLater
(
find
.
byKey
(
const
ValueKey
<
int
>(
1
)),
matchesGoldenFile
(
'text_field_cursor_test.cupertino_
${de
scribeEnum(debugDefaultTargetPlatformOverride!)
.toLowerCase()}
.1.png'
,
'text_field_cursor_test.cupertino_
${de
bugDefaultTargetPlatformOverride!.name
.toLowerCase()}
.1.png'
,
),
);
},
variant:
const
TargetPlatformVariant
(<
TargetPlatform
>{
TargetPlatform
.
iOS
,
TargetPlatform
.
macOS
}));
...
...
packages/flutter/test/foundation/diagnostics_test.dart
View file @
5ddc00cc
...
...
@@ -59,10 +59,10 @@ void validateNodeJsonSerializationHelper(Map<String, Object?> json, DiagnosticsN
expect
(
json
[
'name'
],
equals
(
node
.
name
));
expect
(
json
[
'showSeparator'
]
??
true
,
equals
(
node
.
showSeparator
));
expect
(
json
[
'description'
],
equals
(
node
.
toDescription
()));
expect
(
json
[
'level'
]
??
describeEnum
(
DiagnosticLevel
.
info
),
equals
(
describeEnum
(
node
.
level
)
));
expect
(
json
[
'level'
]
??
DiagnosticLevel
.
info
.
name
,
equals
(
node
.
level
.
name
));
expect
(
json
[
'showName'
]
??
true
,
equals
(
node
.
showName
));
expect
(
json
[
'emptyBodyDescription'
],
equals
(
node
.
emptyBodyDescription
));
expect
(
json
[
'style'
]
??
describeEnum
(
DiagnosticsTreeStyle
.
sparse
),
equals
(
describeEnum
(
node
.
style
!)
));
expect
(
json
[
'style'
]
??
DiagnosticsTreeStyle
.
sparse
.
name
,
equals
(
node
.
style
!.
name
));
expect
(
json
[
'type'
],
equals
(
node
.
runtimeType
.
toString
()));
expect
(
json
[
'hasChildren'
]
??
false
,
equals
(
node
.
getChildren
().
isNotEmpty
));
}
...
...
packages/flutter/test/material/app_bar_test.dart
View file @
5ddc00cc
...
...
@@ -100,8 +100,8 @@ void main() {
center
=
tester
.
getCenter
(
title
);
size
=
tester
.
getSize
(
title
);
expect
(
center
.
dx
,
greaterThan
(
400
-
size
.
width
/
2.0
),
reason:
'on
${
describeEnum(platform)
}
'
);
expect
(
center
.
dx
,
lessThan
(
400
+
size
.
width
/
2.0
),
reason:
'on
${
describeEnum(platform)
}
'
);
expect
(
center
.
dx
,
greaterThan
(
400
-
size
.
width
/
2.0
),
reason:
'on
${
platform.name
}
'
);
expect
(
center
.
dx
,
lessThan
(
400
+
size
.
width
/
2.0
),
reason:
'on
${
platform.name
}
'
);
// One action is still centered.
...
...
@@ -121,8 +121,8 @@ void main() {
center
=
tester
.
getCenter
(
title
);
size
=
tester
.
getSize
(
title
);
expect
(
center
.
dx
,
greaterThan
(
400
-
size
.
width
/
2.0
),
reason:
'on
${
describeEnum(platform)
}
'
);
expect
(
center
.
dx
,
lessThan
(
400
+
size
.
width
/
2.0
),
reason:
'on
${
describeEnum(platform)
}
'
);
expect
(
center
.
dx
,
greaterThan
(
400
-
size
.
width
/
2.0
),
reason:
'on
${
platform.name
}
'
);
expect
(
center
.
dx
,
lessThan
(
400
+
size
.
width
/
2.0
),
reason:
'on
${
platform.name
}
'
);
// Two actions is left aligned again.
...
...
@@ -143,7 +143,7 @@ void main() {
center
=
tester
.
getCenter
(
title
);
size
=
tester
.
getSize
(
title
);
expect
(
center
.
dx
,
lessThan
(
400
-
size
.
width
/
2.0
),
reason:
'on
${
describeEnum(platform)
}
'
);
expect
(
center
.
dx
,
lessThan
(
400
-
size
.
width
/
2.0
),
reason:
'on
${
platform.name
}
'
);
}
});
...
...
packages/flutter/test/material/slider_test.dart
View file @
5ddc00cc
...
...
@@ -2138,11 +2138,11 @@ void main() {
expect
(
find
.
byType
(
Slider
),
findsOneWidget
);
expect
(
find
.
byType
(
CupertinoSlider
),
findsOneWidget
);
expect
(
value
,
0.5
,
reason:
'on
${
describeEnum(platform)
}
'
);
expect
(
value
,
0.5
,
reason:
'on
${
platform.name
}
'
);
final
TestGesture
gesture
=
await
tester
.
startGesture
(
tester
.
getCenter
(
find
.
byType
(
CupertinoSlider
)));
// Drag to the right end of the track.
await
gesture
.
moveBy
(
const
Offset
(
600.0
,
0.0
));
expect
(
value
,
1.0
,
reason:
'on
${
describeEnum(platform)
}
'
);
expect
(
value
,
1.0
,
reason:
'on
${
platform.name
}
'
);
await
gesture
.
up
();
}
...
...
@@ -2153,11 +2153,11 @@ void main() {
expect
(
find
.
byType
(
Slider
),
findsOneWidget
);
expect
(
find
.
byType
(
CupertinoSlider
),
findsNothing
);
expect
(
value
,
0.5
,
reason:
'on
${
describeEnum(platform)
}
'
);
expect
(
value
,
0.5
,
reason:
'on
${
platform.name
}
'
);
final
TestGesture
gesture
=
await
tester
.
startGesture
(
tester
.
getCenter
(
find
.
byType
(
Slider
)));
// Drag to the right end of the track.
await
gesture
.
moveBy
(
const
Offset
(
600.0
,
0.0
));
expect
(
value
,
1.0
,
reason:
'on
${
describeEnum(platform)
}
'
);
expect
(
value
,
1.0
,
reason:
'on
${
platform.name
}
'
);
await
gesture
.
up
();
}
});
...
...
packages/flutter/test/material/switch_list_tile_test.dart
View file @
5ddc00cc
...
...
@@ -198,10 +198,10 @@ void main() {
value
=
false
;
await
tester
.
pumpWidget
(
buildFrame
(
platform
));
expect
(
find
.
byType
(
CupertinoSwitch
),
findsOneWidget
);
expect
(
value
,
isFalse
,
reason:
'on
${
describeEnum(platform)
}
'
);
expect
(
value
,
isFalse
,
reason:
'on
${
platform.name
}
'
);
await
tester
.
tap
(
find
.
byType
(
SwitchListTile
));
expect
(
value
,
isTrue
,
reason:
'on
${
describeEnum(platform)
}
'
);
expect
(
value
,
isTrue
,
reason:
'on
${
platform.name
}
'
);
}
for
(
final
TargetPlatform
platform
in
<
TargetPlatform
>[
TargetPlatform
.
android
,
TargetPlatform
.
fuchsia
,
TargetPlatform
.
linux
,
TargetPlatform
.
windows
])
{
...
...
@@ -210,9 +210,9 @@ void main() {
await
tester
.
pumpAndSettle
();
// Finish the theme change animation.
expect
(
find
.
byType
(
CupertinoSwitch
),
findsNothing
);
expect
(
value
,
isFalse
,
reason:
'on
${
describeEnum(platform)
}
'
);
expect
(
value
,
isFalse
,
reason:
'on
${
platform.name
}
'
);
await
tester
.
tap
(
find
.
byType
(
SwitchListTile
));
expect
(
value
,
isTrue
,
reason:
'on
${
describeEnum(platform)
}
'
);
expect
(
value
,
isTrue
,
reason:
'on
${
platform.name
}
'
);
}
});
...
...
packages/flutter/test/material/switch_test.dart
View file @
5ddc00cc
...
...
@@ -752,14 +752,14 @@ void main() {
for
(
final
TargetPlatform
platform
in
<
TargetPlatform
>[
TargetPlatform
.
iOS
,
TargetPlatform
.
macOS
])
{
value
=
false
;
await
tester
.
pumpWidget
(
buildFrame
(
platform
));
expect
(
find
.
byType
(
CupertinoSwitch
),
findsOneWidget
,
reason:
'on
${
describeEnum(platform)
}
'
);
expect
(
find
.
byType
(
CupertinoSwitch
),
findsOneWidget
,
reason:
'on
${
platform.name
}
'
);
final
CupertinoSwitch
adaptiveSwitch
=
tester
.
widget
(
find
.
byType
(
CupertinoSwitch
));
expect
(
adaptiveSwitch
.
trackColor
,
inactiveTrackColor
,
reason:
'on
${
describeEnum(platform)
}
'
);
expect
(
adaptiveSwitch
.
trackColor
,
inactiveTrackColor
,
reason:
'on
${
platform.name
}
'
);
expect
(
value
,
isFalse
,
reason:
'on
${
describeEnum(platform)
}
'
);
expect
(
value
,
isFalse
,
reason:
'on
${
platform.name
}
'
);
await
tester
.
tap
(
find
.
byType
(
Switch
));
expect
(
value
,
isTrue
,
reason:
'on
${
describeEnum(platform)
}
'
);
expect
(
value
,
isTrue
,
reason:
'on
${
platform.name
}
'
);
}
for
(
final
TargetPlatform
platform
in
<
TargetPlatform
>[
TargetPlatform
.
android
,
TargetPlatform
.
fuchsia
,
TargetPlatform
.
linux
,
TargetPlatform
.
windows
])
{
...
...
@@ -767,9 +767,9 @@ void main() {
await
tester
.
pumpWidget
(
buildFrame
(
platform
));
await
tester
.
pumpAndSettle
();
// Finish the theme change animation.
expect
(
find
.
byType
(
CupertinoSwitch
),
findsNothing
);
expect
(
value
,
isFalse
,
reason:
'on
${
describeEnum(platform)
}
'
);
expect
(
value
,
isFalse
,
reason:
'on
${
platform.name
}
'
);
await
tester
.
tap
(
find
.
byType
(
Switch
));
expect
(
value
,
isTrue
,
reason:
'on
${
describeEnum(platform)
}
'
);
expect
(
value
,
isTrue
,
reason:
'on
${
platform.name
}
'
);
}
});
...
...
packages/flutter/test/material/text_field_test.dart
View file @
5ddc00cc
...
...
@@ -641,7 +641,7 @@ void main() {
await
expectLater
(
find
.
byKey
(
const
ValueKey
<
int
>(
1
)),
matchesGoldenFile
(
'text_field_cursor_test_
${de
scribeEnum(debugDefaultTargetPlatformOverride!)
.toLowerCase()}
.material.1.png'
,
'text_field_cursor_test_
${de
bugDefaultTargetPlatformOverride!.name
.toLowerCase()}
.material.1.png'
,
),
);
},
variant:
const
TargetPlatformVariant
(<
TargetPlatform
>{
TargetPlatform
.
iOS
,
TargetPlatform
.
macOS
}));
...
...
packages/flutter/test/widgets/editable_text_test.dart
View file @
5ddc00cc
...
...
@@ -5054,7 +5054,7 @@ void main() {
testWidgets
(
'keyboard shortcuts respect read-only'
,
(
WidgetTester
tester
)
async
{
final
String
platform
=
de
scribeEnum
(
defaultTargetPlatform
)
.
toLowerCase
();
final
String
platform
=
de
faultTargetPlatform
.
name
.
toLowerCase
();
final
TextEditingController
controller
=
TextEditingController
(
text:
testText
);
controller
.
selection
=
const
TextSelection
(
baseOffset:
0
,
...
...
packages/flutter/test/widgets/semantics_tester.dart
View file @
5ddc00cc
...
...
@@ -823,7 +823,7 @@ class _IncludesNodeWith extends Matcher {
if (label != null) 'label "
$label
"',
if (value != null) 'value "
$value
"',
if (hint != null) 'hint "
$hint
"',
if (textDirection != null) ' (
${
describeEnum(textDirection!)
}
)',
if (textDirection != null) ' (
${
textDirection!.name
}
)',
if (actions != null) 'actions "
$
{
actions
!.
join
(
', '
)}
"',
if (flags != null) 'flags "
$
{
flags
!.
join
(
', '
)}
"',
if (scrollPosition != null) 'scrollPosition "
$scrollPosition
"',
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment