Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 2.06 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. void main() {
  4.   runApp(MyApp());
  5. }
  6.  
  7. class MyApp extends StatelessWidget {
  8.   // This widget is the root of your application.
  9.   @override
  10.   Widget build(BuildContext context) {
  11.     return MaterialApp(
  12.       title: 'Flutter Demo',
  13.       theme: ThemeData(
  14.         primaryColor: Color(0xFF0f1e3d),
  15.         // brightness: Brightness.dark
  16.       ),
  17.       debugShowCheckedModeBanner: false,
  18.       home: MyTabbedPage(),
  19.     );
  20.   }
  21. }
  22.  
  23. class MyTabbedPage extends StatefulWidget {
  24.   const MyTabbedPage({Key key}) : super(key: key);
  25.   @override
  26.   _MyTabbedPageState createState() => new _MyTabbedPageState();
  27. }
  28.  
  29. class _MyTabbedPageState extends State<MyTabbedPage>
  30.     with SingleTickerProviderStateMixin {
  31.   TabController _tabController;
  32.  
  33.   @override
  34.   void initState() {
  35.     super.initState();
  36.     _tabController = new TabController(vsync: this, length: 2);
  37.     _tabController.addListener(_handleTabChange);
  38.   }
  39.  
  40.   @override
  41.   void dispose() {
  42.     _tabController.dispose();
  43.     super.dispose();
  44.   }
  45.  
  46.   void _handleTabChange() {
  47.     setState(() {
  48.       print("touched");
  49.       index = _tabController.index;
  50.       print(index);
  51.     });
  52.   }
  53.  
  54.   int index;
  55.  
  56.   @override
  57.   Widget build(BuildContext context) {
  58.     print(_tabController.index);
  59.     return new Scaffold(
  60.       appBar: new AppBar(
  61.         bottom: new TabBar(
  62.           controller: _tabController,
  63.           onTap: (int i) {
  64.             setState(() {
  65.               print("touched");
  66.               index = i;
  67.               print(index);
  68.             });
  69.           },
  70.           tabs: <Tab>[
  71.             new Tab(
  72.               text: index == 0 ? 'LEFT' : null,
  73.               icon: index == 0 ? null : Icon(Icons.mail),
  74.             ),
  75.             new Tab(
  76.               text: index == 1 ? 'RIGHT' : null,
  77.               icon: index == 1 ? null : Icon(Icons.adb),
  78.             ),
  79.           ],
  80.         ),
  81.       ),
  82.       body: new TabBarView(controller: _tabController, children: [
  83.         Text("left"),
  84.         Text("right"),
  85.       ]),
  86.     );
  87.   }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement