import android.content.Context;
import android.view.View;
import android.widget.EditText;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import static io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.platform.PlatformView;
public class FlutterTextView implements PlatformView, MethodChannel.MethodCallHandler {
private final EditText textView;
private final MethodChannel methodChannel;
FlutterTextView(Context context, BinaryMessenger messenger, int id) {
textView = new EditText(context);
methodChannel = new MethodChannel(messenger, "plugins.cjs.test/textview_" + id);
methodChannel.setMethodCallHandler(this);
}
@Override
public View getView() {
return textView;
}
@Override
public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
switch (methodCall.method) {
case "setText":
setText(methodCall, result);
break;
default:
result.notImplemented();
}
}
private void setText(MethodCall methodCall, Result result) {
String text = (String) methodCall.arguments;
textView.setText(text);
result.success(null);
}
@Override
public void dispose() {}
}
这是Android平台代码。在Flutter小部件中嵌入EditText AndroidView时,软键盘无法显示。本地Flutter版本是1.2.1。
Flutter 1.2.1•频道Beta•https://github.com/flutter/flutter.git 框架•修订版8661d8aecd(3周前)•2019-02-14 19:19:53 -0800 发动机•版本3757390fa4 工具•Dart 2.1.2(内部版本2.1.2-dev.0.0 0a7dcf17eb)