Created
April 6, 2019 21:50
-
-
Save shihaohong/4e0864b55d7482c7f080fe81047bcdec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: TabBarTest(title: 'Test Tab Bar'), | |
); | |
} | |
} | |
class TabBarTest extends StatefulWidget { | |
TabBarTest({Key key, this.title}) : super(key: key); | |
final String title; | |
@override | |
_TabBarTestState createState() => _TabBarTestState(); | |
} | |
class _TabBarTestState extends State<TabBarTest> with TickerProviderStateMixin { | |
TabController _tabController; | |
List<Widget> _tabs = [ | |
Container(decoration: BoxDecoration(color: Colors.red)), | |
Container(decoration: BoxDecoration(color: Colors.blue)), | |
Container(decoration: BoxDecoration(color: Colors.greenAccent)), | |
]; | |
@override | |
void initState() { | |
_tabController = TabController(vsync: this, length: 3); | |
super.initState(); | |
} | |
@override | |
void dispose() { | |
_tabController.dispose(); | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(title: Text('tabBarTesting')), | |
body: TabBarView(children: _tabs, controller: _tabController), | |
bottomNavigationBar: TabBar(controller: _tabController, tabs: const <Tab>[ | |
Tab(icon: Icon(Icons.person), text: 'Home'), | |
Tab(icon: Icon(Icons.school), text: 'Grades'), | |
Tab(icon: Icon(Icons.settings), text: 'Settings') | |
]), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment