Navigation & Routing Questions with Answers

14 practice questions on Navigation & Routing (Flutter & Dart) with answers and step-by-step solutions. Try 10 samples below, then practise all 14 free in the AptiNest app.

Sample questions

Question 1Easy

With named routes, how do you navigate to /settings?

  1. Navigator.pushNamed(context, '/settings')
  2. Route.open(context, '/settings')
  3. Navigator.goto('/settings')
  4. Navigator.push('/settings')

Answer: A. Navigator.pushNamed(context, '/settings')

Explanation

pushNamed looks up the name in the routes table (or onGenerateRoute) of the app.

Step-by-step solution

  1. PushNamed uses context to access navigator and route name.
  2. Navigator.pushNamed is the correct method for named routes.
  3. Other options like Route.open or Navigator.goto are not valid methods.
  4. Navigator.push requires a route object, not a string name.
  5. Correct syntax is Navigator.pushNamed(context, '/settings').

Why the other options are wrong

  • B. Route.open is not a Flutter API; navigation goes through the Navigator class.
  • C. Navigator.goto is not a Flutter method; the named push is Navigator.pushNamed.
  • D. Navigator.push takes a route object, not a name string, so this call does not compile.

Tip: Use Navigator.pushNamed(context, '/route') for named routes.

Question 2Easy

How does Flutter's Navigator manage screens?

  1. As a stack of routes
  2. As an unordered set of pages
  3. As a tree of tabs
  4. As a queue of routes

Answer: A. As a stack of routes

Explanation

push adds a route on top of the stack and pop removes the top route, revealing the one below.

Step-by-step solution

  1. Navigator keeps routes in a stack.
  2. Push adds a route on top and pop removes the top route.
  3. So Navigator manages screens as a stack of routes, which is option A.

Why the other options are wrong

  • B. Pages are not kept as an unordered set; the Navigator uses a stack.
  • C. Tabs are a separate widget, not how Navigator stores screens.
  • D. A queue is first in, first out; Navigator pops the most recent route.

Tip: Navigator.push adds a screen on top and Navigator.pop removes the top screen.

Question 3Easy

How can a screen return a value to the screen that opened it?

  1. Pass it to setState on the first screen's State
  2. Store it in a global variable read in the first screen's initState
  3. Pass it to Navigator.pop; the caller awaits Navigator.push
  4. Return it from the second screen's build method

Answer: C. Pass it to Navigator.pop; the caller awaits Navigator.push

Explanation

Navigator.push returns a Future that completes with the value given to Navigator.pop(context, value).

Step-by-step solution

  1. Call Navigator.push to open the second screen and await its result.
  2. In the second screen, call Navigator.pop(context, value) with the value to return.
  3. Navigator.push returns a Future that completes with the value given to Navigator.pop.
  4. Pass it to Navigator.pop; the caller awaits Navigator.push.

Why the other options are wrong

  • A. setState on the first screen's State does not return a value from the second screen to the caller.
  • B. A global read in initState runs before the second screen returns, so the value is not ready.
  • D. build returns widgets, not a value to a caller; a screen cannot return data that way.

Tip: Use await Navigator.push(...) and return data via Navigator.pop(context, data).

Question 4Easy

What does MaterialPageRoute provide?

  1. A list of all named routes declared in the app
  2. A widget that draws the Material app bar for a page
  3. A route that can only be opened as a modal dialog
  4. A route with platform-appropriate page transitions

Answer: D. A route with platform-appropriate page transitions

Explanation

MaterialPageRoute wraps a screen in a route with the platform's standard transition animation.

Step-by-step solution

  1. MaterialPageRoute is used to create routes in Flutter apps.
  2. It provides transitions that match the platform's design language.
  3. These transitions are consistent across Android and iOS devices.
  4. The route includes animations for entering and exiting pages.
  5. This ensures a native look and feel on all platforms.

Why the other options are wrong

  • A. MaterialPageRoute does not hold the list of named routes; that is the routes map on MaterialApp.
  • B. It is a route, not an app bar; the AppBar widget draws the bar.
  • C. It is not limited to dialogs; it is a full page route that is pushed onto the Navigator.

Tip: Use MaterialPageRoute for standard page transitions that match the platform's design.

Question 5Medium

A route is opened with Navigator.pushNamed(context, '/item', arguments: 42). How does the new screen read 42?

  1. ModalRoute.of(context)!.settings.arguments
  2. widget.arguments in its constructor
  3. Navigator.of(context).arguments
  4. context.read<RouteArgs>().value

Answer: A. ModalRoute.of(context)!.settings.arguments

Explanation

The arguments are stored in the route's RouteSettings, available through ModalRoute.of(context).

Step-by-step solution

  1. Navigator.pushNamed stores the argument in the route's RouteSettings.
  2. ModalRoute.of(context) returns the current route object.
  3. Read arguments with ModalRoute.of(context)!.settings.arguments.

Why the other options are wrong

  • B. The constructor does not receive route arguments; the screen reads them from its route.
  • C. Navigator itself has no arguments property; the value sits on the route's settings.
  • D. RouteArgs is not a provider the app registered; the value comes from RouteSettings.

Tip: Use ModalRoute.of(context)!.settings.arguments to get arguments on a new screen.

Question 6Medium

What does Navigator.pushAndRemoveUntil(context, route, (r) => false) do?

  1. Pushes the route and removes only the route below it
  2. Removes all routes and does not push the new route
  3. Pushes the route only if the stack is currently empty
  4. Pushes the route and removes every route below it

