Google Flutter Google Flutter Navigation 1 — Questions and Answers
Question 1: Which method pushes a new route onto the Navigator stack in Flutter?
- Navigator.pop()
- Navigator.push() (Correct answer)
- Navigator.replace()
- Navigator.launch()
Correct answer: Navigator.push()
Navigator.push() adds a new route to the top of the navigation stack, navigating the user to a new screen.
Question 2: What does Navigator.pop() do?
- Pushes a new screen
- Removes the current route from the stack and returns to the previous screen (Correct answer)
- Replaces the current route
- Clears the entire navigation stack
Correct answer: Removes the current route from the stack and returns to the previous screen
Navigator.pop() removes the top route from the stack, returning control to the previous screen.
Question 3: Which Navigator method removes the current route and replaces it with a new one?
- Navigator.push()
- Navigator.pop()
- Navigator.pushReplacement() (Correct answer)
- Navigator.swap()
Correct answer: Navigator.pushReplacement()
Navigator.pushReplacement() replaces the current route with a new one, preventing the user from going back.
Question 4: What is a named route in Flutter?
- A route with an AppBar title
- A route identified by a string name registered in MaterialApp's routes map (Correct answer)
- A route that uses a custom transition animation
- A route that accepts URL query parameters
Correct answer: A route identified by a string name registered in MaterialApp's routes map
Named routes are identified by string identifiers registered in the routes map of MaterialApp, navigated to with Navigator.pushNamed().
Question 5: Which Flutter navigation package provides a declarative, URL-based routing system?
- go_router (Correct answer)
- page_route
- navigator_2
- url_strategy
Correct answer: go_router
go_router is the officially recommended Flutter package for declarative routing with URL support and deep linking.
Question 6: What is the purpose of the WillPopScope widget?
- To add a pop animation to a widget
- To intercept and control the back button press before popping the route (Correct answer)
- To style the navigation bar
- To push a route conditionally
Correct answer: To intercept and control the back button press before popping the route
WillPopScope intercepts the back navigation gesture or button, allowing you to confirm or prevent the pop.
Which method pushes a new route onto the Navigator stack in Flutter?