Documentation

Documentation

YourOwn SetupYourOwn SDKYourOwn API
Sphere SetupSphere SDKSphere API
  • Resources

›Getting started for flutter

Getting started

  • Copilot.cx Mobile SDK
  • Importing the iOS SDK
  • Importing the Android SDK
  • SDK configuration

Getting started for flutter

  • Importing the Copilot.cx Android SDK for Flutter
  • Importing the Copilot.cx iOS SDK for Flutter
  • Interacting with the Copilot.cx SDK in Dart

Getting around

  • Hello Copilot

Reference

  • Manage session
  • Report
  • In-app messages
  • Authentication

Event reporting guide

  • Predefined events
  • Custom events

Appendix

  • Releases
  • Open source mapping

Importing the Copilot.cx Android SDK for Flutter

Setting up the android side for Copilot.cx

Please follow steps 1 through 5 in Importing the Android SDK

Creating CopilotModule to interface with Dart

  1. Create a CopilotModule class that will interact with the Dart code. Inside the setupMethodChannel function, we'll "capture" function calls from the dart side(with or without parameters) and point them to our native side fuctions. In this following example we're using the startSession, endSession and sendEvent functions.
class CopilotModule(
    private val flutterEngine: FlutterEngine,
    private val application: Application,
    private val context: Context,
) {

    private val channel = "myProjectChannelName"

    init {
        setupMethodChannel()
    }

    private fun setupMethodChannel() {
        MethodChannel(flutterEngine.dartExecutor.binaryMessenger, channel).setMethodCallHandler { call, result ->
            when (call.method) {
                "startSession" -> {
                    val userId = call.argument<String>("userId")
                    val isConsentGiven = call.argument<Boolean>("isConsentGiven")
                    if (userId != null && isConsentGiven != null) {
                        startSession(userId, isConsentGiven)
                    }
                }

                "endSession" -> {
                    endSession()
                }
                "sendEvent" -> {
                    val eventName = call.argument<String>("eventName")
                    val eventParams = call.argument<Map<String, String>>("eventParams")
                    if (eventName != null && eventParams != null) {
                        sendEvent(eventName, eventParams)
                    }
                }
                else -> {
                    result.notImplemented()
                }
            }
        }
    }

    private fun startSession(userId: String?, isConsentGiven: Boolean) {
        Copilot.getInstance().Manage.YourOwn.sessionStarted(userId, isConsentGiven)
    }

    private fun endSession() {
        Copilot.getInstance().Manage.YourOwn.sessionEnded()
    }

    private fun sendEvent(eventName: String, map: Map<String, String>) {
        val customEvent = CustomAnalyticsEvent(eventName, map)
        Copilot.getInstance().Report.logEvent(customEvent)
    }
}
  1. Create a FlutterApplication class and init the Copilot.Cx Sdk inside the onCreate function. Don't forget to replace the application class name inside the AndroidManifest.xml file.
class MyApplication : FlutterApplication() {
    override fun onCreate() {
        super.onCreate()
        Copilot.setup(this, listOf(FirebaseEventLogProvider(this)))
    }
}
  1. inside your MainActivity add an instance for CopilotModule and initialize it inside configureFlutterEngine and setup the Copilot.cx SDK with the EventLogProvider
class MainActivity: FlutterActivity() {
    lateinit var copilotModule : CopilotModule

    override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
        ...
        copilotModule = CopilotModule(flutterEngine,application, this)
        ...
    }
}
← SDK configurationImporting the Copilot.cx iOS SDK for Flutter →
  • Creating CopilotModule to interface with Dart
Copilot
Mail: hello@copilot.cx
Call: (212).398.0001
© Copilot.cx 2025