3

I want to implement a custom scrollable TabBar in my body, not in the appBar

enter image description here

4
  • What you have tried? Commented Jul 15, 2019 at 10:53
  • i tried some solution but i cant find a solution | Commented Jul 15, 2019 at 10:55
  • I think I am going to make a package for what you want later this week because I need it too, but check out my solution using pageView below! Commented Jul 16, 2019 at 3:17
  • Also, I think this is worth checking out: stackoverflow.com/questions/50609252/… Commented Jul 16, 2019 at 3:19

4 Answers 4

3

PageView and PageController

So this isn't exactly what you are looking for, instead of bottom bar you could do a horizontal scroll (scrollView), but I hope this pushes you in the right direction. This code basically uses pageView to display pages, and since there is a page controller you can animate any button or onPress to a specific page.

Let me know if you have any questions!

import 'package:flutter/material.dart';

class TestWidget extends StatefulWidget {
  TestWidget({Key key}) : super(key: key);

  @override
  _TestWidgetState createState() => _TestWidgetState();
}

class _TestWidgetState extends State<TestWidget> {
  int _selectedIndex = 0;

  PageController _pageController;

  @override
  void initState() {
    super.initState();
    _pageController = PageController();
  }

  @override
  void dispose() {
    _pageController.dispose();
    super.dispose();
  }

  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Tab Bar"),
      ),
      body: Center(
        child: Column(
          children: <Widget>[ 
            Expanded(
              flex: 10,
              child: ButtonBar(
                alignment: MainAxisAlignment.center,
                children: <Widget>[
                  FlatButton(
                    splashColor: Colors.blueAccent,
                    color: Colors.blue,
                    onPressed: () {
                      _pageController.animateToPage(0, duration: Duration(milliseconds: 500), curve: Curves.ease);
                    },
                    child: Text("One",),
                  ),
                  FlatButton(
                    splashColor: Colors.blueAccent,
                    color: Colors.blue,
                    onPressed: () {
                      _pageController.animateToPage(1, duration: Duration(milliseconds: 500), curve: Curves.ease);
                    },
                    child: Text("Two",),
                  ),
                  FlatButton(
                    splashColor: Colors.blueAccent,
                    color: Colors.blue,
                    onPressed: () {
                      _pageController.animateToPage(2, duration: Duration(milliseconds: 500), curve: Curves.ease);
                    },
                    child: Text("Three",),
                  )
                ],
              ),
            ),
            Expanded(
              flex: 40,
              child: PageView(
                controller: _pageController,
                children: [
                  Text("Page One"),
                  Text("Page Two"),
                  Text("Page Three")
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}

This basically allows you to use any tab bar or buttons you wont to switch page while keeping swipe functionality :-)

Sign up to request clarification or add additional context in comments.

Comments

1

I would start with a listView that scrolls horizontally, then build up thous ListTile elements, and make them clickable. If you want to swipe then add on a gesturedetector.

2 Comments

what about TabController ?? i want a custom tabBar not just List view
if you mean the dragable functionality with "TabController" then you can use GestureDragStartCallback see this api.flutter.dev/flutter/gestures/GestureDragStartCallback.html and you can add a function to change the page, when the pointer is dragging horizontaly.
0

You can create a custom list with the same view. Here is the sample code

ListView.builder(
              itemBuilder: (_, count) {
                return Container(
                  decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(10.0),
                      color: Colors.green),
                  child: GestureDetector(
                    onTap: (){
                      print("You clicked");
                    },
                    child: Text(
                      list[count],
                      style: TextStyle(color: Colors.white, fontSize: 12),textAlign: TextAlign.center,
                    ),
                  ),
                );
              },
              itemCount: list.length,
              scrollDirection: Axis.horizontal,
            )

1 Comment

if it is possible i prefer using flutter TabController and TabBar
0

Try to use "NestedScrollView" and put the information outside the tabbar in "flexibleSpace"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.