duplicate pages when pushed with Navigator - dart

why pages get duplicated when pushed with Navigator?
I want to switch between pages but always a new instance is created.I don't want to replace or pop ... is there a way to switch pages in Navigator if it is already open in Navigator. we have different routes and we want to switch between pages if it is already in the stack. below is an example to illustrate the issue:
Navigator.pushNamed(context, '/home');
Navigator.pushNamed(context, '/register');
Navigator.pushNamed(context, '/about');

Related

How to push a full-screen page that stays on top of Flutter BottomNavigationBar

I searched everywhere and could not come up with an answer.
I have a BottomNavigationBar and a FloatingActionButton.
What I am trying to do is pushing a full screen page when the user presses the FloatingActionButton.
This page needs to cover the area of the BottomNavigationBar and previous AppBar since in this new page user is not allowed to go to the other tabs of the BottomNavigationBar.
I came across fullscreenDialog, a property of PageRoute Widget class and got excited but could not get it to exactly work as I wanted it to work(top<->bottom as I will explain later)
This page will have it's own Scaffold and AppBar and is able to push/pop to next screens(inside of it's own navigation tree)
In order to pop this page, the user will press a 'x' button positioned at bottom center of the page.
I want to push/pop this new Page from top<->bottom instead of the usual navigation style which is left<->right (For iOS/Cupertino)
I am familiar with this type of UI from iOS devices(ModalViewController)
So How would we implement the push and pop commands?
Or is there another, better/recommended way to do this?
I had a similar problem, and it was solved with this:
await Navigator.of(context, rootNavigator:true).push( // ensures fullscreen
CupertinoPageRoute(
builder: (BuildContext context) {
return MyWidget();
}
) );
Found at https://stackoverflow.com/a/54017488/247451
You should try MaterialPageRoute with fullscreenDialog prop (docs):
Navigator.of(context).push(new MaterialPageRoute<Null>(
builder: (BuildContext context) {
return new AddEntryDialog();
},
fullscreenDialog: true
));
Might not be the best way in your case, but it will appear above the bottom bar and any other navigation widgets.
Code taken from: https://marcinszalek.pl/flutter/flutter-fullscreendialog-tutorial-weighttracker-ii/

Flutter use PageController inside another screen

I have a main page with 3 tabs where I can navigate between them via
_tabController.jumpToPage(tab);
but when I open new screen form tab
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => TrainerListPage())
);
I can't make navigation between tabs until screen is open and I have to do something like this:
Navigator.pop(context);
tabStorage.tabController.jumpToPage(0);
where tabStorage is my class for keeping ref to PageController instance
If I will have 3 opened screen in order I have to call
Navigator.pop(context)
three times and it has at least visual defect.
What is correct way to active it?

How to disable back operation of Flutter's Navigator class

After a login page, a page gets replaced by an overview page like so:
Navigator.popAndPushNamed( context, MyApp.ROUTE_TESTER_TASK_OVERVIEW );
This removes the current page from the Navigator's stack and pushes the new page on it. Fine.
Q: But how to I disable, that a user performs a back navigation? The user shouldn't bee able to leave the Task Overview page.
Should I keep the stack holding one and only one page all the time.
Or does Navigator has another option to disable a back navigation?
Q: Additionally, I want to disable the swipe right gesture, so than it doesn't show the previous page [as I the user clicked Android's back button].
One possible (probably not the best) solution is to wrap the second page within a WillPopScope widget. In the onWillPop parameter you can just return Future.value(false) to intercept all pop actions.

jQuery Tabbed UI using AJAX - switching between tabs previous view

Let's say I have two tabs tabA and tabB. When I click on tabA the first page of that section appears, call it tabA1. If I click on a link on that page then page tabA1 is replaced with tabA2. If I then click on another tab, say tabB, and then go and click on tabA again I get an image of tabA2 lingering for a bit.
How can I make it so that clicking tabA will always show tabA1 straight away? Is it saving it in the cookies for fast access?
Before switching additionally try setting the content in the tab (or equivalent wrapper) to display : none.
This is happened to me and that's how I fixed it. Although I know it fixes the symptoms and not the exact problem.

MonoCross Example using "MXTouchViewGroup*" in a MonoCross.Touch application

Does anyone have example code illustrating how one would use the "MXTouchViewGroup*" code in the framework to create/use a tab bar at the bottom. Looking at code for MXToughViewGroup*, it isn't 100% clear how I would setup/use the navigation framework with a tab bar. Unfortunately the MonoCross book also has no examples of this case.
Any help would be appreciated.
Thanks in Advance.
So after poking around in MonoCross source, I've figured out how one would use a MonoTouch/iOS tab bar while using the MonoCross pattern, and specifically while continuing to use MonoCross.Navigation to move around your app:
//------- MonoCross Shared Application
// Main Menu
NavigationMap.Add("Menu/Tab1", new Tab1Controller());
NavigationMap.Add("Menu/Tab2", new Tab2Controller());
NavigationMap.Ass("Other", new OtherController());
// Set default navigation URI
NavigateOnLoad = "Menu/Tab1";
//------- MonoCross.Touch Container
// init monocross application
MXTouchContainer.Initialize(new SharedApplication(), this, window)
// Add view to container as usual
MXTouchContainer.AddView<ModelTab1>(typeof(Tab1View),ViewPerspective.Default);
MXTouchContainer.AddView<ModelTab2>(typeof(Tab2View),ViewPerspective.Default);
MXTouchContainer.AddView<ModelOther>(typeof(OtherView),ViewPerspective.Default);
// Create a MXTouchViewGroup, with items representing tab items
MXTouchViewGroupItem[] menuItems = new MXTouchViewGroupItem[] {
new MXTouchViewGroupItem(typeof(Tab1View),"Tab 1!",""),
new MXTouchViewGroupItem(typeof(Tab2View),"Tab 2!",""),
};
MXTouchViewGroup tvg = new MXTouchViewGroup(new MXTouchViewGroupTabController(),menuItems);
// Add the group to MXTouchContainer.ViewGroups
List<MXTouchViewGroup> ltvg = ((MXTouchContainer)MXTouchContainer.Instance).ViewGroups;
ltvg.Add(tvg);
// navigate to to starting location now
MXTouchContainer.Navigate(null,MXTouchContainer.Instance.App.NavigateOnLoad);
In the shared app, create controllers derived from MXController as usual and add them to the NavigationMap. Absolutely nothing special to be done in the "Shared Application"
In The MonoCross Container, you add views derived from MXTouch*View as usual to the container as usual as well. What is done differently is to create a "MXTouchViewGroup" with one "MXTouchViewGroupItems" created for each tab; each "MXTouchViewGroupItem" has one of your views associated to it. You'll want to create an appropriate "MXTouchViewGroup" item for your tab bar, and then add the group to your "MXTouchContainer" as shown, and then let the framework navigate to the first view as usual.
The result of all this is that when navigating to a view that is in a "group" (i.e. "Tab1View" or "Tab2View"), the framework will automagically render a tab bar with the view, without any further intervention. If you navigate to a view that isn't in a "group" (i.e. "OtherView"), the tabbar will not render.
That's it.

Resources