Advertisement
Guest User

tab crash

a guest
Sep 1st, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 1.76 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 = 0;
  52.  
  53.   @override
  54.   Widget build(BuildContext context) {
  55.     return Center(
  56.       child: Column(
  57.         mainAxisAlignment: MainAxisAlignment.center,
  58.         children: <Widget>[
  59.           Text(widget.name),
  60.           SizedBox(
  61.             height: 80.0,
  62.           ),
  63.           Text(
  64.             count.toString(),
  65.             style: Theme.of(context).textTheme.display1,
  66.           ),
  67.           OutlineButton(
  68.             child: Text("increment"),
  69.             onPressed: _increment,
  70.           ),
  71.         ],
  72.       ),
  73.     );
  74.   }
  75.  
  76.   void _increment() => setState(() {
  77.         count++;
  78.       });
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement