0
0
Fluttermobile~20 mins

Pull-to-refresh in Flutter - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Pull-to-refresh Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
What happens when you pull down on a ListView wrapped with RefreshIndicator?

Consider a Flutter app with a RefreshIndicator wrapping a ListView. What is the expected behavior when the user pulls down on the list?

Flutter
RefreshIndicator(
  onRefresh: () async {},
  child: ListView.builder(
    itemCount: 10,
    itemBuilder: (context, index) => ListTile(title: Text('Item $index')),
  ),
)
AA loading spinner appears at the top and the onRefresh callback is triggered.
BThe list scrolls up without any visual feedback or callback.
CThe app crashes because RefreshIndicator cannot wrap ListView.
DNothing happens because onRefresh is empty.
Attempts:
2 left
💡 Hint

Think about what RefreshIndicator is designed to do when the user pulls down.

lifecycle
intermediate
1:30remaining
What is the correct return type of the onRefresh callback in RefreshIndicator?

In Flutter's RefreshIndicator, what must the onRefresh callback return?

AFuture<void>
Bvoid
Cbool
Dint
Attempts:
2 left
💡 Hint

Consider that the refresh action is asynchronous and the indicator waits for it to complete.

📝 Syntax
advanced
2:30remaining
Which code snippet correctly implements pull-to-refresh with RefreshIndicator?

Choose the Flutter code snippet that correctly implements a pull-to-refresh feature using RefreshIndicator and updates the list items.

Flutter
class MyList extends StatefulWidget {
  @override
  State<MyList> createState() => _MyListState();
}

class _MyListState extends State<MyList> {
  List<String> items = ['A', 'B', 'C'];

  Future<void> _refresh() async {
    await Future.delayed(Duration(seconds: 1));
    setState(() {
      items.add('D');
    });
  }

  @override
  Widget build(BuildContext context) {
    return RefreshIndicator(
      onRefresh: _refresh,
      child: ListView.builder(
        itemCount: items.length,
        itemBuilder: (context, index) => ListTile(title: Text(items[index])),
      ),
    );
  }
}
AChange onRefresh to: onRefresh: () { _refresh(); }
BThe code above as is.
CChange _refresh to return void instead of Future<void>.
DRemove setState call inside _refresh.
Attempts:
2 left
💡 Hint

Remember that onRefresh expects a Future and setState updates UI.

🔧 Debug
advanced
2:00remaining
Why does the RefreshIndicator spinner never disappear?

A developer uses RefreshIndicator but the spinner stays visible forever after pulling down. What is the most likely cause?

Flutter
RefreshIndicator(
  onRefresh: () async {
    // Forgot to complete the future
  },
  child: ListView(...),
)
AThe RefreshIndicator must be inside a Scaffold.
BThe ListView is not scrollable, so RefreshIndicator doesn't work.
CThe onRefresh callback must return void, not Future.
DThe onRefresh future never completes, so spinner stays visible.
Attempts:
2 left
💡 Hint

Think about what controls the spinner visibility.

🧠 Conceptual
expert
2:30remaining
How to enable pull-to-refresh only when the list is scrolled to the top?

In Flutter, how does RefreshIndicator ensure that pull-to-refresh activates only when the scrollable is at the top?

AIt requires a manual check in onRefresh to verify scroll position.
BIt triggers pull-to-refresh regardless of scroll position.
CIt listens to the scroll position and triggers only if offset is zero or less.
DIt disables pull-to-refresh if the list has more than 10 items.
Attempts:
2 left
💡 Hint

Think about how scroll position affects user gestures.