What is the purpose of the SingleChildScrollView widget in Flutter?
#widget#scrolling#layout
Answer
Overview
makes a single widget scrollable. It's used when you have a widget (typically a textSingleChildScrollView
text
Columntext
ListViewBasic Usage
dartSingleChildScrollView( child: Column( children: [ Text('Section 1'), SizedBox(height: 300, child: Container(color: Colors.blue)), Text('Section 2'), SizedBox(height: 300, child: Container(color: Colors.red)), Text('Section 3'), ], ), )
Scroll Directions
dart// Vertical scroll (default) SingleChildScrollView( scrollDirection: Axis.vertical, child: Column(children: [...]), ) // Horizontal scroll SingleChildScrollView( scrollDirection: Axis.horizontal, child: Row(children: [...]), )
Common Pattern: Form Screen
dartScaffold( body: SafeArea( child: SingleChildScrollView( padding: EdgeInsets.all(16), child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ TextFormField(decoration: InputDecoration(labelText: 'Name')), SizedBox(height: 16), TextFormField(decoration: InputDecoration(labelText: 'Email')), SizedBox(height: 16), TextFormField(decoration: InputDecoration(labelText: 'Password')), SizedBox(height: 24), ElevatedButton(onPressed: () {}, child: Text('Submit')), ], ), ), ), )
With ScrollController
dartfinal ScrollController _scrollController = ScrollController(); SingleChildScrollView( controller: _scrollController, child: Column(children: [...]), ) // Scroll to top _scrollController.animateTo(0, duration: Duration(milliseconds: 300), curve: Curves.easeOut, );
SingleChildScrollView vs ListView
| Feature | SingleChildScrollView | ListView |
|---|---|---|
| Number of children | One child (often a Column) | Many children |
| Lazy rendering | ❌ No — renders all at once | ✅ Yes — renders only visible |
| Performance | ❌ Poor for long lists | ✅ Good for long lists |
| Use case | Form screens, small content | Dynamic/long lists |
| Content type | Arbitrary layout | Repeated list items |
Best Practice: Use
for forms and short screens where all content is known. UsetextSingleChildScrollViewfor dynamic or long lists.textListView.builder