Google Flutter Google Flutter Navigation 2 — Questions and Answers
Question 1: Which widget provides a bottom navigation bar for switching between top-level app destinations?
- TabBar
- BottomNavigationBar (Correct answer)
- NavigationRail
- Drawer
Correct answer: BottomNavigationBar
BottomNavigationBar displays icons and labels at the bottom of the screen for switching between top-level views.
Question 2: How does Navigator 2.0 differ from Navigator 1.0 in Flutter?
- Navigator 2.0 uses a Stack widget instead of Navigator
- Navigator 2.0 is declarative and uses a pages list, enabling URL-driven navigation (Correct answer)
- Navigator 2.0 only works on web
- Navigator 2.0 removes named routes
Correct answer: Navigator 2.0 is declarative and uses a pages list, enabling URL-driven navigation
Navigator 2.0 uses a declarative pages list driven by app state, making back-stack management and deep linking explicit.
Question 3: What does Navigator.pushAndRemoveUntil() do?
- Pushes a route and removes all routes from the stack up to a predicate condition (Correct answer)
- Pushes a route and removes only the current route
- Pushes a route and schedules a pop after a delay
- Replaces the entire route stack with a single route
Correct answer: Pushes a route and removes all routes from the stack up to a predicate condition
pushAndRemoveUntil pushes a new route and removes all routes below it until the predicate returns true.
Question 4: Which widget creates a side drawer that slides in from the left edge?
- SidePanel
- NavigationRail
- Drawer (Correct answer)
- ModalBottomSheet
Correct answer: Drawer
Drawer is a Material Design panel that slides in from the side, typically assigned to the drawer property of Scaffold.
Question 5: In go_router, which parameter specifies the initial location when the app launches?
- initialRoute
- initialPath
- initialLocation (Correct answer)
- startPath
Correct answer: initialLocation
The initialLocation parameter of GoRouter sets the URL path the app navigates to on launch.
Question 6: What is deep linking in the context of Flutter navigation?
- Linking two widgets together programmatically
- Navigating to a specific screen via a URL or universal link from outside the app (Correct answer)
- Creating nested navigators
- Sharing state between routes
Correct answer: Navigating to a specific screen via a URL or universal link from outside the app
Deep linking allows an external URL or push notification to open the app and navigate directly to a specific screen.
Which widget provides a bottom navigation bar for switching between top-level app destinations?