# Flutter

## Android

{% hint style="info" %}
본 가이드는 Flutter 3.29.0, Dart 3.7.0 기준으로 작성되었습니다.

SDK가 지원하는 최소 버전은 Android API 21 이상입니다.
{% endhint %}

### 플러그인 다운로드

1\) 플러그인을 다운로드 합니다.

[**▶다운로드**](/app-push/sdk-manual/sdk-down.md#flutter)

2\) 프로젝트 폴더와 같은 경로에 압축을 해제합니다.

### 플러그인 적용하기

1\) 프로젝트 pubspec.yaml 에 'fingerpush\_plugin' 을 추가합니다.&#x20;

{% hint style="danger" %} <mark style="color:red;">fingerpush\_plugin 폴더를 상대 경로로 참조하여 추가합니다.</mark>
{% endhint %}

{% code title="<project>/pubspec.yaml" %}

```
fingerpush_plugin:
    path: ../fingerpush_plugin/
```

{% endcode %}

2\) 명령어를 실행하여 플러그인을 적용합니다.&#x20;

```
flutter pub get
```

### 프로젝트 설정하기

1\) 핑거푸시 앱 생성 및 FCM 프로젝트 생성은 Android 매뉴얼을 참고바랍니다.

{% content-ref url="/pages/KLfbEmWVkBoUfAoLPnS5" %}
[Android SDK 매뉴얼](/app-push/sdk-manual/android.md)
{% endcontent-ref %}

2\) gradle 설정

a. 프로젝트 레벨의 settings.gradle.kts 에 'com.google.gms:google-services' 플러그인을 추가합니다.

{% code title="<project>/settings.gradle.kts" %}

```gradle
plugins {
    ...
    id("com.google.gms.google-services") version "4.4.3"
}
```

{% endcode %}

b. 앱 레벨의 build.gradle.kts 하단에 google-services 플러그인을 추가합니다.

{% code title="<project>/<app-module>/build.gradle.kts" %}

```gradle
plugins {
    id 'com.google.gms.google-services'
}
```

{% endcode %}

3\) AndroidManifest 설정

a. allowBackup 값을 false 로 설정합니다.

{% code title="AndroidManifest.xml" %}

```
<application
    ...
    android:allowBackup="false"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name">
    ...
</application>
```

{% endcode %}

b. 푸시 수신을 서비스를 추가합니다.

{% code title="AndroidManifest.xml" %}

```
<application>
    ...
    <service
        android:name="com.fingerpush.fingerpush_plugin.IntentService"
        android:exported="false">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>
</application>
```

{% endcode %}

4\) MainActivity 설정

{% hint style="info" %}
인앱푸시를 사용하는 경우 FlutterFragmentActivity 를 상속받습니다.
{% endhint %}

{% code title="MainActivity.kt" %}

```kotlin
...
class MainActivity : FlutterFragmentActivity(), MethodCallHandler {

    private lateinit var channel: MethodChannel

    override fun onNewIntent(intent: Intent) {
        super.onNewIntent(intent)
        checkPayload(intent.extras)
    }

    // 푸시 수신 데이터 체크
    private fun checkPayload(data: Bundle?) {
        if (data != null) {
            val jsonObject = JSONObject()
            val payload = data.getBundle("payload")

            val keys = payload?.keySet()
            if (keys != null) {
                for (key in keys) {
                    jsonObject.put(key, payload?.getString(key))
                }
                sendPayload(jsonObject.toString())
            }
        }
    }
    
    private fun sendPayload(payload: String) {
        if (this::channel.isInitialized) {
            channel.invokeMethod("onNotification", payload)
        } else {
            Handler(mainLooper).postDelayed({ sendPayload(payload) }, 200)
        }
    }
    
    override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
        super.configureFlutterEngine(flutterEngine)
        GeneratedPluginRegistrant.registerWith(flutterEngine)
        channel = MethodChannel(flutterEngine.dartExecutor, "FingerPushOnNotification")
        channel.setMethodCallHandler(this@MainActivity)

        if (intent.extras != null) {
            checkPayload(intent.extras)
        }
    }

    override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
        if (call.method.equals("onNotification")) {
            checkPayload(intent.extras)
        }
    }

}
```

{% endcode %}

### Android API Reference

Android API 는 아래 링크에서 확인 할 수 있습니다.

{% content-ref url="/pages/fx2bsLtt8TXjECxe6mfO" %}
[Android API Reference](/app-push/api-reference/android.md)
{% endcontent-ref %}

## iOS

{% hint style="info" %}
본 가이드는 Flutter SDK 3.0.0 기준으로 작성되었습니다.

최소 버전 iOS 10 이상
{% endhint %}

### 플러그인 다운로드

1\) 플러그인을 다운로드 합니다.

[**▶다운로드**](/app-push/sdk-manual/sdk-down.md#flutter)

2\) 프로젝트 폴더와 같은 경로에 압축을 해제합니다.

### 플러그인 적용하기

1\) 프로젝트 pubspec.yaml 에 'fingerpush\_plugin' 을 추가합니다.&#x20;

{% hint style="danger" %} <mark style="color:red;">fingerpush\_plugin 폴더를 상대 경로로 참조하여 추가합니다.</mark>
{% endhint %}

{% code title="<project>/pubspec.yaml" %}

```
fingerpush_plugin:
    path: ../fingerpush_plugin/
```

{% endcode %}

2\) 명령어를 실행하여 플러그인을 적용합니다.&#x20;

```
flutter pub get
```

3\) 프로젝트에 'fingerpush\_plugin.dart' import 합니다.

```objectivec
import 'package:fingerpush_plugin/fingerpush_plugin.dart';
```

4\) fingerpush\_plugin/example/lib/main.dart 파일을 참고하여 플러그인을 적용합니다.

{% hint style="danger" %} <mark style="color:red;">푸시 테스트시에는 반드시 실제 기기를 사용해주세요.</mark>

<mark style="color:red;">시뮬레이터에서는 핑거푸시를 통해 푸시 수신 받을 수 없습니다.</mark>
{% endhint %}

### 프로젝트 설정하기

1\) Xcode 로 Bundle Identifier 와 Provisioning 변경해주세요.

2\) Capability 에 Background Mode 와 Push Notifications 를 추가해주세요.

![](/files/xj2kkVII7Qn8ufPD5U6D)

### iOS API Refeence

iOS API 는 아래 링크에서 확인 할 수 있습니다.

{% content-ref url="/pages/waHVao92YorJZvOfCgIz" %}
[iOS API Reference](/app-push/api-reference/ios.md)
{% endcontent-ref %}

## 예제 파일 적용

{% hint style="info" %}
예제 파일은 'fingerpush\_plugin > example > lib > main.dart' 에서 확인할 수 있습니다&#x20;
{% endhint %}

<figure><img src="/files/0mQhGIduIu0IZNLS0jtw" alt=""><figcaption></figcaption></figure>


---

# 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://developers.fingerpush.com/app-push/sdk-manual/flutter.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.
