Flutter Tabbar Example | Flutter TabController Code Snippet

0

In Flutter,  is a widget used to create a tabbed interface, allowing users to navigate between different views easily. It works in conjunction with  and  to display multiple pages or sections within a single screen.




Here’s a basic example of how  is implemented:


 import 'package:flutter/material.dart';  

 
class FirstScreen extends StatelessWidget {  
  @override  
  Widget build(BuildContext context) {  
    return Container(  
      child: Center(  
        child: Text('It is a contact tab, which is responsible for displaying the contacts stored in your mobile',  
            style: TextStyle(fontSize: 32.0),  
          )  
      ),  
    );  
  }  
}  

class SecondScreen extends StatelessWidget {  
  @override  
  Widget build(BuildContext context) {  
    return Container(  
      child: Center(  
        child: Text('It is a second layout tab, which is responsible for taking pictures from your mobile.',  
        style: TextStyle(fontSize: 35.0),  
        ),  
      ),  
    );  
  }  
}  

class Tabbarexample extends StatelessWidget {
@override  
  Widget build(BuildContext context) {  
    return MaterialApp(
      home:DefaultTabController(length: 2, child: Scaffold(
       appBar: AppBar(title: Text("Tab bar example"),bottom: TabBar(tabs:[
        Tab(icon: Icon(Icons.contacts), text: "Tab 1"),  
        Tab(icon: Icon(Icons.camera_alt), text: "Tab 2")  
       ]),),
       body:TabBarView(children:[
              FirstScreen(),  
              SecondScreen(),  ])
      ))
     );
  }
}



void main() {
  runApp(Tabbarexample());
}

Post a Comment

0Comments

POST Answer of Questions and ASK to Doubt

Post a Comment (0)