Repository: flutter
Issue: Keyboard opens and hides when text field is focussed while navigating back and forth using inner navigator.
Labels: a: text input,framework,f: routes,f: focus,has reproducible steps,P2,found in release: 2.5,found in release: 2.6,team-framework,triaged-framework

I have inner Navigator on the HostScreen. When I add some screen with a text field and then request focus on it (on tap on the field) keyboard appears. Then, I want to hide it. So I tap on the free area. Keyboard hides. Then I tap on the "Forward" button and make a push into the inner navigator one more screen. At this moment, the keyboard appears and then immediately disappears (This is the problem). When I tap the "Back" button, the text field acquires focus, and the keyboard appears. 

Code sample:

main.dart

```
import 'package:flutter/material.dart';
import 'package:flutter_app_for_issues/pages/host_screen.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: const Text('Hello World'),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          Navigator.of(context).push(
            MaterialPageRoute(
              builder: (context) {
                return const HostScreen();
              },
            ),
          );
        },
      ),
    );
  }
}

```


host_screen.dart

```
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_app_for_issues/components/navigation/routes.dart';
import 'package:flutter_app_for_issues/pages/steps/numeric_page.dart';

class HostScreen extends StatefulWidget {
  const HostScreen({Key? key}) : super(key: key);

  @override
  _HostScreenState createState() => _HostScreenState();
}

class _HostScreenState extends State<HostScreen> {
  final GlobalKey<NavigatorState> navigatorKey = GlobalKey();

  int pageCounter = 1;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.red,
      body: SafeArea(
        child: GestureDetector(
          onTap: () {
            if (FocusScope.of(context).enclosingScope != null) {
              FocusScope.of(context).unfocus();
            }
          },
          child: Column(
            children: [
             Container(
                color: Colors.blue,
                width: double.infinity,
                height: 50,
              ),
              Expanded(
                child: Navigator(
                  key: navigatorKey,
                  onGenerateRoute: (settings) {
                    return InstanceRoute(
                      page: NumericPage(
                        numberOfPage: pageCounter,
                      ),
                    );
                  },
                ),
              ),
              Row(
                children: [
                  Expanded(
                    child: TextButton(
                      child: const Text('Back'),
                      onPressed: () {
                        if (navigatorKey.currentState?.canPop() ?? false) {
                          navigatorKey.currentState?.pop();
                          --pageCounter;
                        } else {
                          Navigator.pop(context);
                        }
                      },
                    ),
                  ),
                  Expanded(
                    child: TextButton(
                      child: const Text('Forward'),
                      onPressed: () {
                        ++pageCounter;
                        navigatorKey.currentState?.push(
                          InstanceRoute(
                            page: NumericPage(
                              numberOfPage: pageCounter,
                            ),
                          ),
                        );
                      },
                    ),
                  ),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }
}

```


numeric_page.dart

```
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

class NumericPage extends StatefulWidget {
  final int numberOfPage;

  const NumericPage({
    Key? key,
    required this.numberOfPage,
  }) : super(key: key);

  @override
  _NumericPageState createState() => _NumericPageState();
}

class _NumericPageState extends State<NumericPage> {
  final textController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Material(
      child: Column(
        children: [
          const SizedBox(height: 16),
          Text('Page #${widget.numberOfPage}'),
          const SizedBox(height: 16),
          TextField(
            controller: textController,
          ),
        ],
      ),
    );
  }
}

```


I can fix it by moving GestureDetector with keyboard hide logic into NumericScreen. But in the case when the inner navigator is not expanded on the full screen there are areas left without hiding the keyboard logic handle (e.g. blue Container).