Created
April 5, 2019 20:47
-
-
Save shihaohong/1909464287ce2f23b74088cf95ce02a6 to your computer and use it in GitHub Desktop.
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 _mainTabController; | |
TabController _nestedTabController; | |
@override | |
void initState() { | |
super.initState(); | |
_mainTabController = TabController(length: 4, vsync: this); | |
_nestedTabController = TabController(length: 2, vsync: this); | |
} | |
@override | |
dispose() { | |
_mainTabController.dispose(); | |
_nestedTabController.dispose(); | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: new Scaffold( | |
appBar: AppBar( | |
title: Text('Exception for Nested Tabs'), | |
bottom: TabBar( | |
controller: _mainTabController, | |
tabs: <Widget>[ | |
Tab(icon: Icon(Icons.add), text: "Tab"), | |
Tab(icon: Icon(Icons.add), text: "Tab"), | |
Tab(icon: Icon(Icons.add), text: "Tab"), | |
Tab(icon: Icon(Icons.add), text: "Tab"), | |
], | |
), | |
), | |
body: TabBarView( | |
controller: _mainTabController, | |
children: <Widget>[ | |
Container(color: Colors.red), | |
_TabBarContainer(tabController: _nestedTabController), | |
Container(color: Colors.green), | |
Container(color: Colors.indigo), | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment