Let's say I have 4 files in my project.
navbar, firstPage, secondPage, thirdPage.
In the navbar I have a side drawer with navigation for the pageview and a pageview for firstPage secondPage and thirdPage.
How do I access navbar PageController.jumpToPage() from button onTab function in other pages?
You can access navbar PageController.jumpToPage() from button onTab function in other pages by 2 ways:
1 passing PageController to the page that have onTab function
2 using dependence injection that can share PageController with any page, have a look at get_it package for more info.
Related
I have an appbar which is used in more than one screen. I have a navigation drawer in the home screen. As the appbar is used in multiple places, i created as a separate widget. But I am not able to access navigation drawer. So I included appbar code in all the screens I needed. Then it works fine. But it will be code duplicate. Is there any fix for this in Flutter?
Thanks.
If you have not done so yet , you can make a separate class for drawer
getAppDrawer(){
return Drawer(
//your code
);
}
and then you can call this in your others screen
drawer : getAppDrawer(),
you can also do this for the appbar
Take a look at the examples here
and here
I'm using Custom Tab navigator to manage persistent bottom navigation bar across all the screens.
Due this Tab navigator sits in one StatefulWidget to host the tabs in the app, So unable to pop to the other widget out of these tabs and hosted widget.
Ex : After successful login, There is one widget Dashboard and it hosts the bottom navigation and tabs using Navigator. Now i want to logout from one of the tab and should navigate to the login screen, which is not part of any tabs or hosted widget.
While trying to push to Login widget, Showing only the blank screen. Because no route within the Custom navigator.
Any solution for this without using any package for persistent bottom navigation.
I have a TabController in flutter which has 4 TabItems. How to push screens inside on any particular tab item with back navigation? instead of opening a new screen which covers the full screen and hides the Tab bar.
Finally after some research, i have achieved this with Cupertino Widgets. Using CupertinoTabScaffold and CupertinoTabBar this can be done.
I have an app with bottom navbar. I can navigate between pages through the navbar. My problem is when i go to another page (not a button for this page on navbar) navbar disappears. I used that code below when click button and go to another page. But as i said navbar dissappears. I want navbar always stay.
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ProgrammingScreen()));
I tried PageView widget but i could'nt navigate pages from buttons. How can i solve this problem?
One option is to all those screens be in the page view widget.
But another thing you can do is put the exact same bottom nav bar in the new pushed screen and if the user selects an option. You can use Navigator.pop() and then navigate to the pageView with the selected option
I am building a flutter app where the user requirement is to build 3 tabs with each tab having custom AppBar which implies to have multiple Scaffolds in each view.
So I have main.dart, screen.dart, account.dart and post.dart
3 tabs => Screen, Account and Post
Screen View => Appbar with just name
Account View => Appbar with Hamburger Icon
Post View => Appbar with Plus icon
According to flutter we can have Appbar and Bottom Navigation Bar (Tabs Bar) inside Scaffold Widget. So to have multiple Scaffolds, I would have to make 3 seperate bottom navigation bar or is there any other way to achieve this functionality?
Also, if we need to make 3 different Bottom Navigation Bar per Scaffold, then how to navigate between them since my first view will be called from main.dart
Thanks for helping and taking out your time to answer the question.