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

  • Application
  • Authentication
  • User
  • Thing
  • In-app messages
  • Report

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 signup, login, logout 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) {
                "signup" -> {
                    val email = call.argument<String>("email")
                    val password = call.argument<String>("password")
                    val firstName = call.argument<String>("firstName")
                    val lastName = call.argument<String>("lastName")
                    if (email != null && password != null && firstName != null && lastName != null) {
                        signup(email, password, firstName, lastName, result)
                    }

                }
                "login" -> {
                    val email = call.argument<String>("email")
                    val password = call.argument<String>("password")
                    if (email != null && password != null) {
                        login(email, password, result)
                    }
                }
                "logout" -> {
                    logout(result)
                }
                "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 signup(email: String, password: String, firstName: String, lastName: String, result: MethodChannel.Result) {
        Copilot.getInstance().Manage.Sphere.Auth.signup().withCopilotAnalysisConsent(true).withEmailPassword(email, password, firstName, lastName).build()
            .execute(object : RequestListener<Void, SignupError> {
                override fun success(response: Void?) {
                    result.success(true)
                    //Your code here
                }

                override fun error(error: SignupError?) {
                    result.error("Signup failed, ${error?.debugMessage}", null, null)
                    //Your code here
                }
            })
    }

    private fun login(email: String, password: String, result: MethocChannel.Result) {
        Copilot.getInstance().Manage.Sphere.Auth.login().withEmailPassword(email, password).build().execute(object: RequestListener<Void, LoginError> {
            override fun success(response: Void?) {
                result.success(true)
                //Your code here
            }

            override fun error(error: LoginError?) {
                result.error("Login failed, ${error?.debugMessage}", null, null)
                //Your code here
            }
        })
    }

    private fun logout() {
        Copilot.getInstance().Manage.Sphere.Auth.logout().build().execute(object: RequestListener<Void, LogoutError> {
            override fun success(response: Void?) {
                result.success(true)
                //Your code here
            }

            override fun error(error: LogoutError?) {
                result.error("Logout failed, ${error?.debugMessage}", null, null)
                //Your code here
            }
        })
    }

    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