k4zek4ge
10/29/2019 - 10:33 AM

Tabbar

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home:  Scaffold(
          resizeToAvoidBottomPadding: false,
        body: SafeArea(
          child: TabBarApp()
           
        ),       
      ),
    ); 
  }
}

class TabBarApp extends StatefulWidget {
  @override
  _TabBarAppState createState() => _TabBarAppState();
}

class _TabBarAppState extends State<TabBarApp> {


  var _data = "";
  TabBar _tabBar() => TabBar(
  tabs: <Widget>[
    Tab(
      text: 'Home',
      icon: Icon(Icons.home),
    ),
    Tab(
      text: 'Videos',
      icon: Icon(Icons.featured_video),
    ),
    Tab(
      text: 'Favourites',
      icon: Icon(Icons.favorite,color: Colors.pink,),
    ),
    Tab(
      text: 'Upload',
      icon: Icon(Icons.file_upload),
    ),
  ],
        labelColor: Colors.blueAccent,
        labelPadding: EdgeInsets.symmetric(vertical: 10),
        labelStyle: TextStyle(fontSize: 18.0),
        unselectedLabelColor: Colors.white,
        unselectedLabelStyle: TextStyle(fontSize: 14),
        indicator: ShapeDecoration(
          color: Colors.white,
          shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(30)),
          ),
        
        onTap: (index) {
          setState(() {
          switch (index) {
            case 0:
              _data = "Home";
              break;
            case 1:
              _data = "Videos";
              break;
            case 2:
              _data = "Favourites";
              break;
            case 3:
              _data = "Upload";
              break;
            default:
              _data = "other";  

          }

          });
         
         
          
        },
      );


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: DefaultTabController(
        length: 4,
        child: Scaffold(
          appBar: AppBar(
            title:Center( child:Text('TabBar'),),
            bottom: _tabBar(),
          ),
          body: Center(
            child: TabBarView(
              children: <Widget>[
                Card(
                  color: Colors.blueAccent,
                  child:Center(child: Text(_data,style: TextStyle(color:Colors.white,fontSize: 25.0,fontWeight: FontWeight.w700),), )
                ),
                 Card(
                    color: Colors.amberAccent,
                  child: Center(child: Text(_data,style: TextStyle(color:Colors.white,fontSize: 25.0,fontWeight: FontWeight.w700),), )
                ),
                Card(
                   color: Colors.pink,
                  child: Center(child: Text(_data,style: TextStyle(color:Colors.white,fontSize: 25.0,fontWeight: FontWeight.w700),), )
                ),
                 Card(
                    color: Colors.white,
                  child: Center(child: Text(_data,style: TextStyle(color:Colors.black,fontSize: 25.0,fontWeight: FontWeight.w700),), )
                )
              ],
            )
            ),
        ),

      ),
    );
  }
}