Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- void main() => runApp(new TabBarDemo());
- class TabBarDemo extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- home: DefaultTabController(
- length: 4,
- child: Scaffold(
- appBar: AppBar(
- bottom: TabBar(
- tabs: [
- Tab(text: "1"),
- Tab(text: "2"),
- Tab(text: "3"),
- Tab(text: "4"),
- ],
- ),
- title: Text('Select last tab'),
- ),
- body: TabBarView(
- children: [
- TabContent("1"),
- TabContent("2"),
- TabContent("3"),
- TabContent("4"),
- ],
- ),
- ),
- ),
- );
- }
- }
- class TabContent extends StatefulWidget {
- final String name;
- TabContent(this.name);
- @override
- _TabContentState createState() => _TabContentState();
- }
- class _TabContentState extends State<TabContent>
- with AutomaticKeepAliveClientMixin<TabContent> {
- @override
- bool get wantKeepAlive => true;
- int count = 0;
- @override
- Widget build(BuildContext context) {
- return Center(
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Text(widget.name),
- SizedBox(
- height: 80.0,
- ),
- Text(
- count.toString(),
- style: Theme.of(context).textTheme.display1,
- ),
- OutlineButton(
- child: Text("increment"),
- onPressed: _increment,
- ),
- ],
- ),
- );
- }
- void _increment() => setState(() {
- count++;
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement