简体   繁体   中英

Custom Widget to extends Widget or use Widget as member?

I want to create a Custom Widget, I am not sure which one is better for my purpose, does anyone give suggestion? First way:

class ListItem extends LisTile {
  final TileType tileType;
  ...
}

Second way:

class ListItem {
  final TileType tileType;
  final ListTile tile;
  ...
}

Strongly recommended to use composition (this has-a that) rather than inheritance (this is-a that). Otherwise, you are tightly coupled with everything the Flutter team does to change upcoming releases that isn't necessarily part of the public interface.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM