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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://haluk-hackali.gitbook.io/flutter-dart-notes/flutter/wigdeti-to-method.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
