mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 01:18:38 +08:00
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:
@ -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(
|
||||
|
||||
Reference in New Issue
Block a user