Untitled

 avatar
unknown
dart
2 years ago
12 kB
9
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(
      
      body: SafeArea(
        child: Container(
          padding: const EdgeInsets.symmetric(horizontal: 5),
          color:Colors.white,
          child: Column(
            children: [
              Card(
                color: Colors.white,
                shape: const RoundedRectangleBorder(),
                child: SizedBox(
                  height: yukseklik*0.1,
                  child:  Row(
                    children: [
                      Expanded(flex:20,child:
                      Text(
                        orientation==
                            Orientation.portrait? "İşlem"
                            "     Türü" :
                            "İşlem Türü"
                        ,textAlign: TextAlign.center,)),
                      const Expanded(flex:20,child: Text("Tarih",textAlign: TextAlign.center)),
                      const Expanded(flex:20,child: Text("Adet",textAlign: TextAlign.center)),
                      const Expanded(flex:20,child: Text("Birim Fiyat",textAlign: TextAlign.center)),
                      const Expanded(flex:20,child: SizedBox()),
                    ],
                  ),
                ),
              ),
              SingleChildScrollView(
                child:SizedBox(
                  height: yukseklik*0.6,
                  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();
                    },
                  ),
                ],
              );
            },
          );
        },
        child: const Icon(Icons.add),
        backgroundColor: Colors.blue,
        foregroundColor: Colors.white,
      ),
    );
  }

  ElevatedButton _hesaplaButton() {
    return ElevatedButton.icon(

                  style: ElevatedButton.styleFrom(
                    backgroundColor: Colors.blue,
                    shape: const RoundedRectangleBorder(
                      borderRadius: BorderRadius.all(Radius.circular(10))
                    )
                  ),
                  onPressed: () {

              }, icon: Icon(Icons.query_stats,color: Colors.white,),
              label:Text("Hesapla",style: TextStyle(color: Colors.white),));
  }

  Card _borsaCard(int index, double yukseklik) {
    return Card(
                        color: (index % 2 == 0) ? Colors.white54 : Colors.white24,
                        shape: const RoundedRectangleBorder(
                          borderRadius: BorderRadius.all(Radius.circular(8))
                        ),
                        child: SizedBox(
                          height: yukseklik*0.1,
                          child: Row(
                            children: [
                              Expanded(flex:20,child: Text(_employeeDataSource[index].tur,textAlign: TextAlign.center,)),
                              Expanded(flex:20,child: Text(_employeeDataSource[index].tarih,textAlign: TextAlign.center)),
                              Expanded(flex:20,child: Text(_employeeDataSource[index].adet,textAlign: TextAlign.center)),
                              Expanded(flex:20,child: Text(_employeeDataSource[index].fiyat.toString(),textAlign: TextAlign.center)),
                              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