Setup

Use AATKit with Flutter app

Usage of Flutter Binding in your project

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

Dart integration

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

  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
  1. Paste copied files to the flutter-binding/android/app/src/main/kotlin/your/package/name directory in your project.

  2. Edit configureFlutterEngine method in your Android project's MainActivity class, like:

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

  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
  1. Paste copied files to the flutter-binding/ios/Runner directory in your project.

  2. Edit application didFinishLaunchingWithOptions method in your iOS project's AppDelegate class, like:

@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>")
      }

      ...
  }
}

Last updated