小编典典

在Flutter中使容器内可滚动文本

flutter

我试图在视图内创建一个可滚动的文本:

// other widgets,

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

// other widgets

该文本的长度大于其父容器的高度,但是由于某种原因,尽管将其包裹在内,但该文本不可滚动SingleChildScrollView。知道我在做什么错吗?


阅读 2342

收藏
2020-08-13

共1个答案

小编典典

尝试添加scrollDirection(水平):

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

默认为垂直。

或者,如果您想拥有自己的身高,则必须更改顺序(SingleChildScrollView在内部Container):

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