Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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;
                    });
like image 341
mario francois Avatar asked Nov 14 '22 22:11

mario francois


1 Answers

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);
like image 157
mario francois Avatar answered Dec 05 '22 21:12

mario francois