Flutter tabbar without appbar

Flutter TabBar Without AppBar

In Flutter, you can create a TabBar without an AppBar by using a combination of widgets like Scaffold, TabController, and TabBarView. Below is a step-by-step explanation with examples:

  1. Import the required Flutter packages:
  2.             
    import 'package:flutter/material.dart';
                
            
  3. Create a StatefulWidget, which will hold the state for managing tabs:
  4.             
    class TabScreen extends StatefulWidget {
      @override
      _TabScreenState createState() => _TabScreenState();
    }
                
            
  5. Define the state class:
  6.             
    class _TabScreenState extends State<TabScreen> with SingleTickerProviderStateMixin {
      TabController _tabController;
    
      @override
      void initState() {
        _tabController = TabController(length: 3, vsync: this);
        super.initState();
      }
    
      @override
      void dispose() {
        _tabController.dispose();
        super.dispose();
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: Column(
            children: [
              TabBar(
                controller: _tabController,
                tabs: [
                  Tab(text: 'Tab 1'),
                  Tab(text: 'Tab 2'),
                  Tab(text: 'Tab 3'),
                ],
              ),
              Expanded(
                child: TabBarView(
                  controller: _tabController,
                  children: [
                    Center(child: Text('Content of Tab 1')),
                    Center(child: Text('Content of Tab 2')),
                    Center(child: Text('Content of Tab 3')),
                  ],
                ),
              ),
            ],
          ),
        );
      }
    }
                
            
  7. Use the TabScreen widget where you want to display the tabs:
  8.             
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter TabBar Without AppBar',
          home: TabScreen(),
        );
      }
    }
                
            
  9. Run the app and you will see a screen with a TabBar and corresponding TabBarView without an AppBar:
  10. TabBar Without AppBar Example

By following the above steps and implementing the provided code, you will be able to create a Flutter TabBar without an AppBar. Feel free to customize the styling and content as per your requirements.

Leave a comment