A Stack has-a List
A Square is-a Shape.
Due to us using a Widget as abstract, when we implement from it, we’re of type Widget.
So class Button needs a type Widget, and we can use any.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
abstract class Widget {} // we can use abstract to pass any widget into constructors like in Button class Text implements Widget { Text(this.text); final String text; } class Button implements Widget { Button({required this.child, this.onPressed}); final Widget child; final void Function()? onPressed; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
void main() { final button = Button( child: Text('Hello'), // can pass any widget we want onPressed: null//() => print('hahaha') ); if (button.onPressed is Function) { button.onPressed!(); } else { print('onPressed function not available'); } } |