Skip to content

Instantly share code, notes, and snippets.

@lesnitsky
Created July 11, 2022 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lesnitsky/02da8180d7d64acd2a2a8b4ed7946199 to your computer and use it in GitHub Desktop.
Save lesnitsky/02da8180d7d64acd2a2a8b4ed7946199 to your computer and use it in GitHub Desktop.
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