Implement switch expressions in dev/ (#139048)

I previously made a PR (#136140) that used `switch` expressions to make some parts of the Flutter codebase easier to understand. It was assigned to the framework team, and @christopherfujino let me know that it was too large to effectively review and recommended breaking it up into smaller pull requests.

Here's a PR that only targets files in the `dev/` directory. Hopefully this will be easier to work with!

(solves issue https://github.com/flutter/flutter/issues/136139)
This commit is contained in:
Nate
2023-11-28 16:40:28 -07:00
committed by GitHub
parent 9c4df1f1f5
commit 3267fbc07a
15 changed files with 117 additions and 197 deletions

View File

@@ -152,19 +152,13 @@ class PathCommandAnimation {
}
String toDart() {
String dartCommandClass;
switch (type) {
case 'M':
dartCommandClass = '_PathMoveTo';
case 'C':
dartCommandClass = '_PathCubicTo';
case 'L':
dartCommandClass = '_PathLineTo';
case 'Z':
dartCommandClass = '_PathClose';
default:
throw Exception('unsupported path command: $type');
}
final String dartCommandClass = switch (type) {
'M' => '_PathMoveTo',
'C' => '_PathCubicTo',
'L' => '_PathLineTo',
'Z' => '_PathClose',
_ => throw Exception('unsupported path command: $type'),
};
final StringBuffer sb = StringBuffer();
sb.write('${kIndent * 4}const $dartCommandClass(\n');
for (final List<Point<double>> pointFrames in points) {