Facebook
From Chartreuse Human, 1 Year ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 93
  1. import 'package:flutter/material.dart';
  2. import 'car.dart';
  3.  
  4. void main() {
  5.   runApp(const Cars());
  6. }
  7.  
  8. class Cars extends StatefulWidget {
  9.   const Cars({Key? key}) : super(key: key);
  10.  
  11.   @override
  12.   State<Cars> createState() => _CarsState();
  13. }
  14.  
  15. class _CarsState extends State<Cars> {
  16.  
  17.   List cars = [
  18.     Car("Renault", 2018, "red", 89000),
  19.     Car("Audi", 2019, "black", 45000),
  20.     Car("Mazda", 2011, "blue", 186000),
  21.     Car("Lexus", 2015, "white", 230000),
  22.     Car("Opel", 2010, "black", 123000),
  23.     Car("Volvo", 2018, "yellow", 20000)
  24.   ];
  25.  
  26.   @override
  27.   Widget build(BuildContext context) {
  28.  
  29.     return MaterialApp(
  30.       home: Scaffold(
  31.         body: SafeArea(
  32.           child: Column(
  33.             children: [
  34.               TextButton(
  35.                 onPressed: () {},
  36.                 child: Container(
  37.                   alignment: Alignment.center,
  38.                   width: 400,
  39.                   height: 60,
  40.                   decoration: BoxDecoration(
  41.                     color: Colors.red,
  42.                     borderRadius: BorderRadius.circular(5)
  43.                   ),
  44.                   child: const Text("Remove", style: TextStyle(
  45.                       color: Colors.white,
  46.                       fontSize: 20
  47.                     )
  48.                   )
  49.                 )
  50.               ),
  51.               Expanded(
  52.                 child: ListView.builder(
  53.                     itemCount: cars.length,
  54.                     itemBuilder: (BuildContext context, int index) {
  55.                       return TextButton(
  56.                         onPressed: () {
  57.                           setState(() {
  58.                             cars[index].setCrashed();
  59.                           });
  60.                         },
  61.                         child: Container(
  62.                           margin: EdgeInsets.all(10),
  63.                           height: 150,
  64.                           width: 400,
  65.                           decoration: BoxDecoration(
  66.                               color: cars[index].isCrashed() ? Colors.amber[800] : Colors.amber,
  67.                               borderRadius: BorderRadius.circular(5)
  68.                           ),
  69.                           child: Column(
  70.                             mainAxisAlignment: MainAxisAlignment.center,
  71.                             children: [
  72.                               Text(cars[index].getName(), style: const TextStyle(
  73.                                   color: Colors.redAccent,
  74.                                   fontSize: 23,
  75.                                   fontWeight: FontWeight.bold
  76.                                 )
  77.                               ),
  78.                               Container(
  79.                                   child: Text("rocznik " + cars[index].getYear().toString(), style: const TextStyle(color: Colors.brown)),
  80.                                   margin: EdgeInsets.all(8),
  81.                               )
  82.                             ],
  83.                           )
  84.                         ),
  85.                       );
  86.                     }
  87.                 ),
  88.               ),
  89.             ],
  90.           ),
  91.         )
  92.       )
  93.     );
  94.   }
  95. }
  96.  
  97.  
  98.  
  99.