-
-
Notifications
You must be signed in to change notification settings - Fork 129
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
Navigator.pop(context); shows RangeError (index): Index out of range: index must not be negative: -1 #420
Comments
Hey @ThalapathySiva 👋 I was able to reproduce it and make a fix in e47ddf7. I would suggest using the |
@slovnicki Thanks for your fix and suggestions and when can I expect this fix in the release? |
@ThalapathySiva The Edit: it's published. |
@slovnicki Yes I have checked and It worked and I have another doubt to ask, In the same location builder example, you have book and book details screen in same location(BookLocation). But when you have a separate location for the book details screen as I mentioned below, If you navigate to details screen and you hit the back button pop does not work, but browser back button will work just fine. class BooksLocation extends BeamLocation<BeamState> {
BooksLocation({RouteInformation? routeInformation}) : super(routeInformation);
@override
List<String> get pathPatterns => [
'/',
'/books',
];
@override
List<BeamPage> buildPages(BuildContext context, BeamState state) {
return [
BeamPage(
key: ValueKey('home'),
title: 'Home',
child: HomeScreen(),
),
if (state.uri.pathSegments.contains('books'))
BeamPage(
key: ValueKey('books'),
title: 'Books',
child: BooksScreen(),
),
];
}
}
class BooksDetailLocation extends BeamLocation<BeamState> {
BooksDetailLocation({RouteInformation? routeInformation})
: super(routeInformation);
@override
List<String> get pathPatterns => [
'/',
'/books/:bookId',
];
@override
List<BeamPage> buildPages(BuildContext context, BeamState state) {
return [
BeamPage(
key: ValueKey('book-${state.pathParameters['bookId']}'),
title: books.firstWhere(
(book) => book['id'] == state.pathParameters['bookId'])['title'],
child: BookDetailsScreen(
book: books.firstWhere(
(book) => book['id'] == state.pathParameters['bookId']),
),
),
];
}
} And Navigate like below, context.beamTo(
BooksDetailLocation()
..state = BeamState(
pathPatternSegments: [
'books',
':bookId',
],
pathParameters: {"bookId": book['id'].toString()},
),
); And finally it would be great if you show me some example to use the super constructor to handle the creation of new state for beam location as you suggested. |
Hi @slovnicki any update on this ? |
Hey @ThalapathySiva, sorry for a late response. This is expected. The list of pages you return in You can read more about this in the Navigating Back section of README. Browser's back button is "reverse chronological", I should probably mention that in README. |
Can you please let me know the correct way of doing beamTo to particular location along with parameters like I have done above. @slovnicki |
@ThalapathySiva It depends on what you want. The most natural way would be to have all books related pages in the same Best is to navigate with, for example |
@slovnicki Thanks for the reply. |
Describe the bug
When using Navigator.pop(context) in the latest version of beamer(1.0.0), It throws the error
Navigator.pop(context); shows RangeError (index): Index out of range: index must not be negative: -1
. This problem happens when usingcontext.beamTo
instead ofcontext.beamToNamed
.Beamer version: (
v1.0.0
)To Reproduce
Steps to reproduce the behavior:
context.beamToNamed
tocontext.beamTo
.Expected behavior
To go back to previous screen instead of the error.
Desktop (please complete the following information):
Additional context
Flutter version: 2.5.3
The text was updated successfully, but these errors were encountered: