Advertisement
Guest User

Untitled

a guest
Sep 1st, 2018
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 1.91 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. void main() => runApp(new TabBarDemo());
  4.  
  5. class TabBarDemo extends StatelessWidget {
  6.   @override
  7.   Widget build(BuildContext context) {
  8.     return MaterialApp(
  9.       home: DefaultTabController(
  10.         length: 4,
  11.         child: Scaffold(
  12.           appBar: AppBar(
  13.             bottom: TabBar(
  14.               tabs: [
  15.                 Tab(text: "1"),
  16.                 Tab(text: "2"),
  17.                 Tab(text: "3"),
  18.                 Tab(text: "4"),
  19.               ],
  20.             ),
  21.             title: Text('Select last tab'),
  22.           ),
  23.           body: TabBarView(
  24.             children: [
  25.               TabContent("1"),
  26.               TabContent("2"),
  27.               TabContent("3"),
  28.               TabContent("4"),
  29.             ],
  30.           ),
  31.         ),
  32.       ),
  33.     );
  34.   }
  35. }
  36.  
  37. class TabContent extends StatefulWidget {
  38.   final String name;
  39.  
  40.   TabContent(this.name);
  41.  
  42.   @override
  43.   _TabContentState createState() => _TabContentState();
  44. }
  45.  
  46. class _TabContentState extends State<TabContent>
  47.     with AutomaticKeepAliveClientMixin<TabContent> {
  48.   @override
  49.   bool get wantKeepAlive => true;
  50.  
  51.   int count;
  52.  
  53.   @override
  54.   void initState() {
  55.     super.initState();
  56.     count = int.parse(widget.name);
  57.   }
  58.  
  59.   @override
  60.   Widget build(BuildContext context) {
  61.     return Center(
  62.       child: Column(
  63.         mainAxisAlignment: MainAxisAlignment.center,
  64.         children: <Widget>[
  65.           Text(widget.name,
  66.             style: Theme.of(context).textTheme.display3,),
  67.           SizedBox(
  68.             height: 80.0,
  69.           ),
  70.           Text(
  71.             count.toString(),
  72.             style: Theme.of(context).textTheme.display3,
  73.           ),
  74.           OutlineButton(
  75.             child: Text("increment"),
  76.             onPressed: _increment,
  77.           ),
  78.         ],
  79.       ),
  80.     );
  81.   }
  82.  
  83.   void _increment() => setState(() {
  84.         count++;
  85.       });
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement