1

我正在尝试从原生 android 打开一个颤振屏幕

所以我试图使用 MethodChannel 将数据返回到 dart 然后调用将导航到当前屏幕的方法

但我的代码不起作用

这是我的代码

@Override
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
    super.configureFlutterEngine(flutterEngine);
    String channelName = "app_channel";
    MethodChannel methodChannel = new MethodChannel(flutterEngine.getDartExecutor(), channelName);

    methodChannel.invokeMethod("openCaller", false, new MethodChannel.Result() {
        @Override
        public void success(@Nullable Object result) {
            Log.i("fromInvoke","success" + result.toString());
        }

        @Override
        public void error(String errorCode, @Nullable String errorMessage, @Nullable Object errorDetails) {
            Log.i("fromInvoke","failed" + errorMessage);

        }

        @Override
        public void notImplemented() {
            Log.i("fromInvoke","not implemented");

        }
    });
}

}

  static const platform =
      const MethodChannel('app_channel');

  @override
  void initState() {
    super.initState();
    platform.setMethodCallHandler(invokedMethods);

  }

这是一个全局函数

 Future<dynamic> invokedMethods(MethodCall methodCall) async {
    switch (methodCall.method) {
        case "openCaller":
          print("arrived to open caller");
          // Navigator.pushNamed(context, "/ring");
          
      }
  }
4

0 回答 0