Skip to content

Keyboard not showing on Android using new embedding API #30505

@chip2n

Description

@chip2n

Android keyboard does not show up when tapping a Flutter TextField using the new Android embedding API (io.flutter.embedding.android). There are a few similar issues (#19644, #21370, #21911), but those seem to refer to non-embedding scenarios. They are closed, and I think they're fixed as well since using the "old" API works for us (see below).

Are we using the new API wrong? It doesn't seem to work with io.flutter.embedding.android.FlutterActivity either, which handles the setup for us.

The reason we're experimenting with the new embedding API is that we need to use TextureView instead of SurfaceView so we can animate screen transitions, fades etc. Everything else seems to work fine so far.

I've tested on my Samsung S7 running Android 8.0 as well as an emulator running 6.0, and both have the same issue.

Steps to Reproduce

  1. Create a new Android application with an empty activity
  2. Add flutter to the app as described by https://github.com/flutter/flutter/wiki/Add-Flutter-to-existing-apps
  3. Initialize Flutter manually using the new embedding API

Here's how we initialize Flutter inside the MainActivity:

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.FrameLayout;

import io.flutter.embedding.android.FlutterView;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.FlutterShellArgs;
import io.flutter.embedding.engine.dart.DartExecutor;
import io.flutter.facade.Flutter;
import io.flutter.view.FlutterMain;

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Flutter.startInitialization(getApplicationContext());
        FlutterShellArgs flutterShellArgs = new FlutterShellArgs(new String[0]);
        FlutterMain.ensureInitializationComplete(getApplicationContext(), flutterShellArgs.toArray());

        FlutterEngine engine = new FlutterEngine(this);
        engine.getNavigationChannel().setInitialRoute("/");
        String appBundlePath = FlutterMain.findAppBundlePath(this);
        DartExecutor.DartEntrypoint entrypoint = new DartExecutor.DartEntrypoint(getResources().getAssets(), appBundlePath, "main");
        engine.getDartExecutor().executeDartEntrypoint(entrypoint);

        FlutterView flutterView = new FlutterView(this, FlutterView.RenderMode.surface);
        flutterView.attachToFlutterEngine(engine);

        FrameLayout container = findViewById(R.id.container);
        container.addView(flutterView);
    }
}

main.dart:

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        body: TextField(),
      ),
    );
  }
}

Logs

The InputMethodManager seems to cancel the call to showSoftInput for some reason. I guess DecorView has focus instead of the FlutterView?

2019-04-04 14:46:04.608 27910-27910/com.example.myapplication D/InputMethodManager: showSoftInput - cancel : mServedView != view : DecorView@47040e3[MainActivity]  view : io.flutter.embedding.android.FlutterView{e948ad1 VFE...C.. ........ 0,0-1080,1848}

Output of flutter doctor -v:

[✓] Flutter (Channel dev, v1.4.8, on Linux, locale en_US.UTF-8)
    • Flutter version 1.4.8 at /home/chip/flutter
    • Framework revision fbefd6b816 (3 days ago), 2019-04-01 10:58:30 -0700
    • Engine revision a850016454
    • Dart version 2.2.1 (build 2.2.1-dev.2.1 None)

[✓] Android toolchain - develop for Android devices (Android SDK version
    28.0.3)
    • Android SDK at /home/chip/android/sdk
    • Android NDK location not configured (optional; useful for native
      profiling support)
    • Platform android-28, build-tools 28.0.3
    • Java binary at: /opt/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build
      1.8.0_152-release-1248-b01)
    • All Android licenses accepted.

[!] Android Studio (version 3.3)
    • Android Studio at /opt/android-studio
    ✗ Flutter plugin not installed; this adds Flutter specific
      functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build
      1.8.0_152-release-1248-b01)

[!] Android Studio
    • Android Studio at /home/chip/android-studio
    ✗ Flutter plugin not installed; this adds Flutter specific
      functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[✓] Connected device (1 available)
    • SM G930F • ce081718cde4393e01 • android-arm64 • Android 8.0.0 (API 26)

! Doctor found issues in 2 categories.

Metadata

Metadata

Labels

platform-androidAndroid applications specifically

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions