slovnicki / beamer

A routing package built on top of Router and Navigator's pages API, supporting arbitrary nested navigation, guards and more.
MIT License
582 stars 128 forks source link

Defining `beamBackOnPop` in BeamLocation constructor does not work #628

Open haqqi opened 11 months ago

haqqi commented 11 months ago

Beamer version: 1.5.6

Describe the bug

Developing for Android app. The original behavior of Beamer (i suppose) it is like:

  1. Render to /auth/login.
  2. From login page, I want to beam to /auth/register (register page).
  3. From register page, when I push back button (andorid) or app bar's back button, the route will be popped /auth, which is not found in my setup. The behavior i want is beam back.
  4. Setting up alwaysBeamBack in BeamerBackButtonDispatcher will solve the behavior of android back button. But not app bar back button.

Well, it can be solved by putting parameter beamBackOnPop to true whenever I call the navigation method. Such as:

Beamer.of(context).beamToNamed(
  '/auth/register`,
  beamBackOnPop: true,
);

This is kinda frustating to set it on every navigation.

Then, I noticed there is a parameter for BeamLocation, which is BeamParameters that has beamBackOnPop. Nice.

But, when I set the parameters, it won't work. It is still running on original behavior, which is removing the last URI.

AuthLocation()
    : super(
        null,
        const BeamParameters(
          beamBackOnPop: true,
        ),
      ); 

Expected behavior

Because the "key concepts" of Beamer, I think this parameter exists to solve the responsibility separation. So, if i am not wrong, the correct behavior should be:

If I set the beamBackOnPop parameters to true in BeamLocation child classes, whenever the route goes to that location, the beamback will be chosen as default pop mechanism.

Smartphone: Xiami Mi 8 with latest PixelExperience ROM

Additional context For now, as I need to finish the project quickly, I go with workaround by setting up beamBackOnPop parameter each time when I called beamToNamed function.

Also, if possible, may be there should be a BeamParameter that can be set up in global for BeamerDelegate.

SAGARSURI commented 6 days ago

@slovnicki any update on this?