Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- void main() => runApp(MyApp());
- class MyApp extends StatefulWidget {
- @override
- _MyAppState createState() => new _MyAppState();
- }
- class _MyAppState extends State<MyApp> with TickerProviderStateMixin {
- static int _noOfTabs = 0;
- static List<Widget> _tabList;
- static List<Widget> _tabViewList;
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- home: DefaultTabController(
- length: _noOfTabs,
- child: Scaffold(
- appBar: new AppBar(
- title: Text('Default TabBar Preview'),
- bottom: (_noOfTabs > 0)
- ? TabBar(isScrollable: true, tabs: _tabList)
- : null,
- ),
- body: (_noOfTabs > 0)
- ? TabBarView(children: _tabViewList)
- : Center(
- child: Text('No tabs'),
- ),
- floatingActionButton: FloatingActionButton(
- child: Icon(Icons.add), onPressed: buttonPressed),
- )));
- }
- void buttonPressed() {
- setState(() {
- _noOfTabs++;
- });
- _tabList = new List<Widget>();
- _tabViewList = new List<Widget>();
- for (var i = 0; i < _noOfTabs; i++) {
- _tabList.add(Tab(text: 'Tab ' + (i + 1).toString()));
- _tabViewList.add(Center(child: Text('Tab ' + (i + 1).toString())));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement