0
0
Fluttermobile~20 mins

CustomScrollView in Flutter - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
CustomScrollView Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
What is the visible output of this CustomScrollView code?
Consider this Flutter code snippet using CustomScrollView. What will the user see on the screen?
Flutter
CustomScrollView(
  slivers: [
    SliverAppBar(
      expandedHeight: 150,
      flexibleSpace: FlexibleSpaceBar(
        title: Text('Hello'),
      ),
      pinned: true,
    ),
    SliverList(
      delegate: SliverChildBuilderDelegate(
        (context, index) => ListTile(title: Text('Item $index')),
        childCount: 3,
      ),
    ),
  ],
)
AA scrollable list with a pinned app bar titled 'Hello' that stays visible on top while scrolling through 3 list items.
BA static app bar with title 'Hello' and a non-scrollable list of 3 items below it.
CAn error because SliverAppBar cannot be used inside CustomScrollView.
DA scrollable list with no app bar visible and 3 list items.
Attempts:
2 left
💡 Hint
Remember that SliverAppBar with pinned:true stays visible when scrolling.
lifecycle
intermediate
2:00remaining
What happens when you scroll up in this CustomScrollView?
Given this CustomScrollView with a SliverAppBar that has floating: true and snap: true, what is the behavior when the user scrolls up slightly?
Flutter
CustomScrollView(
  slivers: [
    SliverAppBar(
      floating: true,
      snap: true,
      expandedHeight: 100,
      flexibleSpace: FlexibleSpaceBar(title: Text('Snap AppBar')),
    ),
    SliverList(
      delegate: SliverChildListDelegate(List.generate(10, (i) => ListTile(title: Text('Item $i')))),
    ),
  ],
)
AThe app bar expands and collapses smoothly without snapping.
BThe app bar stays hidden until the user scrolls to the top of the list.
CThe app bar immediately snaps open and becomes fully visible when the user scrolls up slightly.
DThe app bar disappears permanently after scrolling.
Attempts:
2 left
💡 Hint
Floating and snap together cause the app bar to appear quickly on scroll up.
📝 Syntax
advanced
2:30remaining
Which option correctly creates a CustomScrollView with a SliverGrid?
Select the code snippet that correctly builds a CustomScrollView containing a SliverGrid with 4 items arranged in 2 columns.
ACustomScrollView(children: [SliverGrid(delegate: SliverChildBuilderDelegate((context, index) => Text('Item $index'), childCount: 4), gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2))])
BCustomScrollView(slivers: [SliverGrid(delegate: SliverChildBuilderDelegate((context, index) => Text('Item $index'), childCount: 4), gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2))])
CCustomScrollView(slivers: [SliverGrid(delegate: SliverChildListDelegate([Text('Item 0'), Text('Item 1'), Text('Item 2'), Text('Item 3')]), gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2))])
DCustomScrollView(slivers: [SliverGrid(delegate: SliverChildBuilderDelegate((context, index) => Text('Item $index')), gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 4))])
Attempts:
2 left
💡 Hint
CustomScrollView uses the slivers parameter, not children.
🔧 Debug
advanced
2:00remaining
Why does this CustomScrollView code cause a runtime error?
This code throws an error when run. What is the cause?
Flutter
CustomScrollView(
  slivers: [
    SliverList(
      delegate: SliverChildBuilderDelegate(
        (context, index) => ListTile(title: Text('Item $index')),
        childCount: 5,
      ),
    ),
    Container(height: 100, color: Colors.red),
  ],
)
AA Container widget cannot be a direct child of slivers; only sliver widgets are allowed.
BCustomScrollView requires a ScrollController to be set explicitly.
CSliverList must be the last sliver in the list.
DSliverChildBuilderDelegate requires a childCount of zero or null to work properly.
Attempts:
2 left
💡 Hint
Check what types of widgets are allowed inside the slivers list.
🧠 Conceptual
expert
2:30remaining
How many items are visible initially in this CustomScrollView with SliverFixedExtentList?
Given this code, how many list items will be visible on the screen initially if the screen height is 600 pixels?
Flutter
CustomScrollView(
  slivers: [
    SliverFixedExtentList(
      itemExtent: 120,
      delegate: SliverChildBuilderDelegate(
        (context, index) => ListTile(title: Text('Item $index')),
        childCount: 10,
      ),
    ),
  ],
)
A4 items
B10 items
C6 items
D5 items
Attempts:
2 left
💡 Hint
Divide screen height by itemExtent to find visible items count.