Facebook
From Putrid Gorilla, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 121
  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.               Container(
  35.                 margin: EdgeInsets.fromLTRB(0, 20, 0, 20),
  36.                 padding: EdgeInsets.all(10),
  37.                 width: 400,
  38.                 decoration: BoxDecoration(
  39.                   border: Border.all(
  40.                     width: 3,
  41.                     color: Colors.brown
  42.                   )
  43.                 ),
  44.                 child: Column(
  45.                   children: [
  46.                     const TextField(
  47.                       decoration: InputDecoration(
  48.                         labelText: 'Nazwa',
  49.                       ),
  50.                     ),
  51.                     const TextField(
  52.                       decoration: InputDecoration(
  53.                         labelText: 'Rocznik',
  54.                       ),
  55.                     ),
  56.                     const TextField(
  57.                       decoration: InputDecoration(
  58.                         labelText: 'Kolor',
  59.                       ),
  60.                     ),
  61.                     const TextField(
  62.                       decoration: InputDecoration(
  63.                         labelText: 'Przebieg',
  64.                       ),
  65.                     ),
  66.                     TextButton(
  67.                         onPressed: () {
  68.                           setState(() {
  69.  
  70.                           });
  71.                         },
  72.                         child: Container(
  73.                             margin: EdgeInsets.fromLTRB(0, 20, 0, 10),
  74.                             alignment: Alignment.center,
  75.                             width: 400,
  76.                             height: 60,
  77.                             decoration: BoxDecoration(
  78.                                 color: Colors.purpleAccent,
  79.                                 borderRadius: BorderRadius.circular(5)
  80.                             ),
  81.                             child: const Text("Add", style: TextStyle(
  82.                                 color: Colors.white,
  83.                                 fontSize: 20
  84.                             )
  85.                             )
  86.                         )
  87.                     )
  88.                   ],
  89.                 )
  90.               ),
  91.               TextButton(
  92.                 onPressed: () {
  93.                   setState(() {
  94.                     cars.removeWhere((car) => car.isCrashed());
  95.                   });
  96.                 },
  97.                 child: Container(
  98.                   alignment: Alignment.center,
  99.                   width: 400,
  100.                   height: 60,
  101.                   decoration: BoxDecoration(
  102.                     color: Colors.red,
  103.                     borderRadius: BorderRadius.circular(5)
  104.                   ),
  105.                   child: const Text("Remove", style: TextStyle(
  106.                       color: Colors.white,
  107.                       fontSize: 20
  108.                     )
  109.                   )
  110.                 )
  111.               ),
  112.               Expanded(
  113.                 child: ListView.builder(
  114.                     itemCount: cars.length,
  115.                     itemBuilder: (BuildContext context, int index) {
  116.                       return TextButton(
  117.                         onPressed: () {
  118.                           setState(() {
  119.                             cars[index].setCrashed();
  120.                           });
  121.                         },
  122.                         child: Container(
  123.                           margin: EdgeInsets.all(10),
  124.                           height: 150,
  125.                           width: 400,
  126.                           decoration: BoxDecoration(
  127.                               color: cars[index].isCrashed() ? Colors.amber[800] : Colors.amber,
  128.                               borderRadius: BorderRadius.circular(5)
  129.                           ),
  130.                           child: Column(
  131.                             mainAxisAlignment: MainAxisAlignment.center,
  132.                             children: [
  133.                               Text(cars[index].getName(), style: const TextStyle(
  134.                                   color: Colors.redAccent,
  135.                                   fontSize: 23,
  136.                                   fontWeight: FontWeight.bold
  137.                                 )
  138.                               ),
  139.                               Container(
  140.                                   child: Text("rocznik " + cars[index].getYear().toString(), style: const TextStyle(color: Colors.brown)),
  141.                                   margin: EdgeInsets.all(8),
  142.                               )
  143.                             ],
  144.                           )
  145.                         ),
  146.                       );
  147.                     }
  148.                 ),
  149.               ),
  150.             ],
  151.           ),
  152.         )
  153.       )
  154.     );
  155.   }
  156. }
  157.  
  158.  
  159.  
  160.