Challenge - 5 Problems
IconButton Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
IconButton Tap Behavior
What will happen when the user taps this IconButton in a Flutter app?
Flutter
IconButton(
icon: Icon(Icons.favorite),
onPressed: () {
print('Icon tapped');
},
)Attempts:
2 left
💡 Hint
Check what the onPressed callback does.
✗ Incorrect
The onPressed callback runs when the IconButton is tapped. Here, it prints a message to the console.
📝 Syntax
intermediate2:00remaining
Correct IconButton Syntax
Which option shows the correct way to create an IconButton with a tooltip and a disabled state?
Attempts:
2 left
💡 Hint
To disable an IconButton, onPressed must be null.
✗ Incorrect
Setting onPressed to null disables the IconButton. The tooltip shows on long press or hover.
❓ lifecycle
advanced2:00remaining
IconButton State and Rebuilds
If an IconButton's icon color depends on a boolean state variable 'isActive', which code snippet correctly updates the icon color when 'isActive' changes?
Attempts:
2 left
💡 Hint
Remember to call setState to update UI in StatefulWidget.
✗ Incorrect
Only option A calls setState to update the UI when isActive changes, so the icon color updates correctly.
advanced
2:00remaining
IconButton Triggering Navigation
Which IconButton code correctly navigates to a new screen named 'DetailsScreen' when tapped?
Attempts:
2 left
💡 Hint
Navigator.push requires a BuildContext and a MaterialPageRoute.
✗ Incorrect
Option C correctly uses Navigator.push with a MaterialPageRoute to navigate to DetailsScreen.
🔧 Debug
expert2:00remaining
Why Does This IconButton Not Respond?
Given this IconButton code, why does tapping the icon not trigger any action?
Flutter
IconButton( icon: Icon(Icons.send), onPressed: null, splashColor: Colors.red, disabledColor: Colors.grey, color: Colors.blue, onLongPress: null, tooltip: 'Send message', enableFeedback: false, mouseCursor: SystemMouseCursors.click, autofocus: false, focusNode: null, )
Attempts:
2 left
💡 Hint
Check if the button is enabled or disabled by properties.
✗ Incorrect
The onPressed property set to null disables the IconButton, so taps do nothing.