🙂 İNSANLARIN EN HAYIRLISI INSANLARA FAYDALI OLANDIR 🙂

Ramazan HABER / FLUTTER / ListTile CheckboxListTile radiobutton dropdownbutton vs kullanımı

1-) FLUTTER - ListTile CheckboxListTile radiobutton dropdownbutton vs kullanımı

 

0-   ListTile KULLANIMI

 

PADDİNGLERİ SIFIRLAMAK İÇİN AŞAĞIDAKİLERİ KULLAN

  dense:true,
  contentPadding:
EdgeInsets.only(left: 0.0, right: 0.0),

 

 

 

 

child: Card(
  shape:
RoundedRectangleBorder(
      borderRadius:
BorderRadius.circular(10)),
  elevation:
12,
  child:
ListTile(
    leading:
Icon(Icons.add),
    title:
Text("Başlık"),
    subtitle:
Text("Alt başlık içerik"),
    trailing:
Icon(Icons.real_estate_agent),
  ),
),

 

leading nedir ? sol taraftaki icon

trailing nedir ? sağ taraftaki icon

 

 

iki widget arasına çizgi atmak için Divider kullanabilirsin

Divider(color: Colors.red,thickness: 1,height: 10,indent: 20,endIndent: 20,),

 

thickness -> kalınlık , height -> yukarıdan margin , indent -> soldan boşuk , endIndent -> sağdan boşluk

 

 

 

 

1-   CHECKBOXLİSTTİLE KULLANIMI

 

 

 

bool check_ulke = false;

 

CheckboxListTile(
  value:
check_ulke,
  onChanged: (secilen) {
    setState(() {
      
check_ulke = secilen!;
    });
  },
  activeColor:
Colors.blue,
  title:
Text("Türkiye"),
  subtitle:
Text("Türkiye sub title"),
  secondary:
Icon(Icons.add),
  selected:
true,
),

 

 

2-   RADİOLİSTTİLE KULLANIMI

 

 

String sehir = "";

 

RadioListTile<String>(
  title:
Text("Antalya"),
  value:
"Antalya",
  groupValue:
sehir,
  onChanged: (deger) {
    setState(() {
      
sehir = deger!;
      print(
"secilen deger : " + deger!);
    });
  },
  subtitle:
Text("Alt içerik"),
  secondary:
Icon(Icons.add),
),
RadioListTile<String>(
  title:
Text("Konya"),
  value:
"Konya",
  groupValue:
sehir,
  onChanged: (deger) {
    setState(() {
      
sehir = deger!;
      print(
"secilen deger : " + deger!);
    });
  },
  subtitle:
Text("Alt içerik"),
  secondary:
Icon(Icons.add),
),
RadioListTile<String>(
  title:
Text("İstanbul"),
  value:
"İstanbul",
  groupValue:
sehir,
  onChanged: (deger) {
    setState(() {
      
sehir = deger!;
      print(
"secilen deger : " + deger!);
    });
  },
  subtitle:
Text("Alt içerik"),
  secondary:
Icon(Icons.add),
),

 

 

 

2.1- DİNAMİK  RADİO KULLANIMI

 

 

List<String> saatList = [
  
"9:00-12:00",
  
"12:00-15:00",
  
"15:00-18:00",
  
"18:00-21:00"
];
String seciliSaat = "9:00-12:00";

Widget saatSec() {
  
return Container(
      height:
150,
      padding:
EdgeInsets.only(left: 5,right: 5),
      child:
GridView.builder(
        itemCount:
saatList.length,
        gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount(
          crossAxisCount:
2,
          mainAxisExtent:
60, // yükseklik demek
        
),
        itemBuilder: (
BuildContext contex, int index) {
          
String data = saatList[index];

          
return InkWell(
            onTap: (){
              setState(() {
                
seciliSaat = data;
              });
            },
            child:
Card(
              semanticContainer:
true,
              clipBehavior:
Clip.antiAliasWithSaveLayer,
              shape:
RoundedRectangleBorder(
                borderRadius:
BorderRadius.circular(10.0),
              ),
              elevation:
8,
              child:
Row(
                mainAxisAlignment:
MainAxisAlignment.center,
                children: [
                  
Container(
                    width:
20,
                    height:
20,
                    child:
Radio(
                        
// title: Text(data),
                        // contentPadding: EdgeInsets.all(0),
                        
value: data,
                        groupValue:
seciliSaat,
                        onChanged: (val) {
                          setState(() {
                            
seciliSaat = val.toString();
                          });
                        }),
                  ),
                  
SizedBox(width: 5,),
                  
Container(
                      child:
Text(
                    
data,

                    style: TextStyle(fontWeight: FontWeight.bold,fontSize: 15),

                    textAlign: TextAlign.left,
                  ))
                ],
              ),
            ),
          );
        },
      ));
}

 

 

 

 

 

 

3-   SWİTCHLİSTTİLE KULLANIMI

 

 

 

bool switchState = false;

 

SwitchListTile(
  value:
switchState,
  onChanged: (deger) {
    setState(() {
      
switchState = deger;
      print(
switchState);
    });
  },
  title:
Text("Switch title"),
  subtitle:
Text("Switch subtitle"),
  secondary:
Icon(Icons.add_alarm),
),

 

 

 

 

4-  SLİDER KULLANIMI

 

 

 

double sliderDeger = 10;

 

child: Slider(
  value:
sliderDeger,
  onChanged: (yeniDeger) {
    setState(() {
      
sliderDeger = yeniDeger;
    });
  },
  min:
10,
  max:
20,
  divisions:
10,  // 10 ile 20 arasını 10 parçaya böl demek
  
label: sliderDeger.toString(),
),

 

 

 

 

5-  DROPDOWNBUTTON KULLANIMI

 

 

 

String seciliDropitem="";

 

child: DropdownButton<String>(
  items:  [
    
DropdownMenuItem(child: Text("İstanbul"),value: "İstanbul",),
    
DropdownMenuItem(child: Text("KONYA"),value: "KONYA",),
    
DropdownMenuItem(child: Text("Antalya"),value: "Antalya",),
  ],
  onChanged: (deger) {
    setState(() {
      
seciliDropitem=deger!;
      print(deger);
    });
  },
  hint:
Text("Lütfen ilinizi seçiniz"),
  value:
seciliDropitem=="" ?  null: seciliDropitem,
),

 

 

 

 

 

 

 

 

6-  DROPDOWNBUTTON KULLANIMI DİNAMİK

 

 

 

String seciliSehir="";

List<String> sehirler = ["Antalya", "İstanbul", "Ankara"];

 

DropdownButton(
  items:
sehirler.map((seciliSehir) {
    
return DropdownMenuItem(
      child:
Text(seciliSehir),
      value: seciliSehir,
    );
  }).toList(),
  onChanged: (
String? value) {
    setState(() {
      
seciliSehir = value!;
    });
  },
  value:
seciliSehir == "" ? null : seciliSehir,
  hint:
Text("Lütfen ilinizi seçiniz"),
),

 

 

 

 

7-  showDatePicker kullanımı

pubspec.yaml

dependencies:

flutter_localizations:
  
sdk: flutter

date_format: ^2.0.5

main.dart

import 'package:flutter_localizations/flutter_localizations.dart';

// türkçe desteklemesi için https://api.flutter.dev/flutter/flutter_localizations/GlobalMaterialLocalizations-class.html

import 'package:date_format/date_format.dart';

// formatlamak için https://pub.dev/packages/date_format/example

return MaterialApp(
  localizationsDelegates:
GlobalMaterialLocalizations.delegates,

  supportedLocales: [const Locale('en'), const Locale('fr'), const Locale('tr')],

 

 

ElevatedButton(
  onPressed: () {
    showDatePicker(
            context: context,
            initialDate:
suan,
            firstDate:
ucAyOnce,
            lastDate:
ucAySonra)
        .then((value) {
      
// then yani seçildikten sonra demek
      
DateTime? onGunSonra = value?.add(Duration(days: 10));
      print(
onGunSonra.toString());
      print(value.toString());
      print(formatDate(value!, [
dd, '.', mm, '.', yyyy]));
    });
  },
  child:
Text("Tarih Seç"),
),

 

 

 

 

7-  showTimePicker kullanımı

pubspec.yaml

dependencies:

flutter_localizations:
  
sdk: flutter

date_format: ^2.0.5

main.dart

import 'package:flutter_localizations/flutter_localizations.dart';

// türkçe desteklemesi için https://api.flutter.dev/flutter/flutter_localizations/GlobalMaterialLocalizations-class.html

import 'package:date_format/date_format.dart';

// formatlamak için https://pub.dev/packages/date_format/example

return MaterialApp(
  localizationsDelegates:
GlobalMaterialLocalizations.delegates,

  supportedLocales: [const Locale('en'), const Locale('fr'), const Locale('tr')],

 

 

ElevatedButton(
  onPressed: () {
    showTimePicker(context: context, initialTime:
suankiSaat)
        .then((secilenSaat) {
      print(secilenSaat?.format(context));
      print(
          
"seçilen saat ${secilenSaat?.hour} dakika ${secilenSaat!.minute}");
    });
  },
  child:
Text("Saat Seç"),
),

 

 

 

7-  CupertinoDatePicker kullanımı

pubspec.yaml

dependencies:

flutter_localizations:
  
sdk: flutter

date_format: ^2.0.5

main.dart

import 'package:flutter_localizations/flutter_localizations.dart';

// türkçe desteklemesi için https://api.flutter.dev/flutter/flutter_localizations/GlobalMaterialLocalizations-class.html

import 'package:date_format/date_format.dart';

// formatlamak için https://pub.dev/packages/date_format/example

return MaterialApp(
  localizationsDelegates:
GlobalMaterialLocalizations.delegates,

  supportedLocales: [const Locale('en'), const Locale('fr'), const Locale('tr')],

 

Container(
  height:
150,
  child:
CupertinoDatePicker(
    mode:
CupertinoDatePickerMode.date,
    onDateTimeChanged: (value) {
      print(value.toString());
      print(formatDate(value, [
dd, '.', mm, '.', yyyy]));
    },
    initialDateTime:
DateTime(1980,01,01),
  ),
)

 

veya

 

Expanded(
  child:
Container(
    margin:
const EdgeInsets.only(left: 16, right: 32),
    child:
Container(
      child:
CupertinoDatePicker(
        mode:
CupertinoDatePickerMode.date,
        onDateTimeChanged: (value) {
          print(value.toString());
          print(formatDate(
              value, [
dd, '.', mm, '.', yyyy]));
        },
        initialDateTime:
DateTime(1980, 01, 01),
      ),
    ),
  ),
),

 

 

 

 

 

 

 2022 Kasım 30 Çarşamba
 805