Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class TabExample extends StatefulWidget {
- const TabExample({Key? key}) : super(key: key);
- @override
- _TabExampleState createState() => _TabExampleState();
- }
- class _TabExampleState extends State<TabExample> {
- int currentIndex = 0;
- @override
- Widget build(BuildContext context) {
- return DefaultTabController(
- length: 2,
- child: Builder(
- builder: (ctx) {
- final TabController tabController = DefaultTabController.of(ctx)!;
- tabController.addListener(() {
- if (!tabController.indexIsChanging) {
- setState(() => currentIndex = tabController.index);
- }
- });
- return Scaffold(
- appBar: AppBar(
- bottom: TabBar(
- tabs: [
- Tab(icon: Text('Tab ONE')),
- Tab(icon: Text('Tab TWO')),
- ],
- ),
- title: Text('Tabs Demo'),
- ),
- body: TabBarView(
- children: [
- _buildWidgetA(),
- _buildWidgetB(),
- ],
- ),
- );
- },
- ),
- );
- }
- Widget _buildWidgetA() {
- List<Widget> children = [];
- for (int i = 0; i < 20; i++) {
- children.add(
- Padding(
- padding: EdgeInsets.symmetric(vertical: 16),
- child: Container(
- height: 100,
- width: double.infinity,
- color: Colors.blue,
- ),
- ),
- );
- }
- return Scrollbar(
- isAlwaysShown: true,
- showTrackOnHover: true,
- child: SingleChildScrollView(
- primary: currentIndex == 0,
- child: Column(
- children: children,
- ),
- ),
- );
- }
- Widget _buildWidgetB() {
- List<Widget> children = [];
- for (int i = 0; i < 20; i++) {
- children.add(
- Padding(
- padding: EdgeInsets.symmetric(vertical: 16),
- child: Container(
- height: 100,
- width: double.infinity,
- color: Colors.green,
- ),
- ),
- );
- }
- return Scrollbar(
- isAlwaysShown: true,
- showTrackOnHover: true,
- child: SingleChildScrollView(
- primary: currentIndex == 1,
- child: Column(
- children: children,
- ),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement