Skip to content

Instantly share code, notes, and snippets.

@ashishkarki
Created April 29, 2020 11:22
Show Gist options
  • Save ashishkarki/fe40e7b8c2b90ef9d841ddafa5c11bcf to your computer and use it in GitHub Desktop.
Save ashishkarki/fe40e7b8c2b90ef9d841ddafa5c11bcf to your computer and use it in GitHub Desktop.
dart-mixin-example1.dart
import 'dart:math';
mixin Area {
double getSquareArea(double side) {
return side * side;
}
double getCircleArea(double radius) {
return pi * radius * radius;
}
}
class Shapes with Area {
final double side;
final double radius;
const Shapes({
this.side,
this.radius,
});
double get squareArea => getSquareArea(side);
double get circleArea => getCircleArea(radius);
}
void main() {
final myShapes = Shapes(side: 10.0, radius: 5.0);
print(
'area of square is ${myShapes.squareArea} and circle is ${myShapes.circleArea}');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment