Last active
April 5, 2019 20:47
-
-
Save shihaohong/ba4512652c2bf1b638821afe68c5729d to your computer and use it in GitHub Desktop.
running implementation of behavior
This file contains 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(new MyApp()); | |
class MyApp extends StatefulWidget { | |
@override | |
_MyAppState createState() => new _MyAppState(); | |
} | |
class _TabBarContainer extends StatelessWidget { | |
final TabController tabController; | |
_TabBarContainer({ | |
this.tabController, | |
}); | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
color: Colors.blue, | |
child: Column( | |
children: <Widget>[ | |
TabBar( | |
controller: tabController, | |
tabs: [ | |
Tab(text: "Yellow"), | |
Tab(text: "Grey"), | |
], | |
), | |
Expanded( | |
flex: 1, | |
child: TabBarView( | |
controller: tabController, | |
children: <Widget>[ | |
Container(color: Colors.yellow), | |
Container(color: Colors.grey), | |
], | |
), | |
) | |
], | |
), | |
); | |
} | |
} | |
class _MyAppState extends State<MyApp> with TickerProviderStateMixin { | |
TabController _tabController; | |
List<Widget> _widgetList; | |
int _selectedIndex = 0; | |
@override | |
void initState() { | |
super.initState(); | |
_tabController = TabController(length: 2, vsync: this); | |
_widgetList = [ | |
Container(color: Colors.red), | |
_TabBarContainer(tabController: _tabController), | |
Container(color: Colors.green), | |
Container(color: Colors.indigo), | |
]; | |
} | |
@override dispose() { | |
_tabController.dispose(); | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: new Scaffold( | |
body: _widgetList.elementAt(_selectedIndex), | |
bottomNavigationBar: BottomNavigationBar( | |
currentIndex: _selectedIndex, | |
onTap: (int index) { | |
setState(() { | |
_selectedIndex = index; | |
}); | |
}, | |
type: BottomNavigationBarType.fixed, | |
items: <BottomNavigationBarItem>[ | |
BottomNavigationBarItem(icon: Icon(Icons.add), title: Text("Tab")), | |
BottomNavigationBarItem(icon: Icon(Icons.add), title: Text("Tab")), | |
BottomNavigationBarItem(icon: Icon(Icons.add), title: Text("Tab")), | |
BottomNavigationBarItem(icon: Icon(Icons.add), title: Text("Tab")), | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment