import 'package:flutter/material.dart'; import 'car.dart'; void main() { runApp(const Cars()); } class Cars extends StatefulWidget { const Cars({Key? key}) : super(key: key); @override State createState() => _CarsState(); } class _CarsState extends State { List cars = [ Car("Renault", 2018, "red", 89000), Car("Audi", 2019, "black", 45000), Car("Mazda", 2011, "blue", 186000), Car("Lexus", 2015, "white", 230000), Car("Opel", 2010, "black", 123000), Car("Volvo", 2018, "yellow", 20000) ]; @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: SafeArea( child: Column( children: [ TextButton( onPressed: () {}, child: Container( height: 20, color: Colors.red ) ), Expanded( child: ListView.builder( itemCount: cars.length, itemBuilder: (BuildContext context, int index) { return TextButton( onPressed: () { setState(() { cars[index].setCrashed(); }); }, child: Container( margin: EdgeInsets.all(10), height: 150, width: 400, color: cars[index].isCrashed() ? Colors.amber[800] : Colors.amber, child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Text(cars[index].getName(), style: const TextStyle( color: Colors.redAccent, fontSize: 23, fontWeight: FontWeight.bold ) ), Container( child: Text("rocznik " + cars[index].getYear().toString(), style: const TextStyle(color: Colors.brown)), margin: EdgeInsets.all(8), ) ], ) ), ); } ), ), ], ), ) ) ); } }