How to make a column widget scrollable in Flutter

The SingleChildScrollView widget in Flutter is the key to making a column widget scrollable. It enables users to scroll through the content vertically, ensuring it is accessible, even when it extends beyond the visible screen.

Error

The problem arises when the content within a column widget exceeds the vertical space available on the screen. Without scrollability, the content gets cut off, making it inaccessible to users. We can see the following error in the terminal.

Vertical viewport was given unbounded height.

This error will arise in the terminal when the available content is not able to render on the screen, as shown below.

Column widget without SingleChildScrollView widget showing error
Column widget without SingleChildScrollView widget showing error

Syntax

SingleChildScrollView is a single-child widget so we can add the column widget as a child.

Scaffold(         
     body: SingleChildScrollView(
                child: Column(
                          children: [
                  
                          ],
                       ),
           ),
);

Example

In the example below, we have a main.dart file in the lib folder where we have defined a column widget with six containers, each with a height of 200 and a different color. By wrapping the column with SingleChildScrollView, the column widget becomes scrollable, allowing users to view the entire content vertically. This technique ensures that even if the containers exceed the available screen space, users can easily scroll through the content to access all the containers.

bmFtZTogbmV3YXBwCmRlc2NyaXB0aW9uOiBBIG5ldyBGbHV0dGVyIHByb2plY3QuCiMgVGhlIGZvbGxvd2luZyBsaW5lIHByZXZlbnRzIHRoZSBwYWNrYWdlIGZyb20gYmVpbmcgYWNjaWRlbnRhbGx5IHB1Ymxpc2hlZCB0bwojIHB1Yi5kZXYgdXNpbmcgYGZsdXR0ZXIgcHViIHB1Ymxpc2hgLiBUaGlzIGlzIHByZWZlcnJlZCBmb3IgcHJpdmF0ZSBwYWNrYWdlcy4KcHVibGlzaF90bzogJ25vbmUnICMgUmVtb3ZlIHRoaXMgbGluZSBpZiB5b3Ugd2lzaCB0byBwdWJsaXNoIHRvIHB1Yi5kZXYKCiMgVGhlIGZvbGxvd2luZyBkZWZpbmVzIHRoZSB2ZXJzaW9uIGFuZCBidWlsZCBudW1iZXIgZm9yIHlvdXIgYXBwbGljYXRpb24uCiMgQSB2ZXJzaW9uIG51bWJlciBpcyB0aHJlZSBudW1iZXJzIHNlcGFyYXRlZCBieSBkb3RzLCBsaWtlIDEuMi40MwojIGZvbGxvd2VkI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AgICAtIGFzc2V0OiBmb250cy9UcmFqYW5Qcm8udHRmCiAgIyAgICAgICAtIGFzc2V0OiBmb250cy9UcmFqYW5Qcm9fQm9sZC50dGYKICAjICAgICAgICAgd2VpZ2h0OiA3MDAKICAjCiAgIyBGb3IgZGV0YWlscyByZWdhcmRpbmcgZm9udHMgZnJvbSBwYWNrYWdlIGRlcGVuZGVuY2llcywKICAjIHNlZSBodHRwczovL2ZsdXR0ZXIuZGV2L2N1c3RvbS1mb250cy8jZnJvbS1wYWNrYWdlcwo=

Conclusion

Using the SingleChildScrollView widget, you can make a column widget scrollable in Flutter. This approach is essential when dealing with content that uses more vertical space than is available. It ensures that all content remains accessible by enabling users to scroll through it.

Whenever you encounter situations where your column widget's content overflows, consider utilizing the SingleChildScrollView widget to provide a seamless scrolling experience for your users.

Free Resources

Copyright ©2024 Educative, Inc. All rights reserved