我正在尝试在视图内创建可滚动的文本:
// other widgets,
SingleChildScrollView(
child: Container(
height: 200,
child: Text(
"Long text here which is longer than the container height"))),
// other widgets
文本长于其父容器的高度,但是由于某种原因,尽管文本被包裹在SingleChildScrollView
中,但仍无法滚动。知道我在做什么错吗?
答案 0 :(得分:1)
尝试添加scrollDirection(水平)
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Container(
height: 200,
child: Text(
"Long text here which is longer than the container height"))),
}
默认为垂直
或者如果您想拥有自己的身高,则必须更改顺序(容器内的SingleChildScrollView)
Container(
height: 200,
child: SingleChildScrollView(
child: Text(
"Long text here which is longer than the container height"))),
答案 1 :(得分:0)
这是一个简单的解决方案 -
使用“扩展”小部件。
Container(
height: 200,
padding: const EdgeInsets.all(5.0),
margin: EdgeInsets.all(8),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: Colors.blueAccent,
width: 5.0,
),
),
child: Expanded(
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Text(PutYourText),
),
),
)