mirror of
https://github.com/nisrulz/flutter-examples.git
synced 2025-05-29 05:22:46 +08:00
added more comments to using_tabs example
This commit is contained in:
@ -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(
|
||||
|
@ -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(
|
||||
|
@ -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(
|
||||
|
@ -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,
|
||||
));
|
||||
}
|
||||
|
Reference in New Issue
Block a user