Home:ALL Converter>Flutter navigation push, while keeping the same Appbar

Flutter navigation push, while keeping the same Appbar

Ask Time:2021-03-23T07:47:18         Author:L. Gangemi

Json Formatter

I'm currently building a Flutter app where I'm struggling to figure out the best way to implement navigation.

I have 2 pages which are:

  • HomePage: from there I want to use an IndexedStack to manage the feed.
  • ProfilePage: the profile page, which (graphically) shares the same AppBar and the same Drawer as the home page.

In my App the user reaches the HomePage immediately after logging in. There is no navigation involved.

From there, I now have a TextButton, which calls Navigator.of(context).pushNamed(AppRoutes.profile).

As I said, both pages share the same Appbar and Drawer, so I created a custom myScaffold. Both pages use this scaffold.

So the behavior is correct, since after clicking the button, the ProfilePage is moved over the HomePage.

My problem is that graphically the appbar should remain the same, but when the profile page is pushed, the animation makes it clear that it is not the same app bar.

  • Is it possible to animate the entry of the profile page, without animating the rebuilding of the appbar?

  • Or is it possible to push a route directly into the scaffold content?

  • As an alternative I was just thinking of writing a function which returns the page widget to be displayed within the scaffold content. But this kind of approach doesn't seem right to me, since there are routes.

From the official documentation you can see from the Interactive example what I mean: Docs

When the second route is built over the first one, a new Appbar is built over the previous one. But what if I need the appbar to stay the same?

Author:L. Gangemi,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/66755344/flutter-navigation-push-while-keeping-the-same-appbar
yy