flutter

 avatar
unknown
dart
2 years ago
14 kB
8
Indexable
import 'package:flutter/material.dart';

class Anasayfa extends StatefulWidget {
  const Anasayfa({super.key});

  @override
  State<Anasayfa> createState() => _AnasayfaState();
}

String? dropdownValue; // İlk değer için bir örnek
DateTime selectedDate = DateTime.now();

class _AnasayfaState extends State<Anasayfa> {
  @override
  Widget build(BuildContext context) {
    Future<void> _selectDate(BuildContext context) async {
      final DateTime? picked = await showDatePicker(
        context: context,
        initialDate: selectedDate,
        firstDate: DateTime(2000),
        lastDate: DateTime(2025),
      );
      if (picked != null && picked != selectedDate) {
        setState(() {
          selectedDate = picked;
        });
      }
    }

    final genislik = MediaQuery.of(context).size.width;
    final yukseklik = MediaQuery.of(context).size.height;
    Orientation orientation = MediaQuery.of(context).orientation;
    return Scaffold(
      appBar: AppBar(
          backgroundColor: Colors.black,
          centerTitle: true,
          titleTextStyle:
              const TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
          title: const Text("Yabancı Borsa Vergi Hesaplama"),
          bottom: PreferredSize(
            preferredSize: const Size.fromHeight(30),
            child: Container(
              decoration: const BoxDecoration(
                  color: Colors.black87,
                  border: Border(
                      bottom: BorderSide(width: 0.5, color: Colors.white))),
              child: Padding(
                padding: const EdgeInsets.symmetric(horizontal: 8.0),
                child: Row(
                  children: [
                    Expanded(
                        flex: 20,
                        child: Text(
                          orientation == Orientation.portrait
                              ? "İşlem"
                                  "     Türü"
                              : "İşlem Türü",
                          textAlign: TextAlign.center,
                          style: const TextStyle(
                              fontWeight: FontWeight.bold, color: Colors.white),
                        )),
                    const Expanded(
                        flex: 20,
                        child: Text(
                          "Tarih",
                          textAlign: TextAlign.center,
                          style: TextStyle(
                              fontWeight: FontWeight.bold, color: Colors.white),
                        )),
                    const Expanded(
                        flex: 20,
                        child: Text(
                          "Adet",
                          textAlign: TextAlign.center,
                          style: TextStyle(
                              fontWeight: FontWeight.bold, color: Colors.white),
                        )),
                    const Expanded(
                        flex: 20,
                        child: Text(
                          "Birim Fiyat",
                          textAlign: TextAlign.center,
                          style: TextStyle(
                              fontWeight: FontWeight.bold, color: Colors.white),
                        )),
                    const Expanded(flex: 20, child: SizedBox()),
                  ],
                ),
              ),
            ),
          )),
      body: SafeArea(
        child: Container(
          padding: const EdgeInsets.symmetric(horizontal: 5),
          color: Colors.black,
          child: Column(
            children: [
              SingleChildScrollView(
                child: SizedBox(
                  height: yukseklik * 0.7,
                  child: ListView.builder(
                    itemCount: _employeeDataSource.length,
                    itemBuilder: (
                      context,
                      index,
                    ) {
                      return InkWell(
                          onTap: () {
                            print("bastım");
                          },
                          child: _borsaCard(index, yukseklik));
                    },
                  ),
                ),
              ),
              Padding(
                padding: const EdgeInsets.all(8.0),
                child: _hesaplaButton(),
              )
            ],
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          showDialog(
            context: context,
            builder: (BuildContext context) {
              return AlertDialog(
                title: const Text('Form'),
                content: SingleChildScrollView(
                  child: ListBody(
                    children: <Widget>[
                      TextButton(
                        onPressed: () => _selectDate(context),
                        child: Text("${selectedDate.toLocal()}".split(' ')[0]),
                      ),
                      Expanded(
                        child: DropdownButtonFormField<String>(
                          decoration: InputDecoration(
                            hintText: 'İşlem Türü',
                            border: OutlineInputBorder(
                              borderSide: BorderSide.none,
                              borderRadius: BorderRadius.circular(10),
                            ),
                            filled: true,
                            fillColor: Colors.white,
                          ),
                          value: dropdownValue,
                          onChanged: (String? newValue) {
                            setState(() {
                              dropdownValue = newValue!;
                            });
                          },
                          items: <String>['Alış', 'Satış']
                              .map<DropdownMenuItem<String>>((String value) {
                            return DropdownMenuItem<String>(
                              value: value,
                              child: Text(value),
                            );
                          }).toList(),
                        ),
                      ),
                      SizedBox(height: yukseklik * 0.05),
                      Expanded(
                        child: TextFormField(
                          cursorColor: Colors.black,
                          decoration: InputDecoration(
                            hintText: 'Hisse Adeti',
                            hintStyle: const TextStyle(
                              color: Colors.grey,
                            ),
                            border: OutlineInputBorder(
                              borderSide: BorderSide.none,
                              borderRadius: BorderRadius.circular(10),
                            ),
                            filled: true,
                            fillColor: Colors.white,
                          ),
                        ),
                      ),
                      SizedBox(height: yukseklik * 0.05),
                      Expanded(
                        child: TextFormField(
                          decoration: InputDecoration(
                            hintText: 'Hisse Fiyat',
                            hintStyle: const TextStyle(
                              color: Colors.grey,
                            ),
                            border: OutlineInputBorder(
                              borderSide: BorderSide.none,
                              borderRadius: BorderRadius.circular(10),
                            ),
                            filled: true,
                            fillColor: Colors.white,
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
                actions: <Widget>[
                  TextButton(
                    child: const Text('İptal'),
                    onPressed: () {
                      Navigator.of(context).pop();
                    },
                  ),
                  TextButton(
                    child: const Text('Tamam'),
                    onPressed: () {
                      // Tamam butonuna basıldığında yapılacak işlemler
                      Navigator.of(context).pop();
                    },
                  ),
                ],
              );
            },
          );
        },
        backgroundColor: Colors.white10,
        foregroundColor: Colors.white,
        child: const Icon(Icons.add),
      ),
    );
  }

  OutlinedButton _hesaplaButton() {
    return OutlinedButton.icon(
        style: ElevatedButton.styleFrom(
            backgroundColor: Colors.white10,
            shape: const RoundedRectangleBorder(
                borderRadius: BorderRadius.all(Radius.circular(8)))),
        onPressed: () {},
        icon: const Icon(
          Icons.query_stats,
          color: Colors.white,
        ),
        label: const Text(
          "Hesapla",
          style: TextStyle(color: Colors.white),
        ));
  }

  Card _borsaCard(int index, double yukseklik) {
    return Card(
      color: (index % 2 == 0) ? Colors.black54 : Colors.white10,
      child: SizedBox(
        child: Row(
          children: [
            Expanded(
                flex: 20,
                child: Text(
                  _employeeDataSource[index].tur,
                  textAlign: TextAlign.center,
                  style: const TextStyle(
                      fontWeight: FontWeight.bold, color: Colors.white),
                )),
            Expanded(
                flex: 20,
                child: Text(
                  _employeeDataSource[index].tarih,
                  textAlign: TextAlign.center,
                  style: const TextStyle(color: Colors.white),
                )),
            Expanded(
              flex: 20,
              child: Text(
                _employeeDataSource[index].adet,
                textAlign: TextAlign.center,
                style: const TextStyle(color: Colors.white),
              ),
            ),
            Expanded(
                flex: 20,
                child: Text(
                  _employeeDataSource[index].fiyat.toString(),
                  textAlign: TextAlign.center,
                  style: const TextStyle(color: Colors.white),
                )),
            Expanded(
                flex: 20,
                child: IconButton(
                  onPressed: () {
                    setState(() {
                      _employeeDataSource.removeAt(index);
                    });
                  },
                  icon: const Icon(
                    Icons.delete,
                    color: Colors.red,
                  ),
                )),
          ],
        ),
      ),
    );
  }
}

class Employee {
  Employee(this.tur, this.tarih, this.adet, this.fiyat);

  final String tur;
  final String tarih;
  final String adet;
  final double fiyat;
}

List<Employee> _employeeDataSource = [
  Employee('Alış', '25.02.2022', '10', 205.94),
  Employee('Satış', '25.04.2023', '15', 205.94),
  Employee('Alış', '25.01.2023', '13', 205.94),
  Employee('Satış', '25.08.2021', '23', 205.94),
  Employee('Alış', '25.07.2023', '7', 205.94),
  Employee('Satış', '25.09.2024', '19', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  Employee('Alış', '25.05.2022', '26', 205.94),
  // Add more employees as needed
];
Editor is loading...
Leave a Comment