Created
July 18, 2019 16:04
-
-
Save brianegan/3ab2f435292c1e42d6d590ab15df82f3 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(TabBarDemo()); | |
| } | |
| class TabBarDemo extends StatefulWidget { | |
| @override | |
| _TabBarDemoState createState() => _TabBarDemoState(); | |
| } | |
| class _TabBarDemoState extends State<TabBarDemo> { | |
| final strings1 = List<String>.generate(10000, (i) => "Tab 1, Item $i"); | |
| final strings2 = List<String>.generate(10000, (i) => "Tab 2, Item $i"); | |
| @override | |
| Widget build(BuildContext context) { | |
| return MaterialApp( | |
| home: DefaultTabController( | |
| length: 2, | |
| child: Scaffold( | |
| appBar: AppBar( | |
| bottom: TabBar( | |
| tabs: [ | |
| Tab(icon: Icon(Icons.directions_car)), | |
| Tab(icon: Icon(Icons.directions_transit)), | |
| ], | |
| ), | |
| title: Text('Tabs Demo'), | |
| ), | |
| body: TabBarView( | |
| children: [ | |
| MyList( | |
| items: strings1, | |
| key: PageStorageKey('list1'), | |
| ), | |
| MyList( | |
| items: strings2, | |
| key: PageStorageKey('list2'), | |
| ), | |
| ], | |
| ), | |
| ), | |
| ), | |
| ); | |
| } | |
| } | |
| class MyList extends StatelessWidget { | |
| final List<String> items; | |
| MyList({Key key, @required this.items}) | |
| : super(key: key); | |
| @override | |
| Widget build(BuildContext context) { | |
| return ListView.builder( | |
| itemCount: items.length, | |
| itemBuilder: (context, index) { | |
| return ListTile( | |
| title: Text('${items[index]}'), | |
| ); | |
| }, | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment