title: Flutter navigate to specific tab in other page
body: <p>I am trying to navigate from one page to another page and set index of a tab bar.</p>
  
  <p>Here is my code in the first page:</p>
  
  <pre><code>GestureDetector(
  onTap: () { Navigator.push(
  context,
  MaterialPageRoute(builder: (context) =&gt; ProductPage()),
  ); },
  child: Container(
  color: Colors.blueGrey,
  )),
  </code></pre>
  
  <p>And in the other page (ProductPage):</p>
  
  <pre><code>class ProductPage extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
  return DefaultTabController(
      length: 3,
      child: Scaffold(
        appBar: AppBar(
      backgroundColor: Color.fromRGBO(65,102,60,1,
      ),
          bottom: TabBar(
            isScrollable: true,
            indicatorColor: Colors.white,
            tabs: [
              Tab(icon: Text('First')),
              Tab(icon: Text('Second')),
              Tab(icon: Text('Third')),
            ],
          ),
        ),
        body: TabBarView(
          children: [
            FirstTab(),
            SecondTab(),
            ThirdTab(),
          ],
        ),
      ),
  );
    }
  }
  </code></pre>
  
  <p>Now it always opens the first tab but I want it to open SecondTab. </p>
  
  <p>I have tried this:</p>
  
  <pre><code>MaterialPageRoute(builder: (context) =&gt; ProductPage(SecondTab)),
  </code></pre>
  
  <p>But it doesn’t work. How can I do to fix this?</p>