A. Using context from build inside showMessage causes an error
B. SnackBar content must be a String, not Text widget
C. ElevatedButton cannot be used inside build method
D. showSnackBar is not a method of ScaffoldMessenger
Solution
Step 1: Identify context usage in showMessage()
The method uses context but it is not passed as a parameter, so it refers to the widget's field or outer scope.
Step 2: Understand context scope in Flutter
Using the context from build inside another method without passing it can cause errors because context may not be valid or accessible.
Final Answer:
Using context from build inside showMessage causes an error -> Option A
Quick Check:
Context must be passed to callbacks [OK]
Hint: Pass context explicitly to methods needing it [OK]
Common Mistakes:
Assuming context is always accessible everywhere
Thinking SnackBar content must be String
Believing ElevatedButton can't be in build
Confusing ScaffoldMessenger methods
5. You want to open a new screen when a button is pressed. Which is the best way to use BuildContext to navigate safely inside the button's onPressed callback?
hard
A. Use setState() to change the screen instead of Navigator
B. Create a new BuildContext inside the callback and call Navigator.push()
C. Pass the BuildContext from the build method to the callback and use Navigator.of(context).push()