Advertisement
Guest User

Tab

a guest
Mar 22nd, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 1.83 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. void main() {
  4.   runApp(MaterialApp(
  5.     home: MyApp(),
  6.   ));
  7. }
  8.  
  9. class MyApp extends StatefulWidget {
  10.   @override
  11.   _MyAppState createState() => _MyAppState();
  12. }
  13.  
  14. class _MyAppState extends State<MyApp> with TickerProviderStateMixin {
  15.   TabController tabController;
  16.  
  17.   @override
  18.   void initState() {
  19.     tabController = TabController(vsync: this, length: 3);
  20.     super.initState();
  21.   }
  22.  
  23.   @override
  24.   void dispose() {
  25.     tabController.dispose();
  26.     super.dispose();
  27.   }
  28.  
  29.   @override
  30.   Widget build(BuildContext context) {
  31.     return Scaffold(
  32.       appBar: AppBar(
  33.         title: Text('MyApp'),
  34.       ),
  35.       body: Container(
  36.         child: Column(
  37.           children: <Widget>[
  38.             TabBar(
  39.               controller: tabController,
  40.               tabs: <Widget>[
  41.                 Tab(
  42.                   icon: Icon(Icons.home,
  43.                       color:
  44.                           tabController.index == 0 ? Colors.red : Colors.green),
  45.                 ),
  46.                 Tab(
  47.                   icon: Icon(Icons.ac_unit,
  48.                       color:
  49.                           tabController.index == 1 ? Colors.red : Colors.green),
  50.                 ),
  51.                 Tab(
  52.                   icon: Icon(Icons.headset,
  53.                       color:
  54.                           tabController.index == 2 ? Colors.red : Colors.green),
  55.                 ),
  56.               ],
  57.             ),
  58.             Expanded(
  59.               child: TabBarView(
  60.                 controller: tabController,
  61.                 children: <Widget>[
  62.                   Icon(Icons.home, size: 100.0),
  63.                   Icon(Icons.ac_unit, size: 100.0),
  64.                   Icon(Icons.headset, size: 100.0),
  65.                 ],
  66.               ),
  67.             )
  68.           ],
  69.         ),
  70.       ),
  71.     );
  72.   }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement