added more comments to using_tabs example

This commit is contained in:
Nishant Srivastava
2017-08-26 00:35:35 -07:00
parent 94e51c66ce
commit a288e167be
4 changed files with 14 additions and 1 deletions

View File

@ -6,6 +6,7 @@ class First extends StatelessWidget {
return new Container(
child: new Center(
child: new Column(
// center the children
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Icon(

View File

@ -6,6 +6,7 @@ class Second extends StatelessWidget {
return new Container(
child: new Center(
child: new Column(
// center the children
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Icon(

View File

@ -6,6 +6,7 @@ class Third extends StatelessWidget {
return new Container(
child: new Center(
child: new Column(
// center the children
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Icon(

View File

@ -17,18 +17,22 @@ class MyHome extends StatefulWidget {
MyHomeState createState() => new MyHomeState();
}
// SingleTickerProviderStateMixin is used for animation
class MyHomeState extends State<MyHome> with SingleTickerProviderStateMixin {
// Create a tab controller
TabController controller;
@override
void initState() {
super.initState();
// Initialize the Tab Controller
controller = new TabController(length: 3, vsync: this);
}
@override
void dispose() {
// Dispose of the Tab Controller
controller.dispose();
super.dispose();
}
@ -40,10 +44,13 @@ class MyHomeState extends State<MyHome> with SingleTickerProviderStateMixin {
appBar: new AppBar(
// Title
title: new Text("Using Tabs"),
// Set the background color of the App Bar
backgroundColor: Colors.blue,
// Set the bottom property of the Appbar to include a Tab Bar
bottom: new TabBar(
tabs: <Tab>[
new Tab(
// set icon to the tab
icon: new Icon(Icons.favorite),
),
new Tab(
@ -53,16 +60,19 @@ class MyHomeState extends State<MyHome> with SingleTickerProviderStateMixin {
icon: new Icon(Icons.airport_shuttle),
),
],
// setup the controller
controller: controller,
),
),
// Body
// Set the TabBar view as the body of the Scaffold
body: new TabBarView(
// Add tabs as widgets
children: <Widget>[
new first_tab.First(),
new second_tab.Second(),
new third_tab.Third()
],
// set the controller
controller: controller,
));
}