title: How to navigate to a different page on a different tab using CupertinoTabBar?
body: <p>I have two tabs - Tab1 and Tab2. Tab1 has 3 pages - Tab1 Page1, Tab1 Page2, Tab1 Page3.</p>
  <p>I want to be able to navigate from Tab2 to Tab1 Page2. I can switch the index using <code>controller.index = 0</code> but am not sure how to navigate to to Page2 of this tab. What is a clean solution for this?</p>
  <p><a href="https://i.stack.imgur.com/Dp8Zu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Dp8Zu.png" alt="enter image description here" /></a></p>
  <pre><code>// main.dart
  void main() =&gt; runApp(MyApp());
  
  class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        title: 'Cupertino Tab Bar Demo',
        theme: ThemeData(primarySwatch: Colors.blue, textTheme: TextTheme()),
        home: SafeArea(child: Scaffold(body: MyHomePage('Cupertino Tab Bar Demo Home Page'))),
      );
    }
  }
  
  class MyHomePage extends StatefulWidget {
    MyHomePage(this.title);
  
    final String title;
  
    @override
    _MyHomePageState createState() =&gt; _MyHomePageState();
  }
  
  class _MyHomePageState extends State&lt;MyHomePage&gt; {
    var navigatorKeyList = [GlobalKey&lt;NavigatorState&gt;(), GlobalKey&lt;NavigatorState&gt;()];
    var currentIndex = 0;
    var controller = CupertinoTabController(initialIndex: 0);
  
    @override
    Widget build(BuildContext context) {
      return CupertinoTabScaffold(
        controller: controller,
        tabBar: CupertinoTabBar(
          onTap: (index) {
            if (currentIndex == index) {
              // Navigate to the tab's root route
              navigatorKeyList[index].currentState.popUntil((route) {
                return route.isFirst;
              });
            }
            currentIndex = index;
          },
          items: [
            BottomNavigationBarItem(title: Text('Tab 1'), icon: Icon(Icons.ac_unit)),
            BottomNavigationBarItem(title: Text('Tab 2'), icon: Icon(Icons.ac_unit)),
          ],
        ),
        tabBuilder: (BuildContext _, int index) {
          switch (index) {
            case 0:
              return CupertinoTabView(
                navigatorKey: navigatorKeyList[index],
                routes: {
                  '/': (context) =&gt; WillPopScope(
                        child: Page1(),
                        onWillPop: () =&gt; Future&lt;bool&gt;.value(true),
                      ),
                  'page1b': (context) =&gt; Page1b(),
                  'page1c': (context) =&gt; Page1c(),
                },
              );
            case 1:
              return CupertinoTabView(
                navigatorKey: navigatorKeyList[index],
                routes: {
                  '/': (context) =&gt; WillPopScope(
                        child: Page2(controller),
                        onWillPop: () =&gt; Future&lt;bool&gt;.value(true),
                      )
                },
              );
            default:
              return Text('Index must be less than 2');
          }
        },
      );
    }
  }
  
  // Tab1 Page1
  class Page1 extends StatelessWidget {
    Page1();
  
    @override
    Widget build(BuildContext context) {
      return BaseContainer(
        Column(
          children: &lt;Widget&gt;[
            Container(
              child: Text(
                'Tab1',
                style: Theme.of(context).textTheme.headline4,
              ),
            ),
            FlatButton(
              color: Colors.lightGreen,
              child: Text('Go to Tab1 Page2'),
              onPressed: () {
                Navigator.pushNamed(context, 'page1b');
              },
            )
          ],
        ),
      );
    }
  }
  
  // Tab1 Page2
  class Page1b extends StatelessWidget {
    Page1b();
  
    @override
    Widget build(BuildContext context) {
      return BaseContainer(
        Column(
          children: &lt;Widget&gt;[
            Container(
              child:
                  Text('Tab1 Page2', style: Theme.of(context).textTheme.headline4),
            ),
            FlatButton(
              color: Colors.lightGreen,
              child: Text('Go to Tab1 Page3'),
              onPressed: () {
                Navigator.pushNamed(context, 'page1c');
              },
            )
          ],
        ),
      );
    }
  }
  
  // Tab2
  class Page2 extends StatelessWidget {
    final CupertinoTabController controller; 
  
    const Page2(this.controller);
  
    @override
    Widget build(BuildContext context) {
      return BaseContainer(
        Column(
          children: &lt;Widget&gt;[
            Container(
              child: Text(
                'Tab2',
                style: Theme.of(context).textTheme.headline4,
              ),
            ),
            FlatButton(
              color: Colors.lightGreen,
              child: Text('Go to Tab1 Page2 (TODO)'),
              onPressed: () {
                // TODO I want this to go to Tab1 Page2
                this.controller.index = 0;
                Navigator.of(context).pushNamed('page1b');
              },
            )
          ],
        ),
      );
    }
  }
  </code></pre>