Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to navigate to the DetailScreen with Navigator.
Flutter
Navigator.of(context).[1](MaterialPageRoute(builder: (context) => DetailScreen())); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop instead of push causes the app to go back instead of forward.
Using pushReplacement removes the previous screen, which is not always desired.
✗ Incorrect
Use push to go to a new screen.
2fill in blank
mediumComplete the code to pass a string message to DetailScreen constructor.
Flutter
Navigator.of(context).push(MaterialPageRoute(builder: (context) => DetailScreen(message: [1]))); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing unquoted text causes errors.
Passing variable names that are not defined.
✗ Incorrect
Strings must be in quotes to pass as text.
3fill in blank
hardFix the error in DetailScreen constructor to accept the message parameter.
Flutter
class DetailScreen extends StatelessWidget { final String [1]; DetailScreen({required this.message}); @override Widget build(BuildContext context) { return Scaffold(body: Center(child: Text(message))); } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different variable name than the constructor parameter.
Forgetting to declare the variable as final.
✗ Incorrect
The variable name must match the constructor parameter name.
4fill in blank
hardFill both blanks to extract the passed message and display it in Text widget.
Flutter
final String [1] = ModalRoute.of(context)!.settings.arguments as [2]; return Scaffold(body: Center(child: Text([1])));
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Casting to wrong type like int.
Using different variable names inconsistently.
✗ Incorrect
Use the same variable name to store the argument and cast it to String.
5fill in blank
hardFill all three blanks to pass and receive a Map with 'title' and 'body' keys between screens.
Flutter
Navigator.of(context).push(MaterialPageRoute(builder: (context) => DetailScreen(data: [1]))); // In DetailScreen final Map<String, String> [2]; Text([3]['title'] ?? 'No Title')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing data as a string instead of a Map.
Using different variable names for the Map.
✗ Incorrect
Pass a Map literal, receive it as 'data', and access 'title' key.