gpt4 book ai didi

android - 我可以从 Dart 调用 Kotlin 函数吗

转载 作者:IT王子 更新时间:2023-10-29 06:51:59 25 4
gpt4 key购买 nike

使用 Flutter,可以通过类似以下方式调用 kotlin/swift 函数:

file.dart:

static const platform = const MethodChannel('my.test.flutterapp/battery');
final int result = await platform.invokeMethod('getBatteryLevel');

file.kt:

private val CHANNEL = "my.test.flutterapp/battery"
MethodChannel(flutterView, CHANNEL).setMethodCallHandler { call, result ->
if (call.method == "getBatteryLevel") {
...
} else {
result.notImplemented()
}
}

是否有类似于从标准 Dart 应用调用 Kotlin 函数的东西,例如 Dart 控制台应用!

最佳答案

https://flutter.io/developing-packages/

Plugin packages: A specialized Dart package which contain an API written in Dart code combined with a platform-specific implementation for Android (using Java or Kotlin), and/or for iOS (using ObjC or Swift). A concrete example is the battery plugin package.

...

flutter create --template=plugin -i swift -a kotlin hello

关于android - 我可以从 Dart 调用 Kotlin 函数吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49065809/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com