我正在编写一个本机插件,在某些情况下,它必须在应用程序的颤动部分调用函数,用Dart编写.它是如何实现的,在这里解释:https: //flutter.io/platform-channels/
此外,从本机/平台部分向Dart /非本机调用方法的示例如下:https: //github.com/flutter/plugins/tree/master/packages/quick_actions
现在,这个例子非常好,以防平台只需要调用a method,即该调用没有返回任何/ void,但是如果它需要调用a function,即需要来自非native/Dart部分的返回值,我不能在互联网上找到了一个例子或文档.我相信它可以实现,因为在本机Java部分,有一个方法:
public void invokeMethod(String method,Object arguments,MethodChannel.Result callback)
所以,有一个callback对象可以从非本机部分返回值 - 或者,我在这里错了,目前无法从应用程序的非本机Dart部分返回值?
我正在 Flutter 应用程序中开发本机 Android 小部件。其中有刷新按钮,点击后我必须在 Flutter 代码中调用一个方法。我正在使用 Flutter Method Channel 进行通信,并且当应用程序处于前台时它工作正常。但是当应用程序最小化或关闭时它不起作用。我收到错误PlatformException(NO_ACTIVITY, null, null)。下面是我的代码。
安卓(AppWidgetProvider)
if (methodChannel == null && context != null) {
FlutterMain.startInitialization(context)
FlutterMain.ensureInitializationComplete(context, arrayOf())
// Instantiate a FlutterEngine.
val engine = FlutterEngine(context.applicationContext)
// Define a DartEntrypoint
val entrypoint: DartEntrypoint = DartEntrypoint.createDefault()
// Execute the DartEntrypoint within the FlutterEngine.
engine.dartExecutor.executeDartEntrypoint(entrypoint)
// Register Plugins when in background. When there
// is already an engine running, this will be ignored (although there will be some
// warnings in the …Run Code Online (Sandbox Code Playgroud)