Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make scrollable Text inside container in Flutter

I'm trying to create a scrollable Text inside a view:

// other widgets,

SingleChildScrollView(
  child: Container(
    height: 200,
    child: Text(
      "Long text here which is longer than the container height"))),

// other widgets

The text is longer than the height of its parent container, but for some reason the text is not scrollable although it is wrapped inside SingleChildScrollView. Any idea what I'm doing wrong?

like image 408
supersize Avatar asked Apr 04 '19 12:04

supersize


People also ask

How do you make the contents of a container scrollable in flutter?

Just change Column widget to ListView widget — and that's all. Your container becomes scrollable.

How do you make a scrollable text in flutter?

We can make the text scrollable in flutter using these 2 widgets: Expanded Class: A widget that expands a child of a Row, Column, or Flex so that the child fills the available space. SingleChildScrollView Class: A box in which a single widget can be scrolled.

How do I add scrollbar to TextField in flutter?

See the example below. TextEditingController _editTextController = TextEditingController(); // Initialise a scroll controller. ScrollController _scrollController = ScrollController(); Then, add it to the TextField widget and wrap this widget in a Scrollbar !


1 Answers

Try to add scrollDirection (horizontal):

SingleChildScrollView(
scrollDirection: Axis.horizontal,
  child: Container(
      height: 200,
      child: Text(
          "Long text here which is longer than the container height")))

Default is vertical.

Or if you want to have with your height then you have to change the order (SingleChildScrollView inside Container):

Container(
    height: 200,
    child: SingleChildScrollView(
        child: Text(
            "Long text here which is longer than the container height")))
like image 183
Stonek Avatar answered Sep 24 '22 01:09

Stonek