Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a scroll controller for infinite scrolling.
Flutter
final ScrollController [1] = ScrollController(); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using vague or unrelated variable names.
Forgetting to declare the ScrollController.
✗ Incorrect
The common and clear name for a scroll controller is 'scrollController'.
2fill in blank
mediumComplete the code to add a listener to the scroll controller.
Flutter
scrollController.[1](() { if (scrollController.position.pixels == scrollController.position.maxScrollExtent) { // Load more items } });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like 'onScroll' or 'listen'.
Forgetting to add the listener.
✗ Incorrect
In Flutter, 'addListener' is used to listen for scroll events.
3fill in blank
hardFix the error in the code to check if the user scrolled to the bottom.
Flutter
if (scrollController.position.[1] == scrollController.position.maxScrollExtent) { fetchMoreData(); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'offset' or 'position' which are not valid properties here.
Confusing 'extent' with current position.
✗ Incorrect
The 'pixels' property gives the current scroll position in pixels.
4fill in blank
hardFill both blanks to create a ListView with infinite scrolling using the scroll controller.
Flutter
ListView.builder( controller: [1], itemCount: items.length + 1, itemBuilder: (context, index) { if (index == items.length) { return [2]; } return ListTile(title: Text(items[index])); }, )
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Creating a new ScrollController inside the ListView.
Returning null instead of a loading widget.
✗ Incorrect
The ListView uses the existing scrollController and shows a loading spinner at the end.
5fill in blank
hardFill all three blanks to dispose the scroll controller properly in a StatefulWidget.
Flutter
@override void [1]() { [2].dispose(); super.[3](); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Calling dispose on the wrong object.
Forgetting to call super.dispose().
✗ Incorrect
The dispose method is overridden to dispose the scrollController and then call super.dispose().