> For the complete documentation index, see [llms.txt](https://aatkit.gitbook.io/aatkit-flutter-binding/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://aatkit.gitbook.io/aatkit-flutter-binding/start/setup.md).

# Setup

Use AATKit with Flutter app

### Usage of Flutter Binding in your project <a href="#markdown-header-using-flutter-binding-in-your-project" id="markdown-header-using-flutter-binding-in-your-project"></a>

Basing on this project, you can integrate AATKit within your Flutter app. To achieve it, please follow the instructions below.

### Dart integration <a href="#markdown-header-dart-integration" id="markdown-header-dart-integration"></a>

All needed dart files are included to the `flutter-binding/lib/aatkit` directory. Copy and paste this folder to the `lib` directory in your project.

### Android integration <a href="#markdown-header-android-integration" id="markdown-header-android-integration"></a>

1. Find `flutter-binding/android/app/src/main/kotlin/com/addapttr/flutter_binding` directory.
2. There are Kotlin files required by the native Android project to let AATKit works correctly. Copy the files from the list:

```
AATKitBinding.kt
AATKitListener.kt
NativeBannerView.kt
NativeViewFactory.kt
```

3. Paste copied files to the `flutter-binding/android/app/src/main/kotlin/your/package/name` directory in your project.
4. Edit `configureFlutterEngine` method in your Android project's `MainActivity` class, like:

```kotlin
class MainActivity: FlutterActivity() {
    companion object {
        const val BANNER_VIEW_TYPE = "<aatkit-banner-view>"
    }

    var aatKitBinding: AATKitBinding? = null

    ...

    override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
        ...

        //Add code below to your configureFlutterEngine to allow calling AATKitBinding methods from
        //dart code.
        aatKitBinding = AATKitBinding(application, this)
        val methodChannel = MethodChannel(
            flutterEngine.dartExecutor.binaryMessenger,
            AATKitBinding.AATKIT_CHANNEL
        )
        aatKitBinding?.handleMethodChannelCalls(methodChannel)

        //Add code below to your configureFlutterEngine to allow creating banner widget
        flutterEngine
            .platformViewsController
            .registry
            .registerViewFactory(BANNER_VIEW_TYPE, NativeViewFactory(methodChannel))
    }

    ...

    override fun onResume() {
        super.onResume()
        aatKitBinding?.onActivityResume()
    }

    override fun onPause() {
        super.onPause()
        aatKitBinding?.onActivityPause()
    }
}
```

### iOS integration <a href="#markdown-header-ios-integration" id="markdown-header-ios-integration"></a>

1. Find `flutter-binding/ios/Runner` directory.
2. There are Swift files required by the native iOS project to let AATKit works correctly. Copy the files from the list:

```
AATKitBinding.swift
AATKitDelegate.swift
AATKitNativeBannerView.swift
AATKitNativeViewFactory.swift
```

3. Paste copied files to the `flutter-binding/ios/Runner` directory in your project.
4. Edit *application* `didFinishLaunchingWithOptions` method in your iOS project's `AppDelegate` class, like:

```swift
@objc class AppDelegate: FlutterAppDelegate {    
    override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
      if let controller = window?.rootViewController as? FlutterViewController {
          let methodChannel = FlutterMethodChannel(name: AATKitBinding.channel, binaryMessenger: controller.binaryMessenger)

          let binding = AATKitBinding(flutterViewController: controller)
          binding.handleMethodChannelCalls(methodChannel: methodChannel)

          weak var registrar = self.registrar(forPlugin: "aatkit-binding")
          let factory = AATKitNativeViewFactory(messenger: registrar!.messenger(), methodChannel: methodChannel)
          self.registrar(forPlugin: "<aatkit-binding>")!.register(
              factory,
              withId: "<aatkit-banner-view>")
      }

      ...
  }
}
```
