Flutter – Form Elemanları

import 'package:flutter/material.dart';
class FormveTextFormField extends StatefulWidget {
  @override
  _FormveTextFormFieldState createState() => _FormveTextFormFieldState();
}
class _FormveTextFormFieldState extends State<FormveTextFormField> {
  String _adsoyad, _mailadres, _password;
  bool otomatikkontrol = true;
  bool checkboxstatemhk = false;
  bool switchdurumu = true;
  String cinsiyet = "";
  double sliderdeger = 1;
  final formkey =
      GlobalKey<FormState>(); //tüm formlarda geçerli bir key oluşturuyoruz
  //bu key sadece aşağıdaki formun keyi olarak düşünebilirsiniz...
  @override
  Widget build(BuildContext context) {
    return Theme(
      data: Theme.of(context).copyWith(
          accentColor: Colors.green,
          errorColor: Colors.green,
          primaryColor: Colors.red.shade400),
      child: Scaffold(
        floatingActionButton: FloatingActionButton(
          onPressed: () {},
          child: Icon(Icons.save),
        ),
        appBar: AppBar(
          title: Text("Form ve Text Form İşlemleri"),
        ),
        body: Padding(
            padding: const EdgeInsets.all(20.0),
            child: Form(
              key: formkey,
              autovalidate: otomatikkontrol,
              child: ListView(
                children: <Widget>[
                  SizedBox(height: 40,)
                  ,
                  Text("Değeri Seçiniz"),
                  Slider(
                    label: "Eti : $sliderdeger",
                    divisions: 120,
                    value: sliderdeger,
                    min: 0,max: 120,
                    onChanged: (verim2) {
                      setState(() {
                        sliderdeger = verim2;
                        cinsiyet = verim2.toString();
                      });
                      debugPrint("Gelen Veri $verim2");
                    },
                  ),
                  SizedBox(),
                  SwitchListTile(
                    value: switchdurumu,
                    
                    onChanged: (verim) {
                      setState(() {
                        switchdurumu = verim;
                        cinsiyet = verim.toString();
                      });
                      debugPrint("Gelen Veri $verim");
                    },
                    title: Text("Switch başlık"),
                    subtitle: Text("Subtitlemmiz"),
                    secondary: Icon(Icons.account_circle),
                  ),
                  SizedBox(
                    height: 20,
                  ),
                  RadioListTile<String>(
                      subtitle: Text("Subtitleee"),
                      title: Text("Seçilmedi ?  $cinsiyet"),
                      value: "Secilmedi",
                      secondary: Icon(Icons.mail),
                      groupValue: cinsiyet,
                      onChanged: (veri) {
                        setState(() {
                          cinsiyet = veri;
                        });
                        debugPrint(veri);
                      }),
                  SizedBox(
                    height: 20,
                  ),
                  RadioListTile<String>(
                      title: Text("Erkek mi?  $cinsiyet"),
                      secondary: Icon(Icons.mail),
                      subtitle: Text("Subtitleee"),
                      value: "Erkek",
                      groupValue: cinsiyet,
                      onChanged: (veri) {
                        setState(() {
                          cinsiyet = veri;
                        });
                        debugPrint(veri);
                      }),
                  SizedBox(
                    height: 20,
                  ),
                  RadioListTile<String>(
                    subtitle: Text("Subtitleee"),
                    secondary: Icon(Icons.mail),
                    title: Text("Kadın mi? $cinsiyet"),
                    value: "Kadın",
                    groupValue: cinsiyet,
                    onChanged: (veri) {
                      setState(() {
                        debugPrint(veri);
                        cinsiyet = veri;
                      });
                    },
                  ),
                  SizedBox(
                    height: 20,
                  ),
                  CheckboxListTile(
                      title: Text("Seçilsin mi?"),
                      // activeColor: Colors.green,
                      // checkColor: Colors.blue,
                      subtitle: Text("Sub Titlemiz..:"),
                      secondary: Icon(Icons.mail),
                      value: checkboxstatemhk,
                      onChanged: (secim) {
                        setState(() {
                          if (secim) {
                            checkboxstatemhk = true;
                            debugPrint("Seçildi");
                          } else {
                            checkboxstatemhk = false;
                            debugPrint("SEÇİLMEDİ");
                          }
                        });
                      }),
                  SizedBox(
                    width: 20,
                    height: 20,
                  ),
                  TextFormField(
                    decoration: InputDecoration(
                      prefixIcon: Icon(Icons.account_circle),
                      labelText: "Ad Soyad :",
                      labelStyle: TextStyle(
                        fontSize: 22,
                      ),
                      border: OutlineInputBorder(),
                      hintText: "Adınız Soyadınız...",
                    ),
                    validator: (String girilenveri) {
                      if (girilenveri.length < 5) {
                        return "Girilen veri 5 ten küçük";
                      }
                    },
                    onSaved: (deger) => _adsoyad = deger,
                  ),
                  SizedBox(
                    height: 10,
                  ),
                  TextFormField(
                    keyboardType: TextInputType.emailAddress,
                    decoration: InputDecoration(
                      prefixIcon: Icon(Icons.email),
                      labelText: "Email Adresiniz :",
                      labelStyle: TextStyle(
                        fontSize: 22,
                      ),
                      border: OutlineInputBorder(),
                      enabledBorder: OutlineInputBorder(
                          borderSide: BorderSide(color: Colors.green)),
                      focusedBorder: OutlineInputBorder(
                          borderSide: BorderSide(color: Colors.amber)),
                      hintText: "Email Adresini...",
                    ),
                    validator: (String girilenveri) => "",
                    onSaved: (deger) => _mailadres = deger,
                  ),
                  SizedBox(
                    height: 10,
                  ),
                  TextFormField(
                    keyboardType: TextInputType.visiblePassword,
                    obscureText: true,
                    decoration: InputDecoration(
                      prefixIcon: Icon(Icons.lock),
                      labelText: "Şifreniz :",
                      labelStyle: TextStyle(
                        fontSize: 22,
                      ),
                      border: OutlineInputBorder(),
                      enabledBorder: OutlineInputBorder(
                          borderSide: BorderSide(color: Colors.green)),
                      focusedBorder: OutlineInputBorder(
                          borderSide: BorderSide(color: Colors.amber)),
                      hintText: "Şifreniz...",
                    ),
                    validator: (String girilenveri) => "",
                    onSaved: (deger) => _password = deger,
                  ),
                  SizedBox(
                    height: 10,
                  ),
                  RaisedButton(
                    color: Colors.greenAccent,
                    disabledColor: Colors.redAccent,
                    child: Text("Butonum benim"),
                    onPressed: () {
                      debugPrint("Butona Basıldı :");
                      _girilenVerileriOnayla();
                    },
                  ),
                ],
              ),
            )),
      ),
    );
  }
  void _girilenVerileriOnayla() {
    if (formkey.currentState.validate()) {
      formkey.currentState.save();
      debugPrint("ad :$_adsoyad mail $_mailadres Şifre : $_password");
    } else {
      setState(() {
        otomatikkontrol = true;
      });
      debugPrint(formkey.currentState.validate().toString());
    }
  }
}

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir