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

@ -287,15 +287,13 @@ MyCollidable randomCollidable(
final rng = random ?? Random();
final rotationSpeed = 0.5 - rng.nextDouble();
final shapeType = Shapes.values[rng.nextInt(Shapes.values.length)];
switch (shapeType) {
case Shapes.circle:
return CollidableCircle(position, size, velocity, screenHitbox)
..rotationSpeed = rotationSpeed;
case Shapes.rectangle:
return CollidableRectangle(position, size, velocity, screenHitbox)
..rotationSpeed = rotationSpeed;
case Shapes.polygon:
return CollidablePolygon(position, size, velocity, screenHitbox)
..rotationSpeed = rotationSpeed;
}
return switch (shapeType) {
Shapes.circle => CollidableCircle(position, size, velocity, screenHitbox)
..rotationSpeed = rotationSpeed,
Shapes.rectangle =>
CollidableRectangle(position, size, velocity, screenHitbox)
..rotationSpeed = rotationSpeed,
Shapes.polygon => CollidablePolygon(position, size, velocity, screenHitbox)
..rotationSpeed = rotationSpeed,
};
}