It will show you as below, you can click the tab on the top or scroll to change the content. The top part is the TabBar, the bottom part is the TabBarView. You should know, the order and the location aren't mattered between TabBar and TabBarView, but they should be in the vertical direction.
Constructor
You can see the code in this example, the three important class are DefaultTabController, TabBar,TabBarView. The TabBar is a bit difficult for us. So let's look at it.
It will show the picture as below, you should know the indicatorColor set the color of the bottom line, the indicatorWeight set the height of the line, the indicatorSize set the type of the line.
If we use the indicatorPadding, it will show as follows .
I will use many parameters in the example, let's look at the code as follows.
TabBar _tabBarLabel() => TabBar(
tabs: _tabTwoParameters(),
labelColor: RED,
labelPadding: EdgeInsets.symmetric(vertical: 10),
labelStyle: TextStyle(fontSize: 20),
unselectedLabelColor: BLUE_LIGHT,
unselectedLabelStyle: TextStyle(fontSize: 14),
onTap: (index) {
var content = "";
switch (index) {
case 0:
content = "Home";
break;
case 1:
content = "Articles";
break;
case 2:
content = "User";
break;
default:
content = "Other";
break;
}
print("You are clicking the $content");
},
);
It will show you as below.
if you click the tab, it will print the contents as follows.
I/flutter ( 4741): You are clicking the User
I/flutter ( 4741): You are clicking the Articles
I/flutter ( 4741): You are clicking the Home
Conclusion
So far, we have learned our TabBarView and TabBar. There are so many custom indicators here that you can choose. The most important thing you should care is that some parameters aren't used at the same time.