I have three pages each one is a StatefulWidget
put into separate dart files named:
welcome.dart
page_01.dart
page_02.dart
I open each page using pushNamed
function of Navigator
like so:
Navigator.of(context).pushNamed('/pageName');
this is made possible using custom RouteGenerator
added to my app main MaterialApp
widget.
Lets say I open welcome page, then page_01 then page_02 in this order. now I am looking at page_02 which is at the top of Navigation stack. I want to know if page_01 is open/added to Navigation stack and its index number, which in this case should have index of 1.
How to know if a page is open in navigation stack and get its index number ?
The state class of Navigator
holds a list of widgets named List<Route<dynamic>> _history
.
Since this value is kept private
and there is no public getter
provided, we can not find what is the status of pushed widgets at any given moment.
However, NavigatorState
does provide some getters to know the status of the extreme ends of _history
:
bool get isCurrent
// if the current widget/route is at the top of the stackbool get isActive
// if the current widget/route is on the navigatorbool get isFirst
// if the current widget/route is at the bottom of the stackSince none of them takes any widget/route as parameters these getters only use this
to produce results for each status queries. There is no way we can get information about widgets that are in the stack but are not being rendered at the moment of the query.
I am afraid I couldn't find any other details to get more about status of other routes.
I have referred to navigator.dart
file for these details since most of the properties are kept private, online API documentation is not helpful.
If somebody can come up with more details, just let me know. :D
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With