> For the complete documentation index, see [llms.txt](https://haluk-hackali.gitbook.io/flutter-dart-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://haluk-hackali.gitbook.io/flutter-dart-notes/flutter/wigdeti-to-method.md).

# Wigdet'i to Method

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.

{% hint style="info" %}
Bunu yapmanın iki yolu var.

1. **Yöntem**: Fonksiyonu kendimiz oluştururuz.&#x20;
2. **Yöntem**: Fonksiyonu Android Studio'ya oluştururuz.
   {% endhint %}

{% code title="1.Yöntem = Manuel" %}

```dart

// 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),
),
```

{% endcode %}

{% hint style="info" %}
**2. Yöntemin Uygulanması:**

FlatButton'ı seç, sağ tıkla,&#x20;

Refactor'u tıkla ,&#x20;

Extracth Methodû tıkla,&#x20;

Fonksiyona isim ver ve Refactor 'ü tıkla. Bitti!
{% endhint %}

```dart
 Expanded(
  child: FlatButton(
    padding: EdgeInsets.all(8.0),
    onPressed: () {
      sesiCal('bip');
   },
  child: Container(
  color: Colors.blue,
 ),
 ),
```
