Make scrollable Text inside container in Flutter

2020-07-23 08:25发布

问题:

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?

回答1:

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")))