Get your
own
website
Change Orientation
Ctrl+Alt+O
Change Theme
Ctrl+Alt+D
Change Language
Go to Spaces
Ctrl+Alt+P
sealed class Shape {} class Circle extends Shape { final double radius; Circle(this.radius); } class Square extends Shape { final double side; Square(this.side); } class Triangle extends Shape { final double base; final double height; Triangle(this.base, this.height); } double area(Shape shape) { return switch (shape) { Circle c => 3.14 * c.radius * c.radius, Square s => s.side * s.side, }; } void main() { print(area(Circle(2))); }
main.dart:20:18: Error: The type 'Shape' is not exhaustively matched by the switch cases since it doesn't match 'Triangle()'.
- 'Shape' is from 'main.dart'.
Try adding a wildcard pattern or cases that match 'Triangle()'.
return switch (shape) {
^