Skip to content

Instantly share code, notes, and snippets.

@li9ht
Created December 1, 2021 02:40
Show Gist options
  • Save li9ht/05af863eccfe1008dde4b6ef3601d3a6 to your computer and use it in GitHub Desktop.
Save li9ht/05af863eccfe1008dde4b6ef3601d3a6 to your computer and use it in GitHub Desktop.
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
class MyFlutterActivity : FlutterActivity() {
private val CHANNEL = "com.example.myflutterapp/data"
val token = "dummy123"
override fun getCachedEngineId(): String {
return "my_engine_id"
}
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler {
call, result ->
if (call.method == "getUserToken") else {
result.notImplemented()
}
if (!token.isNullOrEmpty()) {
result.success(token)
} else {
result.error("UNAVAILABLE", "Battery level not available.", null)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment