mario francois
mario francois

Reputation: 1371

pushReplacement or pushAndRemoveUntil(Route<dynamic> route) => false not Working

A page-based route cannot be completed using imperative api, provide a new list without the corresponding Page to Navigator.pages instead. 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 3075 pos 7: '!hasPage || isWaitingForExitingDecision'

Only Navigator.push works. Before Flutter 2 it was working.

Navigator.pushAndRemoveUntil(
                    context,
                    PageRouteBuilder(
                      transitionDuration: const Duration(milliseconds: 3300),
                      transitionsBuilder: (BuildContext context,
                          Animation<double> animation,
                          Animation<double> secondaryAnimation,
                          Widget child) {
                        return _CustomPageTransition(
                            routeAnimation: animation,
                            fullscreenDialog: false,
                            child: child);
                      },
                      pageBuilder: (_, __, ___) => LoginScreen(),
                    ),
                    (route) {
                      print(route.settings.name);
                      return false;
                    });

Upvotes: 6

Views: 3840

Answers (1)

mario francois
mario francois

Reputation: 1371

It's an old question that nowaday I solved it by using auto_route package. But I think if you use Navigator.replace it will work.

AutoRouter.of(context).replaceNamed(LoginScreenRoute().path);

Or

AutoRouter.of(context).replace(LoginScreenRoute());

In the MaterialAutoRouter:

@MaterialAutoRouter(routes: <AutoRoute>[
AutoRoute(page: RouteAuthentication, initial: true),
CustomRoute(
    page: LoginScreen,
    fullscreenDialog: true,
    transitionsBuilder: TransitionsBuilders.slideLeftWithFade,durationInMilliseconds: 3300
),])

In my case I wanted to animate with the Hero widget. But the code below doesn't work.

AutoRouter.of(context).pushAndPopUntil(LoginScreenRoute(),
                  predicate: (_) => false);

Upvotes: 1

Related Questions