dart copywith
//copyWith allows us to copy a T and pass in arguments that overwrite //settable values. class _HomePageState extends State<HomePage> { List<Product> products = []; @override void initState() { super.initState(); Product sixSeaterDiningTableBrown = Product( id: "0", name: "6 Seater Dining Table", color: Colors.brown, ); Product sixSeaterDiningTableBlack = sixSeaterDiningTableBrown.copyWith(color: Colors.black, id: "1"); products.add(sixSeaterDiningTableBrown); products.add(sixSeaterDiningTableBlack); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text("Hello, copyWith!"), ), body: ListView( children: products .map((Product product) => ListTile( trailing: Container( width: 14, height: 14, color: product.color, ), title: Text(product.name), subtitle: Text(product.id), )) .toList()), ); } }