Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to update the ConvexAppBar's index. #147

Open
JaisonST opened this issue Jul 4, 2021 · 7 comments
Open

Unable to update the ConvexAppBar's index. #147

JaisonST opened this issue Jul 4, 2021 · 7 comments
Labels
enhancement New feature or request

Comments

@JaisonST
Copy link

JaisonST commented Jul 4, 2021

Hey! love the package it works great. I was trying to automatically move the index along with page swipes. I have a setState() that is updating a global index value. I'm unable to access currentIndex or some kind of active index that would auto update the navbar.

Here's my code:

  final _pageViewController = PageController();
  int _activePage = 0;

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageView(
        controller: _pageViewController,
        children: <Widget>[
          Container(color: Colors.red),
          Container(color: Colors.green),
          Container(color: Colors.blue)
        ],
        onPageChanged: (index) {
          setState(() {
            _activePage = index;
          });
        },
      ),
      bottomNavigationBar: ConvexAppBar(
        items: [
          TabItem(icon: Icons.message, title: 'Chat'),
          TabItem(icon: Icons.home, title: 'Home'),
          TabItem(icon: Icons.people, title: 'Profile'),
        ],
        onTap: (int i) {
          _pageViewController.animateToPage(i,
              duration: Duration(milliseconds: 200), curve: Curves.bounceOut);
        },
        backgroundColor: Colors.black,
        initialActiveIndex: _activePage,
      ),
    );
  }

simulator_screenshot_82749B2D-6144-412D-8AD4-6A8E4EAD5B96

as u can see, i've swiped to Profile screen but its still on chat in the ConvexAppBar.

@mt-akar
Copy link

mt-akar commented Jul 12, 2021

This is because the widget includes an initialActiveIndex property instead of the standard selectedIndex property.

My project requires has the same situation. It requires to go back to the previous page when the back button is pressed, which in turn requires a selectedIndex property to be present.

This is a common behavior pattern and exists in both flutter's own BottomNavigationBar and in almost all other packages. It should be included here as well.

@JaisonST
Copy link
Author

@m-azyoksul, Yea maybe most packages don't have an active index, however i was able to build the functionality i was looking for without the ConvexAppBar package using a BottomNavigationBar's property of currentIndex. Couldn't recreate the Animation that ConvexAppBar provided tho. Fingers Crossed there'd be an update with access to currentIndex.

@mt-akar
Copy link

mt-akar commented Jul 12, 2021

@JaisonST What I mean by selectedIndex is exactly the same as BottomNavigationBar's currentIndex.

There are a bunch of packages that do have a currentIndex property besides the framework one such as flutter_snake_navigationbar, salomon_bottom_bar, water_drop_nav_bar, sliding_clipped_nav_bar, persistent_bottom_nav_bar, bottom_bar, etc. You might like the design of one of these packages. bottom_bar package even explains how to make the swipeable-page layout as you want it.

I still think this package should also implement the currentIndex property.

@avenwu
Copy link
Contributor

avenwu commented Jul 15, 2021

will take into consideration

@avenwu avenwu added the enhancement New feature or request label Jul 15, 2021
@dishankjindal1
Copy link

dishankjindal1 commented Nov 29, 2021

I am having a same issue. I am trying to rebuild the bottom nav bar.

In my Scenario, I have 2 Tab Items if auth is false otherwise 3 Tab Items if auth is true.

what is happening in my case, i am forcing the parent of the convex bottom bar to restart with the fresh data.
It updates the tab correctly but the alignment of the active items initally is as per the previous state but after i tap on the items everything is fixed.

Screenshot1 Screenshot2
Screenshot_20211129-142140.png Screenshot_20211129-142200.png
As you can see, my app is initially designed to have 2 tabs, But when it see an admin user, I added a new tab to the screen now when I press on any tab the issue fixes itself, but it happening on every cold start

@povpros
Copy link

povpros commented Feb 28, 2022

check this
https://github.com/hacktons/convex_bottom_bar/blob/master/doc/issue-change-active-tab-index.md

@vytautas-pranskunas-
Copy link

wow.. cannot believe this package lacks such simple thing.... Instead suggesting

_appBarKey.currentState.animateTo(2/* index*/);

it would so much cleaner to implement currentIndex because for example now I am changing select index from MobX store and have to do hacks (in order not to break single responsibility) to listen to index change and animate to tab.... This is really not right way...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants