在Flutter中的容器内创建可滚动文本

问题描述 投票:0回答:1

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

// other widgets,

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

// other widgets

文本长度超过其父容器的高度,但由于某种原因,文本虽然包含在SingleChildScrollView中,但不可滚动。知道我做错了什么吗?

dart flutter flutter-layout
1个回答
1
投票

尝试添加scrollDirection(水平)

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

}

默认为垂直

或者如果你想拥有你的身高那么你必须改变顺序(Container内的SingleChildScrollView)

Container(
    height: 200,
    child: SingleChildScrollView(
        child: Text(
            "Long text here which is longer than the container height"))),
© www.soinside.com 2019 - 2024. All rights reserved.