refactor: Modernize switch; use switch-expressions and no break; (#3133)

Replaces the switch cases that can be replaces with switch expressions
and removes `break;` where it isn't needed.

https://dart.dev/language/branches#switch-statements
This commit is contained in:
Lukas Klingsbo
2024-04-18 23:41:08 +02:00
committed by GitHub
parent 69f5c388ce
commit b283b82f6c
29 changed files with 183 additions and 425 deletions

View File

@ -18,18 +18,15 @@ class SpawnComponentWorld extends World with TapCallbacks {
@override
void onTapDown(TapDownEvent info) {
final shapeType = Shapes.values.random();
final Shape shape;
final position = info.localPosition;
switch (shapeType) {
case Shapes.rectangle:
shape = Rectangle.fromCenter(
final shape = switch (shapeType) {
Shapes.rectangle => Rectangle.fromCenter(
center: position,
size: Vector2.all(200),
);
case Shapes.circle:
shape = Circle(position, 150);
case Shapes.polygon:
shape = Polygon(
),
Shapes.circle => Circle(position, 150),
Shapes.polygon => Polygon(
[
Vector2(-1.0, 0.0),
Vector2(-0.8, 0.6),
@ -44,8 +41,8 @@ class SpawnComponentWorld extends World with TapCallbacks {
..scale(200)
..add(position);
}).toList(),
);
}
),
};
add(
SpawnComponent(