Mah*_*Bkh 16 android flutter flutter-channel
我在我的颤振应用程序中使用本机 android 方法使用说明使用的文档
MethodChannel(flutterView, CHANNEL).setMethodCallHandler...
Run Code Online (Sandbox Code Playgroud)
但是在升级 flutter 之后,该MethodChannel功能不需要了flutterView,也没有flutterView了。
can not resolve method getFlutterView()
Run Code Online (Sandbox Code Playgroud)
我认为应该有一个创建频道的新教程
相反,它需要一些BinaryMessenger我不知道该给什么的。
这是不再工作的旧代码:
import io.flutter.app.FlutterActivity;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
public class MainActivity extends FlutterActivity {
private static final String CHANNEL = "samples.flutter.dev/battery";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
new MethodChannel(getFlutterView(), CHANNEL).setMethodCallHandler(
new MethodCallHandler() {
@Override
public void onMethodCall(MethodCall call, Result result) {
// Note: this method is invoked on the main thread.
// TODO
}
});
}
Run Code Online (Sandbox Code Playgroud)
Ric*_*eap 34
替换getFlutterView()为getFlutterEngine().getDartExecutor().getBinaryMessenger()。
您实际上并不需要.getBinaryMessenger()asDartExecutor实现BinaryMessenger本身(仅通过转发),但我认为指定信使更正确。
只需将此方法添加到您的类中:
BinaryMessenger getFlutterView(){
return getFlutterEngine().getDartExecutor().getBinaryMessenger();
}
Run Code Online (Sandbox Code Playgroud)
然后可以选择将所有(重构 > 重命名)“getFlutterView”替换为“getBinaryMessenger”以获得更具可读性的代码:
BinaryMessenger getBinaryMessenger(){
return getFlutterEngine().getDartExecutor().getBinaryMessenger();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7511 次 |
| 最近记录: |