Skip to content

Instantly share code, notes, and snippets.

@vishna
Last active December 14, 2019 11:46
Show Gist options
  • Save vishna/5f42dd5df670b61c0898500512d4b175 to your computer and use it in GitHub Desktop.
Save vishna/5f42dd5df670b61c0898500512d4b175 to your computer and use it in GitHub Desktop.
import io.flutter.embedding.android.FlutterActivity // there are two FlutterActivities :|
import io.flutter.plugins.GeneratedPluginRegistrant // this is not seen by IntelliJ by works ¯\_(ツ)_/¯
typealias FlutterCallback = (methodCall: MethodCall, result: MethodChannel.Result) -> Unit
class FlutterPathActivity : FlutterActivity() {
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
infix fun String.handles(callHandler: FlutterCallback) {
MethodChannel(flutterEngine.dartExecutor, this).setMethodCallHandler(callHandler)
}
GeneratedPluginRegistrant.registerWith(flutterEngine) // is this handled by default, I guess no?
val initialPath = intent.getStringExtra(ConstantsBase.KEY_FLUTTER_PATH) // avoid initalRoute
navChannel handles navCallback(initialPath)
}
}
private const val navChannel = "com.eyeem.app/nav"
private fun navCallback(initialPath: String): FlutterCallback {
return { methodCall, result ->
when (methodCall.method) {
"getInitialPath" -> result.success(initialPath)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment