Reland "if chains → switch expressions" (#148634)
I did a goof a while back:

Now that [the bug is fixed](e9d403541f), I think we're good to re-implement the if-chains cleanup!
Related:
- https://github.com/flutter/flutter/pull/147793
- https://github.com/flutter/flutter/pull/148556
- https://github.com/flutter/flutter/issues/148548
This commit is contained in:
@@ -546,12 +546,11 @@ Matcher coversSameAreaAs(Path expectedPath, { required Rect areaToCompare, int s
|
||||
/// * [flutter_test] for a discussion of test configurations, whereby callers
|
||||
/// may swap out the backend for this matcher.
|
||||
AsyncMatcher matchesGoldenFile(Object key, {int? version}) {
|
||||
if (key is Uri) {
|
||||
return MatchesGoldenFile(key, version);
|
||||
} else if (key is String) {
|
||||
return MatchesGoldenFile.forStringPath(key, version);
|
||||
}
|
||||
throw ArgumentError('Unexpected type for golden file: ${key.runtimeType}');
|
||||
return switch (key) {
|
||||
Uri() => MatchesGoldenFile(key, version),
|
||||
String() => MatchesGoldenFile.forStringPath(key, version),
|
||||
_ => throw ArgumentError('Unexpected type for golden file: ${key.runtimeType}'),
|
||||
};
|
||||
}
|
||||
|
||||
/// Asserts that a [Finder], [Future<ui.Image>], or [ui.Image] matches a
|
||||
|
||||
@@ -932,14 +932,11 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
|
||||
|
||||
final Key? key = widget.key;
|
||||
if (key is ValueKey<dynamic>) {
|
||||
String? keyLabel;
|
||||
if (key is ValueKey<int> ||
|
||||
key is ValueKey<double> ||
|
||||
key is ValueKey<bool>) {
|
||||
keyLabel = 'const ${key.runtimeType}(${key.value})';
|
||||
} else if (key is ValueKey<String>) {
|
||||
keyLabel = "const Key('${key.value}')";
|
||||
}
|
||||
final String? keyLabel = switch (key.value) {
|
||||
int() || double() || bool() => 'const ${key.runtimeType}(${key.value})',
|
||||
final String value => "const Key('$value')",
|
||||
_ => null,
|
||||
};
|
||||
if (keyLabel != null) {
|
||||
final Iterable<Element> matches = find.byKey(key).evaluate();
|
||||
if (matches.length == 1) {
|
||||
|
||||
Reference in New Issue
Block a user