Product list with a model class
Show a list of products with ListView.builder and a Product class.
intermediateDart / Flutter· Flutter & Dart
The task
Create a Product class (name, price, inStock) and a ProductList widget that shows a list of products:
- Use
ListView.builder(it only builds the rows on screen). - Each row is a
ListTile: the name as the title, the price as the subtitle (\$12.50). - Products out of stock show the text "Sold out" in grey at the end of the row.
- Tapping a product that's in stock shows a
SnackBar: "Added <name> to cart".
What you'll build
The finished app screen, as a web preview (yours will run on a phone or emulator). Try it, then build it below.