Created
July 11, 2022 11:33
-
-
Save lesnitsky/02da8180d7d64acd2a2a8b4ed7946199 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User { | |
final String name; | |
User({required this.name}); | |
} | |
class SuperchargedUser extends User { | |
final String ability; | |
// no duplication of the "final String name;" here | |
SuperchargedUser({super.key, super.name, required this.ability}); | |
} | |
class UserTile extends StatelessWidget { | |
final String name; | |
const UserTile({Key? key, required this.name}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return Text(name); | |
} | |
} | |
class SuperchargedUserTile extends StatelessWidget { | |
final String ability; | |
// You have to declare this again, in order to be able to access this | |
// inside build. | |
final String name; | |
const SuperchargedUserTile({super.key, required this.ability, required this.name}); | |
@override | |
Widget build(BuildContext context) { | |
return Row( | |
children: [ | |
UserTile(name: name), | |
Text(ability), | |
], | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment