PopUntil target Route? routes = A, B, C, D, если маршрут на D, всплывает до B - PullRequest
0 голосов
/ 08 мая 2020

Вот как я генерирую свои маршруты:

     switch (settings.name) {
      case '/':
        return CupertinoPageRoute(builder: (_) => SplashPage());
      case '/login':
        return CupertinoPageRoute(builder: (_) => LoginPage());
      case '/home':
        return CupertinoPageRoute(builder: (_) => HomePage());
      case '/catalogTree':
        return CupertinoPageRoute(builder: (_) => CatalogPageTree());
      case '/uploadImageCropper':
        return CupertinoPageRoute(
            builder: (_) =>
                UploadImageCropper(args: args != null ? args : null),
            fullscreenDialog: true);
      case '/uploadImageConfirm':
        return CupertinoPageRoute(
            builder: (_) =>
                UploadImageConfirm(args: args != null ? args : null),
            fullscreenDialog: true);
      case '/rentTree':
        return CupertinoPageRoute(builder: (_) => RentPageTree());
      case '/rentGallery':
        return CupertinoPageRoute(
            builder: (_) => RentImageGallery(args: args != null ? args : null));
      case '/cart':
        return CupertinoPageRoute(builder: (_) => CartPage());
     ...

В этом случае я нахожусь на B, и я нажимаю на C, затем на D с помощью:

Navigator.pushNamed(context, '/uploadImageCropper', arguments: {'img': imagePath, 'baseContext': context}); // /uploadImageCropper is page C in this example

Navigator.pushNamed(context, '/uploadImageConfirm', arguments: {'img': imagePath, 'baseContext': context}); // /uploadImageConfirm is page D in this example

// and just in case people ask, I guess page A is /home

I пробовал:

Navigator.of(context).popUntil(ModalRoute.withName("/catalogTree")); // /catalogTree is page B in this example

Но отправляет меня на черную страницу. Я просто хочу go со страницы D на страницу B

Navigator pushReplacement или push не очень эффективные решения, поскольку они либо исключают страницу A, либо дублируют маршруты.

...