Bird
Raised Fist0
Fluttermobile~15 mins

SingleChildScrollView in Flutter - Mini App: Build & Ship

Choose your learning style10 modes available
Build: Scrollable List Screen
This screen shows a vertical list of colored boxes that can be scrolled if they don't fit on the screen.
Target UI
Scrollable List Screen

+-----------------------+
| Title: Scrollable List|
|-----------------------|
| [Red Box]             |
| [Green Box]           |
| [Blue Box]            |
| [Yellow Box]          |
| [Purple Box]          |
| [Orange Box]          |
|                       |
|                       |
|                       |
+-----------------------+
Use SingleChildScrollView to make the list scrollable vertically.
Display six colored boxes stacked vertically.
Each box should have a fixed height and fill the screen width with some margin.
Add a title text at the top inside an AppBar.
Starter Code
Flutter
import 'package:flutter/material.dart';

class ScrollableListScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Scrollable List'),
      ),
      body: // TODO: Add SingleChildScrollView with colored boxes here
    );
  }
}
Task 1
Task 2
Task 3
Solution
Flutter
import 'package:flutter/material.dart';

class ScrollableListScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Scrollable List'),
      ),
      body: SingleChildScrollView(
        child: Column(
          children: [
            Container(
              height: 150,
              margin: EdgeInsets.all(10),
              color: Colors.red,
            ),
            Container(
              height: 150,
              margin: EdgeInsets.all(10),
              color: Colors.green,
            ),
            Container(
              height: 150,
              margin: EdgeInsets.all(10),
              color: Colors.blue,
            ),
            Container(
              height: 150,
              margin: EdgeInsets.all(10),
              color: Colors.yellow,
            ),
            Container(
              height: 150,
              margin: EdgeInsets.all(10),
              color: Colors.purple,
            ),
            Container(
              height: 150,
              margin: EdgeInsets.all(10),
              color: Colors.orange,
            ),
          ],
        ),
      ),
    );
  }
}

We use SingleChildScrollView to make the whole column scrollable vertically. Inside it, a Column holds six Container widgets, each with a fixed height of 150 pixels and a margin of 10 pixels around for spacing. Each container has a different background color to visually separate them. The AppBar shows the screen title at the top. This setup allows the user to scroll through the colored boxes if they don't fit on the screen.

Final Result
Completed Screen
Scrollable List Screen

+-----------------------+
| Title: Scrollable List|
|-----------------------|
| [Red Box]             |
| [Green Box]           |
| [Blue Box]            |
| [Yellow Box]          |
| [Purple Box]          |
| [Orange Box]          |
|                       |
|                       |
|                       |
+-----------------------+
User can scroll vertically to see all six colored boxes.
The AppBar stays fixed at the top while scrolling.
Stretch Goal
Add horizontal scrolling with SingleChildScrollView to show colored boxes side by side.
💡 Hint
Set scrollDirection to Axis.horizontal and use a Row instead of Column inside SingleChildScrollView.

Practice

(1/5)
1. What is the main purpose of SingleChildScrollView in Flutter?
easy
A. To make a single widget scrollable when it doesn't fit on the screen
B. To create a grid layout with multiple widgets
C. To handle user input in forms
D. To navigate between different screens

Solution

  1. Step 1: Understand the widget's purpose

    SingleChildScrollView is designed to make one widget scrollable if it is too big for the screen.
  2. Step 2: Compare with other options

    Options B, C, and D describe other Flutter widgets or features unrelated to scrolling a single child.
  3. Final Answer:

    To make a single widget scrollable when it doesn't fit on the screen -> Option A
  4. Quick Check:

    SingleChildScrollView = scrollable single widget [OK]
Hint: SingleChildScrollView scrolls one widget only [OK]
Common Mistakes:
  • Confusing with ListView for multiple items
  • Thinking it handles navigation
  • Assuming it manages user input
2. Which of the following is the correct way to explicitly make a vertical scroll using SingleChildScrollView?
easy
A. SingleChildScrollView(child: Text('Hello')) without scrollDirection
B. SingleChildScrollView(scrollDirection: Axis.horizontal, child: Text('Hello'))
C. SingleChildScrollView(direction: Axis.vertical, child: Text('Hello'))
D. SingleChildScrollView(scrollDirection: Axis.vertical, child: Text('Hello'))

Solution

  1. Step 1: Check the property name and value

    The correct property to set scroll direction is scrollDirection with value Axis.vertical for vertical scrolling.
  2. Step 2: Analyze each option

    SingleChildScrollView(scrollDirection: Axis.horizontal, child: Text('Hello')) uses horizontal direction, wrong for vertical. SingleChildScrollView(direction: Axis.vertical, child: Text('Hello')) uses wrong property name direction. SingleChildScrollView(child: Text('Hello')) without scrollDirection does not explicitly specify vertical scrolling (defaults to vertical).
  3. Final Answer:

    SingleChildScrollView(scrollDirection: Axis.vertical, child: Text('Hello')) -> Option D
  4. Quick Check:

    scrollDirection = Axis.vertical for vertical scroll [OK]
