在Flutter中使容器内可滚动文本
问题内容:
我试图在视图内创建一个可滚动的文本:
// other widgets,
SingleChildScrollView(
child: Container(
height: 200,
child: Text(
"Long text here which is longer than the container height"))),
// other widgets
该文本的长度大于其父容器的高度,但是由于某种原因,尽管将其包裹在内,但该文本不可滚动SingleChildScrollView
。知道我在做什么错吗?
问题答案:
尝试添加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")))