sosnus
sosnus

Reputation: 1340

Flutter Navigator - push to the same page

how is the best way to push to the same page?

I have route A>B>C

and now, at page C I want do action, and after it I want push to C, but remove old C from route, so:

I have: A>B>C

And execute this code on Page C

Navigator.of(context).pushReplacement(
                  MaterialPageRoute(
                    builder: (context) => C(param: myParam),
                  ),
                );

And I have A>B>C>C How to change this code to get new route ' A>B>C' after second push to page C? I just want delete last navigation from route

Upvotes: 0

Views: 2312

Answers (2)

sosnus
sosnus

Reputation: 1340

Sum up, my new solution:

      child: MaterialApp(
        onGenerateRoute: _getRoute,
        home: PgSelectStartup(),
      ),

// _getRoute
  Route<dynamic> _getRoute(RouteSettings settings) {
    if (settings.name == '/C') {
      return _buildRoute(
          settings,
          new PgConsultationsView(
              consultation: settings.arguments as MyParamClass));
    }



And call it:

Navigator.popAndPushNamed(context, "/C",
                    arguments: myParam);

Upvotes: 0

quim
quim

Reputation: 214

If you are in the same page you want to push, you could do:

Navigator.popAndPushNamed(context, C);

Which will pop current page (C) and push C.

Upvotes: 1

Related Questions