Move to next Tab on Button Click in Flutter

This Article is posted by seven.srikanth at 11/28/2018 7:25:59 PM



<p id="e5c07b;](_MyHomePageState();" color:="" color:=>In this post, I've shared the code which will help you to move to next tab on button click in Flutter. Here is the final main.dart code. All you need to do is to, copy paste this code into your newly created flutter project and run it. color: rgb(187, 187, 187); background-color: rgb(40, 44, 52); font-family: Consolas, "Courier New", monospace; font-size: 14px; line-height: 19px; white-space: pre-wrap;](color: #c678dd;](import color: #98c379;]('package:flutter/material.dart'; color: #c678dd;](void color: #61afef;](main() => color: #61afef;](runApp(color: #e5c07b;](MyApp()); color: #c678dd;](class color: #e5c07b;](MyApp color: #c678dd;](extends color: #e5c07b;](StatelessWidget { color: #c678dd;](@override color: #e5c07b;](Widget color: #61afef;](build(color: #e5c07b;](BuildContext context) { color: #c678dd;](final appTitle color: #56b6c2;](= color: #98c379;]('Tabs Demo'; color: #c678dd;](return color: #e5c07b;](MaterialApp( titlecolor: #c678dd;](: appTitle, homecolor: #c678dd;](: color: #e5c07b;](MyHomePage(titlecolor: #c678dd;](: appTitle), ); }} color: #c678dd;](class color: #e5c07b;](MyHomePage color: #c678dd;](extends color: #e5c07b;](StatefulWidget { color: #c678dd;](final color: #e5c07b;](String title; color: #c678dd;](const color: #e5c07b;](MyHomePage({color: #e5c07b;](Key key, color: #e06c75;](this.title}) color: #c678dd;](: color: #e06c75;](super(keycolor: #c678dd;](: key); color: #c678dd;](@override color: #e5c07b;](Statecolor: #56b6c2;]( color: #61afef;](createState() }</p> <p id="61afef;](animateTo(_tabIndex);" color:= _tabController="" color:="" color:="" color:="" lengthcolor:="" color:="" _tabIndex="" _tabController.index="" _tabController.color:="">color: #c678dd;](class color: #e5c07b;](_MyHomePageState color: #c678dd;](extends color: #e5c07b;](Statecolor: #56b6c2;]( color: #c678dd;](with color: #e5c07b;](SingleTickerProviderStateMixin { color: #c678dd;](int _tabIndex color: #56b6c2;](= color: #d19a66;](0; color: #e5c07b;](TabController _tabController; color: #c678dd;](@override color: #c678dd;](void color: #61afef;](initState() color: #c678dd;](void color: #61afef;](_toggleTab() color: #c678dd;](@override color: #e5c07b;](Widget color: #61afef;](build(color: #e5c07b;](BuildContext context) { color: #c678dd;](return color: #e5c07b;](MaterialApp( homecolor: #c678dd;](: color: #e5c07b;](Scaffold( appBarcolor: #c678dd;](: color: #e5c07b;](AppBar( titlecolor: #c678dd;](: color: #e5c07b;](Text(widget.title), bottomcolor: #c678dd;](: color: #e5c07b;](TabBar( controllercolor: #c678dd;](: _tabController, tabscolor: #c678dd;](: [ color: #e5c07b;](Tab(textcolor: #c678dd;](: color: #98c379;]('Tab 1'), color: #e5c07b;](Tab(textcolor: #c678dd;](: color: #98c379;]('Tab 2'), color: #e5c07b;](Tab(textcolor: #c678dd;](: color: #98c379;]('Tab 3'), ], ), ), bodycolor: #c678dd;](: color: #e5c07b;](TabBarView( controllercolor: #c678dd;](: _tabController, childrencolor: #c678dd;](: [ color: #e5c07b;](Card( childcolor: #c678dd;](: color: #e5c07b;](Column( mainAxisSizecolor: #c678dd;](: color: #e5c07b;](MainAxisSize.min, childrencolor: #c678dd;](: color: #56b6c2;]([ color: #e5c07b;](ListTile( leadingcolor: #c678dd;](: color: #e5c07b;](Icon(color: #e5c07b;](Icons.album), titlecolor: #c678dd;](: color: #e5c07b;](Text(color: #98c379;]('Hello 1'), subtitlecolor: #c678dd;](: color: #e5c07b;](Text(color: #98c379;]('Click on Next Button to go to Tab 2.'), ), color: #e5c07b;](ButtonTheme.color: #61afef;](bar( color: #7f848e;font-style: italic;](// make buttons use the appropriate styles for cards childcolor: #c678dd;](: color: #e5c07b;](ButtonBar( childrencolor: #c678dd;](: color: #56b6c2;]([ color: #e5c07b;](FlatButton( childcolor: #c678dd;](: color: #c678dd;](const color: #e5c07b;](Text(color: #98c379;]('Next'), onPressedcolor: #c678dd;](: _toggleTab, ), ], ), ), ], ), ), color: #e5c07b;](Card( childcolor: #c678dd;](: color: #e5c07b;](Column( mainAxisSizecolor: #c678dd;](: color: #e5c07b;](MainAxisSize.min, childrencolor: #c678dd;](: color: #56b6c2;]([ color: #e5c07b;](ListTile( leadingcolor: #c678dd;](: color: #e5c07b;](Icon(color: #e5c07b;](Icons.album), titlecolor: #c678dd;](: color: #e5c07b;](Text(color: #98c379;]('Hello 2'), subtitlecolor: #c678dd;](: color: #e5c07b;](Text(color: #98c379;]('Click on Next Button to go to Tab 3'), ), color: #e5c07b;](ButtonTheme.color: #61afef;](bar( color: #7f848e;font-style: italic;](// make buttons use the appropriate styles for cards childcolor: #c678dd;](: color: #e5c07b;](ButtonBar( childrencolor: #c678dd;](: color: #56b6c2;]([ color: #e5c07b;](FlatButton( childcolor: #c678dd;](: color: #c678dd;](const color: #e5c07b;](Text(color: #98c379;]('Next'), onPressedcolor: #c678dd;](: _toggleTab, ), ], ), ), ], ), ), color: #e5c07b;](Card( childcolor: #c678dd;](: color: #e5c07b;](Column( mainAxisSizecolor: #c678dd;](: color: #e5c07b;](MainAxisSize.min, childrencolor: #c678dd;](: color: #56b6c2;]([ color: #e5c07b;](ListTile( leadingcolor: #c678dd;](: color: #e5c07b;](Icon(color: #e5c07b;](Icons.album), titlecolor: #c678dd;](: color: #e5c07b;](Text(color: #98c379;]('Hello 3'), subtitlecolor: #c678dd;](: color: #e5c07b;](Text(color: #98c379;]('The End'), ), color: #e5c07b;](ButtonTheme.color: #61afef;](bar( color: #7f848e;font-style: italic;](// make buttons use the appropriate styles for cards childcolor: #c678dd;](: color: #e5c07b;](ButtonBar( childrencolor: #c678dd;](: color: #56b6c2;]([ color: #e5c07b;](FlatButton( childcolor: #c678dd;](: color: #c678dd;](const color: #e5c07b;](Text(color: #98c379;]('Done'), onPressedcolor: #c678dd;](: _toggleTab, ), ], ), ), ], ), ), ], ), )); }}</p> <p>Hope this is helpful. Thanks,Srikanth</p>


Tags: Move to next Tab on Button Click in Flutter








1 Comments
Login to comment.
Recent Comments

ashokmedidi9 at 11/26/2020

Tanks a lot ..mate really saved my time

Login to Reply.