'Couldn't handle popUntil()

I have an AppRouter like this;

  class AppRouter {
  //static const String homeScreen = '/';
  static const String mapScreen = '/';
  static const String filterByIndoorLevelsScreen = '/filter-by-indoor-levels';
  static const String filterByLocationPointsScreen =
      '/filter-by-location-points';

  const AppRouter._();

  static Route<dynamic> onGenerateRoute(RouteSettings settings) {
    switch (settings.name) {
      case mapScreen:
        return MaterialPageRoute(builder: (_) => MapScreen());

      case filterByIndoorLevelsScreen:
        return MaterialPageRoute(builder: (_) => FilterByIndoorLevelsScreen());

      case filterByLocationPointsScreen:
        return MaterialPageRoute(
            builder: (_) => FilterByLocationPointsScreen(
                  args: settings.arguments
                      as FilterByLocationPointsScreenArguments,
                ));

                ....
                .......

      default:
        throw const RouteException('Route not found!');
    }
  }
}

I am pushing pages like this Navigator.of(context).pushNamed(AppRouter.filterByIndoorLevelsScreen)

And something like this is not working puts me in a black screen with nothing in debug console:

Navigator.of(context).popUntil(ModalRoute.withName(AppRouter.mapScreen))

I've tried Navigator.of(context).popUntil((route) => route.settings.name == AppRouter.mapScreen) as stated in comments belov. Still puts me in a black screen

It works when i write Navigator.of(context).popUntil((route) => route.isFirst); but what if i wanted to go another screen instead of the first page?



Solution 1:[1]

I've solved it by using

Navigator.of(context).pushNamedAndRemoveUntil(AppRouter.mapScreen, (route) => false)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1