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.
// 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),
),
Expanded(
child: FlatButton(
padding: EdgeInsets.all(8.0),
onPressed: () {
sesiCal('bip');
},
child: Container(
color: Colors.blue,
),
),
Last updated
Was this helpful?