1

I have no idea How to make Tab bar like This in my flutter web

Can I have an idea or How call This pattern.

Example video: https://youtu.be/A3ttwYljg_8

enter image description here

Matthew Layton
  • 39,871
  • 52
  • 185
  • 313

1 Answers1

1

You just have to give body to TabBarView, rest will be taken care by flutter itself.

Sample Code : -

TabBarView(
  children: <Widget>[
  Tabbar 1 body ...., //1st index, 1st tab
  Tabbar 2 body ...., //2nd index, 2nd tab
  Tabbar 3 body ...., //...
  Tabbar 4 body ...., //...
  Tabbar 5 body ....  //...
  ]
)

TabBarView

Complete Code : -

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  static const String _title = 'Flutter Code Sample';

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: _title,
      home: MyStatelessWidget(),
    );
  }
}

class MyStatelessWidget extends StatefulWidget {
  const MyStatelessWidget({super.key});

  @override
  State<MyStatelessWidget> createState() => _MyStatelessWidgetState();
}

class _MyStatelessWidgetState extends State<MyStatelessWidget> {
  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      initialIndex: 0,
      length: 5,
      child: Scaffold(
        appBar: AppBar(
          backgroundColor: const Color.fromARGB(255, 107, 179, 234),
          title: const Text('TabBar Widget'),
          bottom: const TabBar(
            labelColor: Colors.black,
            indicator: BoxDecoration(color: Colors.yellow),
            labelPadding: EdgeInsets.only(bottom: 5),
            indicatorPadding:
                EdgeInsets.only(left: 30, right: 30, bottom: 10, top: 5),
            tabs: <Widget>[
              SizedBox(
                width: 70,
                height: 40,
                child: Center(
                  child: Tab(
                    text: "Tab 1",
                  ),
                ),
              ),
              SizedBox(
                width: 70,
                height: 40,
                child: Tab(
                  text: "Tab 2",
                ),
              ),
              SizedBox(
                width: 70,
                height: 40,
                child: Tab(
                  text: "Tab 3",
                ),
              ),
              SizedBox(
                width: 70,
                height: 40,
                child: Tab(
                  text: "Tab 4",
                ),
              ),
              SizedBox(
                width: 70,
                height: 40,
                child: Tab(
                  text: "Tab 5",
                ),
              ),
            ],
          ),
        ),
        body: TabBarView(
          children: <Widget>[
            Column(
              children: [
                Expanded(
                    child: Container(
                  color: Colors.red,
                )),
                Expanded(
                    child: Container(
                  color: Colors.purple,
                ))
              ],
            ),
            Column(
              children: [
                Expanded(
                    child: Container(
                  color: const Color.fromARGB(255, 9, 79, 135),
                )),
                Expanded(
                    child: Container(
                  color: Colors.purple,
                ))
              ],
            ),
            Column(
              children: [
                Expanded(
                    child: Container(
                  color: const Color.fromARGB(255, 144, 255, 54),
                )),
                Expanded(
                    child: Container(
                  color: Colors.purple,
                ))
              ],
            ),
            Column(
              children: [
                Expanded(
                    child: Container(
                  color: const Color.fromARGB(255, 109, 40, 36),
                )),
                Expanded(
                    child: Container(
                  color: Colors.yellow,
                ))
              ],
            ),
            Column(
              children: [
                Expanded(
                    child: Container(
                  color: Colors.green,
                )),
                Expanded(
                    child: Container(
                  color: Colors.yellow,
                ))
              ],
            ),
          ],
        ),
      ),
    );
  }
}

Output :-

Ramji
  • 904
  • 2
  • 5
  • 20
  • Thank you for ans, but at bottom side I want to use same tab mean tab1 -> top1 + bottom1, tab2 -> top2 + bottom1, tab3 -> top3 + bottom1, tab4 -> top4 + bottom2, tab5 -> top5 + bottom2, bottom side never change at tab 1-3, it will change at tab 4-5 – Athiruj Kaewseesuk Jan 20 '23 at 19:00
  • @AthirujKaewseesuk, you can add if condition on that tab, if the index is 3 then change the bottom tab. To check which tabbar is active, use onTap method of tabbar. – Ramji Jan 21 '23 at 03:38