Challenge - 5 Problems
GoRouter Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
intermediate
2:00remaining
Understanding Basic Route Definition in GoRouter
Given the following GoRouter configuration, what is the initial screen shown when the app starts?
Flutter
final router = GoRouter( initialLocation: '/home', routes: [ GoRoute( path: '/home', builder: (context, state) => const HomeScreen(), ), GoRoute( path: '/settings', builder: (context, state) => const SettingsScreen(), ), ], );
Attempts:
2 left
💡 Hint
Look at the initialLocation property in the GoRouter setup.
✗ Incorrect
The initialLocation is set to '/home', so the GoRouter shows the HomeScreen widget first.
❓ ui_behavior
intermediate2:00remaining
Passing Parameters with GoRouter
What will be the output on the DetailsScreen when navigating to '/details/42' with this GoRouter setup?
Flutter
final router = GoRouter( routes: [ GoRoute( path: '/details/:id', builder: (context, state) { final id = state.params['id']; return DetailsScreen(id: id!); }, ), ], ); // DetailsScreen widget shows text: 'Item ID: <id>'
Attempts:
2 left
💡 Hint
Check how the parameter is extracted from state.params.
✗ Incorrect
The ':id' in the path captures '42' as a parameter, passed to DetailsScreen and displayed.
❓ lifecycle
advanced2:00remaining
GoRouter Refresh Listenable Behavior
If you want the GoRouter to rebuild routes when a user logs in or out, which of these is the correct way to trigger route refresh?
Flutter
class AuthNotifier extends ChangeNotifier { bool _loggedIn = false; bool get loggedIn => _loggedIn; void login() { _loggedIn = true; notifyListeners(); } void logout() { _loggedIn = false; notifyListeners(); } } final authNotifier = AuthNotifier(); final router = GoRouter( refreshListenable: authNotifier, routes: [ GoRoute( path: '/profile', builder: (context, state) => ProfileScreen(), ), ], );
Attempts:
2 left
💡 Hint
refreshListenable listens for notifyListeners calls.
✗ Incorrect
Calling notifyListeners() on the refreshListenable triggers GoRouter to rebuild routes.
📝 Syntax
advanced2:00remaining
Correct Syntax for Nested Routes in GoRouter
Which option correctly defines nested routes for '/dashboard' and '/dashboard/settings' using GoRouter?
Attempts:
2 left
💡 Hint
Nested routes use relative paths without leading slash in 'routes' list.
✗ Incorrect
Nested routes inside 'routes' use relative paths like 'settings' without leading slash.
🔧 Debug
expert2:00remaining
Identifying the Cause of a GoRouter Navigation Error
You get this error when navigating: 'Could not find a matching route for the path /profile'. Given this GoRouter setup, what is the cause?
Flutter
final router = GoRouter( routes: [ GoRoute( path: '/home', builder: (context, state) => HomeScreen(), ), GoRoute( path: '/settings', builder: (context, state) => SettingsScreen(), ), ], );
Attempts:
2 left
💡 Hint
Check if '/profile' is listed in the routes.
✗ Incorrect
The error occurs because '/profile' route is not defined in the GoRouter routes list.