Skip to content

Instantly share code, notes, and snippets.

@SamJakob
Created September 2, 2022 21:53
Show Gist options
  • Save SamJakob/e52b3c0917d19f2dcd763644c51ce6d4 to your computer and use it in GitHub Desktop.
Save SamJakob/e52b3c0917d19f2dcd763644c51ce6d4 to your computer and use it in GitHub Desktop.
Dart Extensions example
/// Library A
class Animal {
final String name;
const Animal({ required this.name });
}
class Dog extends Animal {
final String breed;
const Dog({ required String name, required this.breed })
: super(name: name);
}
/// Your program
void main() {
final astro = Dog(name: 'Astro', breed: 'German Shephard');
print(astro.name);
astro.bark();
}
/// Library B
extension DogAction on Dog {
void bark() {
print('Woof!');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment