skip to Main Content

I want to add to my user profile the swipe category like instagram has : https://imgur.com/a/ALeXB73 but I don’t know what package I should use or if there is a package that has this

2

Answers


  1. Good News! There is no need to use a package as there is already a widget from the flutter library that handles this pretty good. The widget is DefaultTabController. It allows you to specify tabs and its contents. An Example could be:

    import 'package:flutter/material.dart';
    
    class TabsExample extends StatelessWidget {
      const TabsExample({super.key});
    
      @override
      Widget build(BuildContext context) {
        return DefaultTabController(
          length: 2,
          child: Scaffold(
            appBar: AppBar(
              bottom: const TabBar(
                tabs: [
                  Tab(text: 'LEFT'), //the button shown at the top
                  Tab(text: 'RIGHT'),
                ],
              ),
            ),
            body: const TabBarView(
              children: [
                // First widget is the page that opens when the left tab button is clicked
                Center(
                  // Any widget you want to display
                  child: Text('LEFT'),
                ),
                // Second widget is the page that opens when the right tab button is clicked
                Center(
                  // Any widget you want to display
    
                  child: Text('RIGHT'),
                ),
              ],
            ),
          ),
        );
      }
    }
    

    OR

    import 'package:flutter/material.dart';
    
    class TabsExample extends StatelessWidget {
      const TabsExample({super.key});
    
      @override
      Widget build(BuildContext context) {
        return DefaultTabController(
          length: 2,
          child: Scaffold(
            appBar: AppBar(),
            body: const Column(
              children: [
                TabBar(
                  tabs: [
                    Tab(text: 'LEFT'), //the button shown at the top
                    Tab(text: 'RIGHT'),
                  ],
                ),
                Expanded(
                  child: TabBarView(
                    children: [
                      // First widget is the page that opens when the left tab button is clicked
                      Center(
                        // Any widget you want to display
                        child: Text('LEFT'),
                      ),
                      // Second widget is the page that opens when the right tab button is clicked
                      Center(
                        // Any widget you want to display
                        child: Text('RIGHT'),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        );
      }
    }
    

    In your case you would replace Tab(text: 'LEFT') with something like Tab(icon: yourIcon) or you could also specify a custom widget to have as the button – Tab(widget: Text('LEFT'))

    The content of the page is specified in the children parameter. (first tab has first child as its page)

    Login or Signup to reply.
  2. Try below code hope its help to you.

    SingleChildScrollView(
          child: Column(
            children: [
              Center(
                child: Text('Hello, World!'),
              ),
              SizedBox(
                height: MediaQuery.of(context).size.height /
                    1.5, // change it on your need
                child: DefaultTabController(
                  length: 2,
                  child: Column(
                    children: [
                      Container(
                        height: 40,
                        width: double.infinity,
                        color: Colors.green[50],
                        child: Center(child: Text("TITLE")),
                      ),
                      TabBar(
                        tabs: [
                          Icon(Icons.menu),
                          Icon(Icons.person),
                        ],
                      ),
                      Expanded(
                        child: TabBarView(
                          children: [
                            ListView.builder(
                              shrinkWrap: true,
                              itemCount: 5,
                              itemBuilder: (context, index) =>
                                  Text("item builder $index"),
                            ),
                            ListView.builder(
                              shrinkWrap: true,
                              itemCount: 10,
                              itemBuilder: (context, index) =>
                                  Text("$index item builder"),
                            ),
                          ],
                        ),
                      )
                    ],
                  ),
                ),
              ),
              Container(
                height: 150,
                color: Colors.green,
                child: const Center(
                  child: Text(
                    'Your Widget if you want',
                  ),
                ),
              ),Container(
                height: 150,
                color: Colors.red,
                child: const Center(
                  child: Text(
                    'Your Widget if you want',
                  ),
                ),
              ),
            ],
          ),
        ),
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search