Hint: Use scrollDirection: Axis.vertical for vertical scroll [OK]
Common Mistakes:
  • Using wrong property name like 'direction'
  • Confusing horizontal and vertical axis
  • Omitting scrollDirection when explicit vertical scroll is required
3. What will happen when this Flutter code runs?
SingleChildScrollView(
  scrollDirection: Axis.horizontal,
  child: Row(
    children: [
      Container(width: 200, height: 100, color: Colors.red),
      Container(width: 200, height: 100, color: Colors.blue),
      Container(width: 200, height: 100, color: Colors.green),
    ],
  ),
)
medium
A. The app will crash due to wrong widget nesting
B. The row will scroll vertically showing all colored containers
C. The row will scroll horizontally showing all colored containers
D. The containers will be clipped and no scrolling happens

Solution

  1. Step 1: Understand scrollDirection and child

    The SingleChildScrollView scrolls horizontally because scrollDirection: Axis.horizontal. The child is a Row with wide containers.
  2. Step 2: Predict UI behavior

    The row's children exceed screen width, so horizontal scroll allows viewing all containers side by side.
  3. Final Answer:

    The row will scroll horizontally showing all colored containers -> Option C
  4. Quick Check:

    Horizontal scroll + Row = scrollable containers [OK]
Hint: Horizontal scroll with Row shows all children side by side [OK]
Common Mistakes:
  • Assuming vertical scroll with horizontal axis
  • Thinking containers get clipped without scroll
  • Believing app crashes due to this nesting
4. Identify the error in this code snippet:
SingleChildScrollView(
  scrollDirection: Axis.vertical,
  child: Column(
    children: [
      Text('Line 1'),
      Text('Line 2'),
      Text('Line 3'),
    ],
  ),
  scrollDirection: Axis.horizontal,
)
medium
A. Duplicate scrollDirection property causes a syntax error
B. Column cannot be child of SingleChildScrollView
C. Missing a SizedBox to wrap Text widgets
D. No error, code runs fine

Solution

  1. Step 1: Check property usage

    The code sets scrollDirection twice in the same widget, which is invalid syntax in Dart.
  2. Step 2: Verify other parts

    Using Column as child is valid. No SizedBox needed for Text widgets. So only duplicate property is error.
  3. Final Answer:

    Duplicate scrollDirection property causes a syntax error -> Option A
  4. Quick Check:

    Duplicate properties cause syntax error [OK]
Hint: Check for duplicate properties in widget constructors [OK]
Common Mistakes:
  • Thinking Column can't be child
  • Assuming missing SizedBox is error
  • Ignoring duplicate property syntax error
5. You want to create a scrollable form with multiple input fields stacked vertically. Which approach correctly uses SingleChildScrollView to avoid overflow errors?
hard
A. Column( children: [TextField(), TextField(), TextField()] ) without scroll view
B. SingleChildScrollView( child: Column( children: [TextField(), TextField(), TextField()] ), )
C. SingleChildScrollView( scrollDirection: Axis.horizontal, child: Column( children: [TextField(), TextField(), TextField()] ), )
D. ListView( children: [TextField(), TextField(), TextField()] ) instead of SingleChildScrollView

Solution

  1. Step 1: Understand scroll direction for vertical form

    A vertical form needs vertical scrolling, so SingleChildScrollView with default vertical scroll is correct.
  2. Step 2: Evaluate options

    SingleChildScrollView( child: Column( children: [TextField(), TextField(), TextField()] ), ) uses vertical scroll with Column child, perfect for stacked inputs. SingleChildScrollView( scrollDirection: Axis.horizontal, child: Column( children: [TextField(), TextField(), TextField()] ), ) wrongly sets horizontal scroll. Column( children: [TextField(), TextField(), TextField()] ) without scroll view lacks scroll, causing overflow. ListView( children: [TextField(), TextField(), TextField()] ) instead of SingleChildScrollView uses ListView which works but is different widget.
  3. Final Answer:

    SingleChildScrollView( child: Column( children: [TextField(), TextField(), TextField()] ), ) -> Option B
  4. Quick Check:

    Vertical scroll + Column = scrollable form [OK]
Hint: Use vertical SingleChildScrollView with Column for forms [OK]
Common Mistakes:
  • Setting horizontal scroll for vertical form
  • Omitting scroll view causing overflow
  • Confusing ListView with SingleChildScrollView
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard