0
0
Fluttermobile~20 mins

ListView.separated in Flutter - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
ListView.separated Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
What is the output of this Flutter code snippet?

Consider this Flutter widget using ListView.separated:

ListView.separated(
  itemCount: 3,
  itemBuilder: (context, index) => Text('Item $index'),
  separatorBuilder: (context, index) => Divider(color: Colors.red),
)

What will the UI display?

Flutter
ListView.separated(
  itemCount: 3,
  itemBuilder: (context, index) => Text('Item $index'),
  separatorBuilder: (context, index) => Divider(color: Colors.red),
)
AA vertical list showing: Item 0, red divider, Item 1, red divider, Item 2
BA vertical list showing: Item 0, Item 1, Item 2 with no dividers
CA vertical list showing: red divider, Item 0, red divider, Item 1, red divider, Item 2
DA vertical list showing: Item 0, red divider, Item 1 only (Item 2 missing)
Attempts:
2 left
💡 Hint

Remember that separatorBuilder inserts widgets between items, not before the first or after the last.

lifecycle
intermediate
1:30remaining
How many times is the separatorBuilder called in this ListView.separated?

Given this code:

ListView.separated(
  itemCount: 5,
  itemBuilder: (context, index) => Text('Item $index'),
  separatorBuilder: (context, index) => SizedBox(height: 10),
)

How many times will separatorBuilder be called during build?

Flutter
ListView.separated(
  itemCount: 5,
  itemBuilder: (context, index) => Text('Item $index'),
  separatorBuilder: (context, index) => SizedBox(height: 10),
)
A5 times
B1 time
C6 times
D4 times
Attempts:
2 left
💡 Hint

Separators appear only between items, not after the last item.

📝 Syntax
advanced
2:00remaining
What error does this ListView.separated code produce?

Analyze this Flutter code snippet:

ListView.separated(
  itemCount: 3,
  itemBuilder: (context, index) => Text('Item $index'),
  separatorBuilder: (context, index) => Text('Separator'),
  itemBuilder: (context, index) => Text('Duplicate'),
)

What error will occur?

Flutter
ListView.separated(
  itemCount: 3,
  itemBuilder: (context, index) => Text('Item $index'),
  separatorBuilder: (context, index) => Text('Separator'),
  itemBuilder: (context, index) => Text('Duplicate'),
)
ARuntime error: separatorBuilder called twice
BSyntaxError: Duplicate named parameter 'itemBuilder'
CNo error, runs fine showing duplicate itemBuilder widgets
DTypeError: itemBuilder must return a Widget
Attempts:
2 left
💡 Hint

Check the parameters passed to the constructor carefully.

navigation
advanced
2:30remaining
How to preserve scroll position when navigating back to a ListView.separated?

You have a ListView.separated inside a screen. When you navigate to another screen and come back, the list resets to the top. How to keep the scroll position?

ASet <code>itemCount</code> to null to preserve state
BWrap ListView.separated with a <code>SingleChildScrollView</code>
CUse a ScrollController and keep it alive with a StatefulWidget
DUse <code>Navigator.pushReplacement</code> instead of <code>push</code>
Attempts:
2 left
💡 Hint

Think about how Flutter remembers scroll positions.

🧠 Conceptual
expert
3:00remaining
Why does ListView.separated improve performance over ListView.builder with manual dividers?

Consider two Flutter lists:

  • One uses ListView.builder with manual dividers inside itemBuilder.
  • The other uses ListView.separated with a separatorBuilder.

Why is ListView.separated often more efficient?

ABecause it builds separators only when needed and optimizes widget reuse
BBecause it caches all items and separators in memory upfront
CBecause it disables scrolling to improve performance
DBecause it uses a different rendering engine than ListView.builder
Attempts:
2 left
💡 Hint

Think about how Flutter builds widgets lazily and reuses them.