Repository: flutter
Issue: Focus gets lost on Android TV
Labels: a: text input,framework,f: material design,f: focus,P2,team-framework,triaged-framework

Run the code below. It displays two raised buttons and a text field and another raised button.

You can use the DPad (or the cursor keys if trying this on the simulator) to change the focus between both buttons. I changed their focus color to make this very obvious.  You can active buttons with RETURN. You cannot activate them using the SELECT button on the DPad but that's something I can fix myself and but part of the bug report.

However, once you focus the text field, you cannot get your focus back and the app ist stuck until you stop and start it again. A hot restart is not enough to free the focus.

Once the text field has the focus, the keyboard opens. On the simulator, it has a DONE button. Selecting that button (don't press ENTER, that's cheating) closes the keyboard – but only if the text field has no `onEditingComplete` callback! As a workaround, overriding `onSubmitted` is triggered on DONE and then the keyboard still closes.

I would expect that `onEditingComplete` also works.

Adding `f.requestFocus();` to the `onSubmitted` callback (`f` is the focus node of the third raised button) is a workaround to get the focus back:

```dart
TextField(
  onSubmitted: (s) => f.requestFocus();
),
```

If I now again enter the text field, this warnings are printed:
```
W/IInputConnectionWrapper( 4205): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 4205): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper( 4205): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 4205): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper( 4205): deleteSurroundingText on inactive InputConnection
W/IInputConnectionWrapper( 4205): commitText on inactive InputConnection
```
Something is wrong here.

My expectation is that the text field works as with a native Android app:

* when focused, it is displayed as "highlighted" but no keyboard opens
* when selected while focused, the keyboard opens, you can edit until DONE is selected and the keyboard closes while the text field stays focused
* while focused, you can use UP to move to the previous button (after moving the cursor to the beginning)
* while focused, you can use DOWN to move to the next button (after moving the cursor to the end)
* while focused, you can use LEFT and RIGHT to move the cursor. 


```dart
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key}) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final f = FocusNode();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            RaisedButton(
              focusColor: Colors.yellow,
              onPressed: () => print("1"),
              child: Text("Hallo!"),
            ),
            RaisedButton(
              focusColor: Colors.amber,
              onPressed: () => print("2"),
              child: Text("Hallo!"),
            ),
            SizedBox(
              width: 200,
              child: TextField(
                onSubmitted: (s) {
                  print(s);
                  f.requestFocus();
                },
              ),
            ),
            RaisedButton(
              focusNode: f,
              focusColor: Colors.lime,
              onPressed: () => print("3"),
              child: Text("Hallo!"),
            ),
          ],
        ),
      ),
    );
  }
}
```

<details>
  <summary>Logs</summary>

<!--
      Run your application with `flutter run --verbose` and attach all the
      log output below between the lines with the backticks. If there is an
      exception, please see if the error message includes enough information
      to explain how to solve the issue.
-->

```
```

<!--
     Run `flutter analyze` and attach any output of that command below.
     If there are any analysis errors, try resolving them before filing this issue.
-->

```
```

<!-- Finally, paste the output of running `flutter doctor -v` here. -->

```
[✓] Flutter (Channel master, v1.14.7-pre.38, on Mac OS X 10.14.6 18G103, locale de-DE)
    • Flutter version 1.14.7-pre.38 at /Users/sma/Work/flutter
    • Framework revision 92f7e16312 (vor 9 Stunden), 2020-01-29 17:51:31 -0800
    • Engine revision 6007c17fd2
    • Dart version 2.8.0 (build 2.8.0-dev.5.0 fc3af737c7)

 [✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at /Users/sma/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
    • All Android licenses accepted.

[✓] Android Studio (version 3.5)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 42.1.1
    • Dart plugin version 191.8593
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[✓] VS Code (version 1.41.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.7.1

[✓] Connected device (6 available)
    • AFTB               • 192.168.178.57:5555                  • android-arm    • Android 5.1.1 (API 22)
    • sdk google atv x86 • emulator-5554                        • android-x86    • Android 7.0 (API 24) (emulator)
```
</details>