beamer
beamer copied to clipboard
App was closed when I pressed on back button
https://github.com/slovnicki/beamer/tree/master/examples/bottom_navigation_multiple_beamers
base on the example above, when I navigated from "books" -> "articles". at this moment, the app will be close when I pressed on back button on android while I am on "articles" screen.
is there a way that I can go back to the previous screen which is "books" screen when I hit the back button?
Hey @iEricKoh :wave: Thanks for creating an issue and sorry for a late response.
This seems like a bug, indeed.
A temporary solution can be to include a timestamp (or anything that will not stay the same) into the key
for root BeamPage
, something like this in the routerDelegate
for MaterialApp.router
:
locationBuilder: RoutesLocationBuilder(
routes: {
'*': (context, state, data) => BeamPage(
key: ValueKey(
'${state.routeInformation.location}-${DateTime.now()}',
),
child: AppScreen(),
),
},
),
The problem is because all the navigation is done inside inner Beamers and the key
of this root BeamPage
stays the same so it never rebuilds, not even when we do want to rebuild it, because what happens is:
-
AppScreen
gets wrapped withBeamPage
internally and Beamer creates a key from the initial path, that's/books
- We navigate with bottom tabs to
/articles
, but handle that without doing anything on the root Beamer, i.e we don't rebuild theAppScreen
with key containing/articles
. Generally, this is what we want, not rebuilding everything because we would lose state of inner Beamers - Then we press the Android back button
- it tries to
pop
, cannot - it tries to
beamBack
, can - it calls
beamBack
(which beams to/books
) on the root router -
AppScreen
was already wrapped withBeamPage
withkey: ValueKey('/books')
so theNavigator
thinks it doesn't need to rebuild anything
- it tries to
I'll definitely try to solve this issue so we don't need the above workaround :thinking:
@slovnicki Thanks for your solutions and the reason why it didn't works.
I've tried the solution above and it works fine!
tho there's still something wrong when I tried more complex routing between two different tabs.
Books -> Articles -> (press back) -> Books // works
Books -> Articles -> Single Article -> tap Books tab ->
tap Articles tab(displaying single article) -> (press back) ->
Articles -> (press back) -> app closed // it should go to books tab, isn't it?
Sorry for a late response @iEricKoh :disappointed:
At first, sounds a bit like a bug with beamingHistory
being cleared too much :thinking:
There's a property in BeamerDelegate
called removeDuplicateHistory
. Try setting it to false
and see do you observe the same behavior (or buggy in some other way). If yes, I think you can create a new issue for this.
Thanks!
I have the same issue but workarounds didnt solved the problem. I am digging to get more info / more explanations
SOLVED :
added MaterialApp.router(
backButtonDispatcher: BeamerBackButtonDispatcher( delegate: routerDelegate as BeamerDelegate, ),