0
0
Fluttermobile~20 mins

IconButton in Flutter - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
IconButton Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2: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');
  },
)
AThe icon changes color automatically when tapped.
BThe app crashes because IconButton requires a child widget.
CNothing happens because onPressed is not set.
DThe message 'Icon tapped' is printed in the console each time the icon is tapped.
Attempts:
2 left
💡 Hint
Check what the onPressed callback does.
📝 Syntax
intermediate
2:00remaining
Correct IconButton Syntax
Which option shows the correct way to create an IconButton with a tooltip and a disabled state?
AIconButton(icon: Icon(Icons.add), tooltip: 'Add', onPressed: null)
BIconButton(icon: Icon(Icons.add), tooltip: 'Add', onPressed: () => null)
CIconButton(icon: Icon(Icons.add), tooltip: 'Add', onPressed: {})
DIconButton(icon: Icon(Icons.add), tooltip: 'Add')
Attempts:
2 left
💡 Hint
To disable an IconButton, onPressed must be null.
lifecycle
advanced
2: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?
AIconButton(icon: Icon(Icons.star, color: isActive ? Colors.yellow : Colors.grey), onPressed: () { setState(() { isActive = !isActive; }); })
BIconButton(icon: Icon(Icons.star, color: Colors.yellow), onPressed: () { isActive = !isActive; })
CIconButton(icon: Icon(Icons.star), onPressed: () { setState(() { isActive = !isActive; }); })
DIconButton(icon: Icon(Icons.star, color: isActive ? Colors.yellow : Colors.grey), onPressed: () { isActive = !isActive; })
Attempts:
2 left
💡 Hint
Remember to call setState to update UI in StatefulWidget.
navigation
advanced
2:00remaining
IconButton Triggering Navigation
Which IconButton code correctly navigates to a new screen named 'DetailsScreen' when tapped?
AIconButton(icon: Icon(Icons.navigate_next), onPressed: () { Navigator.pushNamed(context, 'DetailsScreen'); })
BIconButton(icon: Icon(Icons.navigate_next), onPressed: () { Navigator.pop(context); })
CIconButton(icon: Icon(Icons.navigate_next), onPressed: () { Navigator.push(context, MaterialPageRoute(builder: (context) => DetailsScreen())); })
DIconButton(icon: Icon(Icons.navigate_next), onPressed: () { Navigator.push(context, DetailsScreen()); })
Attempts:
2 left
💡 Hint
Navigator.push requires a BuildContext and a MaterialPageRoute.
🔧 Debug
expert
2: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,
)
ABecause onPressed is an empty function, so no action occurs.
BBecause the 'onPressed' property is set to null, disabling the button.
CBecause splashColor is set, it blocks the tap event.
DBecause onLongPress is null, the button is disabled.
Attempts:
2 left
💡 Hint
Check if the button is enabled or disabled by properties.