5
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 • 频道测试版 • 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)

4

0 回答 0