Answer: D. Pushes the route and removes every route below it

Explanation

The predicate decides which old routes to keep; returning false for every route clears the stack, as is common after logout.

Step-by-step solution

  1. Navigator.pushAndRemoveUntil adds a new route to the stack.
  2. The predicate (r) => false always returns false for every route.
  3. Returning false removes all existing routes from the stack.
  4. This clears the stack and pushes the new route on top.
  5. So it pushes the route and removes every route below it.

Why the other options are wrong

  • A. It removes every route below, not just one; the predicate returning false removes them all.
  • B. It does push the new route; the predicate only decides what is removed below it.
  • C. It pushes the route regardless of whether the stack is empty; the predicate does not check that.

Tip: Use pushAndRemoveUntil to clear the stack and add a new route in one step.

Question 7Medium

What does the declarative Router API (Navigator 2.0), used by packages like go_router, add over plain push/pop?

  1. It removes the need for a Navigator widget anywhere in the application tree
  2. It makes routes load on a background isolate to speed up page transitions
  3. The page stack is derived from app state, suiting deep links and URLs
  4. It only changes the transition animations between pages, nothing else

Answer: C. The page stack is derived from app state, suiting deep links and URLs

Explanation

With the Router API the list of pages is computed from state such as the current URL, so the browser address bar and deep links map cleanly onto the screen stack.

Step-by-step solution

  1. The page stack is built from app state like URLs and deep links.
  2. This ensures the UI matches the URL and deep links correctly.
  3. So routes are derived from app state, not just push/pop calls.
  4. This makes deep links and URLs work seamlessly with the screen stack.
  5. Final answer: The page stack is derived from app state, suiting deep links and URLs.

Why the other options are wrong

  • A. A Navigator widget is still used; the router API builds on it rather than removing it.
  • B. Route loading is not moved to isolates; the change is how the page stack is declared.
  • D. Transitions are not its main change; the difference is that the page stack follows app state.

Tip: Use Router API for URL-driven navigation in Flutter apps.

Question 8Medium

After a successful login you want the home screen, and back should not return to login. Which call fits?

  1. Navigator.restorablePush
  2. Navigator.pushReplacement
  3. Navigator.maybePop
  4. Navigator.push

Answer: B. Navigator.pushReplacement

Explanation

pushReplacement swaps the current route (login) for the new one (home), so there is nothing to go back to.

Step-by-step solution

  1. Navigator.pushReplacement replaces login with home, removing login from navigation stack.
  2. This ensures back button does not return to login screen.
  3. PushReplacement keeps home as the only route in history.
  4. Other options leave login in stack, allowing back navigation.
  5. Thus, Navigator.pushReplacement is correct.

Why the other options are wrong

  • A. restorablePush keeps login under home, so back can return to it.
  • C. maybePop only pops a route when possible; it cannot replace login with home.
  • D. push adds home on top of login, leaving login in history so back returns there.

Tip: Use pushReplacement to navigate to a new screen and prevent going back.

Question 9Hard

In MyApp's build, which returns MaterialApp, a button's onPressed calls Navigator.of(context).push(...) using MyApp's own context. What happens?

  1. Error: the context does not include a Navigator, as it is above MaterialApp
  2. It pushes onto a new Navigator that MaterialApp creates just for that call
  3. It works, because MaterialApp creates its Navigator before MyApp's build runs
  4. It silently does nothing, because no route is currently visible on screen

Answer: A. Error: the context does not include a Navigator, as it is above MaterialApp

Explanation

Navigator.of searches ancestors of the context. MaterialApp creates the Navigator below MyApp, so MyApp's context cannot find it; use a widget below MaterialApp.

Step-by-step solution

  1. MyApp’s build returns a MaterialApp widget as its child.
  2. Navigator.of looks for a Navigator in the ancestors of that context.
  3. Error: the context does not include a Navigator, as it is above MaterialApp.

Why the other options are wrong

  • B. MaterialApp does not create a hidden Navigator for one call; the lookup fails above it.
  • C. MaterialApp builds its Navigator after MyApp's build returns, so the context cannot reach it.
  • D. Nothing is silently ignored; the context lookup itself fails, so the call throws.

Tip: Obtain a context from a widget inside MaterialApp (e.g., Builder) to use Navigator.

Question 10Hard

A dialog opened with showDialog is visible on top of a page. Code calls Navigator.pop(context). What is removed?

  1. Nothing, because dialogs must be closed with dismiss()
  2. The dialog, since it is the top route on the stack
  3. The page underneath the dialog, while the dialog stays
  4. Both the dialog and the page below it at the same time

Answer: B. The dialog, since it is the top route on the stack

Explanation

Dialogs are routes pushed on the Navigator. pop removes the topmost route, which is the dialog.

Step-by-step solution

  1. Navigator.pop(context) removes the topmost route from the stack.
  2. Dialogs are added as routes to the navigator when shown.
  3. The dialog is the top route, so it gets removed first.
  4. The page underneath remains visible after the dialog is popped.
  5. Thus, only the dialog is removed.

Why the other options are wrong

  • A. Navigator.pop works on dialogs, which are routes; dismiss() is not a Flutter method for this.
  • C. The page below stays; pop removes only the top route, which here is the dialog.
  • D. pop removes one route per call, so the page below is not removed at the same time.

Tip: Remember: pop() always removes the topmost route, which is often the dialog.

Practise all 14 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all Flutter & Dart topics · All topics