B. Using Scaffold.of(context) inside appBar's leading causes context error
C. IconButton icon is incorrect for drawer
D. Body widget should be a ListView for drawer to work
Solution
Step 1: Understand context usage in Scaffold
Calling Scaffold.of(context) inside appBar's leading uses a context that is above Scaffold, causing an error.
Step 2: Identify correct way to open drawer
Use a Builder widget or a GlobalKey to get a context below Scaffold to open drawer properly.
Final Answer:
Using Scaffold.of(context) inside appBar's leading causes context error -> Option B
Quick Check:
Context must be below Scaffold to open drawer [OK]
Hint: Scaffold.of(context) needs context inside Scaffold, not appBar [OK]
Common Mistakes:
Assuming drawer needs ListView to open
Thinking icon choice affects drawer opening
Believing body widget type affects drawer
5. You want to create a drawer with a header and three clickable items that navigate to different screens. Which code snippet correctly implements this behavior?
A)
A. Uses Column with onTap that closes drawer and navigates correctly
B. Uses ListView but ListTiles have no onTap, so no navigation
C. Uses ListView with onTap only closing drawer, no navigation
D. Uses Column with onTap navigating to screens but does not close drawer
Solution
Step 1: Check navigation and drawer closing
To navigate and close drawer, use Navigator.popAndPushNamed inside onTap.
Step 2: Compare layout widgets
Column works but may cause overflow; ListView is better for scrolling but not required here.
Step 3: Evaluate options
Column with pushNamed navigates but drawer stays open; ListView without onTap has no navigation; ListView with pop only closes drawer; Column with popAndPushNamed closes drawer and navigates properly.
Final Answer:
Uses Column with onTap that closes drawer and navigates correctly -> Option A
Quick Check:
popAndPushNamed closes drawer and navigates [OK]
Hint: Use popAndPushNamed to close drawer and navigate [OK]
Common Mistakes:
Not closing drawer before navigation
Missing onTap handlers on ListTile
Using Navigator.pop only closes drawer without navigation
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.