0
0
Fluttermobile~20 mins

Infinite scrolling in Flutter - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Infinite Scrolling Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
Detecting scroll position for infinite scrolling
In Flutter, which code snippet correctly detects when the user has scrolled to the bottom of a ListView to trigger loading more items?
Flutter
ScrollController _controller = ScrollController();

_controller.addListener(() {
  if (_controller.position.pixels == _controller.position.maxScrollExtent) {
    // Load more items
  }
});
Aif (_controller.position.pixels >= _controller.position.minScrollExtent) { /* load more */ }
Bif (_controller.position.pixels == _controller.position.maxScrollExtent) { /* load more */ }
Cif (_controller.offset == 0) { /* load more */ }
Dif (_controller.position.atEdge) { /* load more */ }
Attempts:
2 left
💡 Hint
Think about when the scroll position reaches the bottom edge.
lifecycle
intermediate
1:30remaining
Properly disposing ScrollController
Which Flutter widget lifecycle method is the best place to dispose a ScrollController to avoid memory leaks?
Adispose()
BinitState()
CdidChangeDependencies()
Dbuild()
Attempts:
2 left
💡 Hint
Think about cleaning up resources when the widget is removed.
📝 Syntax
advanced
2:30remaining
Correct async data loading in infinite scroll
Which code snippet correctly loads more data asynchronously when the user scrolls to the bottom, updating the UI in Flutter?
Flutter
void _loadMore() async {
  final newItems = await fetchItems();
  setState(() {
    items.addAll(newItems);
  });
}

_controller.addListener(() {
  if (_controller.position.pixels == _controller.position.maxScrollExtent) {
    _loadMore();
  }
});
AUse async function _loadMore with await fetchItems and call setState to add new items.
BCall fetchItems without await and update items directly without setState.
CUse a synchronous function to fetch items and update items inside setState.
DCall setState before await fetchItems to update UI early.
Attempts:
2 left
💡 Hint
UI updates must happen inside setState after data is ready.
navigation
advanced
2:30remaining
Maintaining scroll position after navigation
After navigating back to a screen with infinite scrolling, which approach preserves the scroll position in Flutter?
AUse a GlobalKey to rebuild the entire widget tree.
BCreate a new ScrollController every time the widget rebuilds.
CReset the scroll position to zero in initState().
DKeep the ScrollController as a member variable and do not recreate it on rebuild.
Attempts:
2 left
💡 Hint
Think about keeping the controller alive to remember scroll offset.
🧠 Conceptual
expert
3:00remaining
Handling rapid scroll events in infinite scrolling
What is the best way to prevent multiple simultaneous data fetches when the user scrolls quickly to the bottom multiple times in Flutter infinite scrolling?
ACall the data fetch function every time the scroll reaches bottom without checks.
BClear the items list before each fetch to avoid duplicates.
CUse a boolean flag to track if a fetch is in progress and ignore new fetch requests until done.
DUse a timer to delay all fetches by 5 seconds.
Attempts:
2 left
💡 Hint
Think about how to avoid starting a new fetch before the previous finishes.