- 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<Cars> createState() => _CarsState();
- }
- class _CarsState extends State<Cars> {
- 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(
- alignment: Alignment.center,
- width: 400,
- height: 60,
- decoration: BoxDecoration(
- color: Colors.red,
- borderRadius: BorderRadius.circular(5)
- ),
- child: const Text("Remove", style: TextStyle(
- color: Colors.white,
- fontSize: 20
- )
- )
- )
- ),
- 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,
- decoration: BoxDecoration(
- color: cars[index].isCrashed() ? Colors.amber[800] : Colors.amber,
- borderRadius: BorderRadius.circular(5)
- ),
- 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),
- )
- ],
- )
- ),
- );
- }
- ),
- ),
- ],
- ),
- )
- )
- );
- }
- }