title: Screen navigation in flutter
body: <p><strong>Update:</strong></p>
  <p>The app has two stateful widget screens: Home, and Search. Both screens have search boxes and a bottom navigation.</p>
  <p>The problem that needs to be solved is when a user taps the <strong>search box at the top of the home screen</strong>, the app should take them to the <strong>search screen without hiding the bottom navigation</strong> (just like what the eBay app does).</p>
  <p>I have tried calling the Search class when the user taps the search box on the Home screen. And this approach works. However, the new screen hides the navigation bar at the bottom.</p>
  <p>The following code handles the navigation between screens.</p>
  <pre><code>class Home extends StatefulWidget {
    @override
    _HomeState createState() =&gt; _HomeState();
  }
  class _HomeState extends State&lt;Home&gt; {
    int _currentIndex = 0;
    final GlobalKey&lt;NavigatorState&gt; _navigatorKey = GlobalKey&lt;NavigatorState&gt;();
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        body: Navigator(
            key: _navigatorKey,
            onGenerateRoute: (RouteSettings settings) {
              switch (settings.name) {
                case 'Search':
                  return MaterialPageRoute(builder: (context) =&gt; Search());
                default:
                  return MaterialPageRoute(builder: (context) =&gt; UserHome());
              }
            }),
         bottomNavigationBar: BottomNavigationBar(
          onTap: _onTap,
          items: [
            BottomNavigationBarItem(icon: Icon(Icons.home),title: Text('Home'))
            BottomNavigationBarItem(icon: Icon(Icons.search), title: Text('Search'))
          ],
        ),
      );
    }
  
    void _onTap(int tappedIndex) {
      setState(() =&gt; _currentIndex = tappedIndex);
      switch (tappedIndex) {
        case 0:
          _navigatorKey.currentState.pushReplacementNamed('Home');
          break;
        case 1:
          _navigatorKey.currentState.pushReplacementNamed('Search');
          break;
      }
    }
  
  }
  </code></pre>