首页 > 解决方案 > 在 Flutter 中的容器内制作可滚动文本

问题描述

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

// other widgets,

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

// other widgets

文本比其父容器的高度长,但由于某种原因,文本虽然被包裹在SingleChildScrollView. 知道我做错了什么吗?

标签: dartflutterflutter-layout

解决方案


尝试添加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")))

推荐阅读