For the complete documentation index, see llms.txt. This page is also available as Markdown.

Wigdet'i to Method

Widget'i Fonksiyona dönüştürmek,

Bir birini tekrarlayan widget'ları bu tekrardan kurtarmak için widget'ı döndüren bir fonksiyon yazarak gerekli yerlerde sadece o fonksiyonu ve fonksiyona ait varsa parametresini çağırarak kodlarımızı fonksiyonel hale getirebiliriz.

Bunu yapmanın iki yolu var.

  1. Yöntem: Fonksiyonu kendimiz oluştururuz.

  2. Yöntem: Fonksiyonu Android Studio'ya oluştururuz.

1.Yöntem = Manuel

// Fonsiyonu Yaz 
  FlatButton buttonYap(String ses, Color renk){
   return FlatButton(
      padding: EdgeInsets.all(8.0),
      onPressed: () {
        sesiCal(ses);
      },
      child: Container(
        color: renk,
      ),
    );
  }
  
  
  // Fonsiyonu Kullan
  
Expanded(
  child: buttonYap('bongo', Colors.redAccent),
),

2. Yöntemin Uygulanması:

FlatButton'ı seç, sağ tıkla,

Refactor'u tıkla ,

Extracth Methodû tıkla,

Fonksiyona isim ver ve Refactor 'ü tıkla. Bitti!

Last updated