Advertisement
Guest User

Untitled

a guest
Jul 24th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. void main() => runApp(MyApp());
  4.  
  5. class MyApp extends StatefulWidget {
  6. @override
  7. _MyAppState createState() => new _MyAppState();
  8. }
  9.  
  10. class _MyAppState extends State<MyApp> with TickerProviderStateMixin {
  11. static int _noOfTabs = 0;
  12. static List<Widget> _tabList;
  13. static List<Widget> _tabViewList;
  14.  
  15. @override
  16. Widget build(BuildContext context) {
  17. return MaterialApp(
  18. home: DefaultTabController(
  19. length: _noOfTabs,
  20. child: Scaffold(
  21. appBar: new AppBar(
  22. title: Text('Default TabBar Preview'),
  23. bottom: (_noOfTabs > 0)
  24. ? TabBar(isScrollable: true, tabs: _tabList)
  25. : null,
  26. ),
  27. body: (_noOfTabs > 0)
  28. ? TabBarView(children: _tabViewList)
  29. : Center(
  30. child: Text('No tabs'),
  31. ),
  32. floatingActionButton: FloatingActionButton(
  33. child: Icon(Icons.add), onPressed: buttonPressed),
  34. )));
  35. }
  36.  
  37. void buttonPressed() {
  38. setState(() {
  39. _noOfTabs++;
  40. });
  41.  
  42. _tabList = new List<Widget>();
  43. _tabViewList = new List<Widget>();
  44.  
  45. for (var i = 0; i < _noOfTabs; i++) {
  46. _tabList.add(Tab(text: 'Tab ' + (i + 1).toString()));
  47. _tabViewList.add(Center(child: Text('Tab ' + (i + 1).toString())));
  48. }
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement