Dart Copywith

[Solved] Dart Copywith | Ruby - Code Explorer | yomemimo.com
Question : dart copywith

Answered by : andenet-alexander

//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()), ); }
}

Source : https://developer.school/dart-flutter-what-does-copywith-do/ | Last Update : Sun, 15 Aug 21

Answers related to dart copywith

Code Explorer Popular Question For Ruby