rafalbednarczuk / curved_navigation_bar

Animated Curved Navigation Bar in Flutter
BSD 2-Clause "Simplified" License
694 stars 242 forks source link

How can I prevent to move other page in some cases #63

Closed NickanBagherpour closed 3 years ago

NickanBagherpour commented 4 years ago

Hi In some cases I want to prevent moving to other pages like I had a profile NavButton and only authenticated user can move to this page otherwise some action (like showing dialog,etc) needs to do without build current tab again (that's so important) I can doing this in onTap function and return to before tab but that's trigger page again I tried below code but it didn't work (NavButton not changed but page changed)

onTap: (index) async {

    if (index == profileIndex && !isLogin()) {
        bool result = await showAuthPopup(); // show signup or login dialog (also close dialog and get the result)

    if(!result) // if the auth task fails, do nothing and continue on the same page you were without building it again otherwise go to profile page
           return;
    }     

     setState(() {
         _page = index;
     });

}

It would be great if onTap accepts bool return value for trigger (instead of void ) , then I could do that

onTap: (index) async {

    if (index == profileIndex && !isLogin()) {
        bool result = await showAuthPopup();

    if(!result)
            return false; // don't do other stuff 
    }     

     setState(() {
         _page = index;
     });

    return true; // do remain stuff like before 

}

I hope I am getting my point across.

Thanks.

develogo commented 4 years ago

I need this too

rafalbednarczuk commented 3 years ago

fixed in https://github.com/rafalbednarczuk/curved_navigation_bar/commit/d5e428b17d03049a0c9cdd055224f97921ad6b03