我正在尝试在滚动视图中嵌入带有可变文本量的平面按钮,以便用户可以滚动文本,也可以点击文本以执行操作。我尝试通过在ConstrainedBox中嵌入一个扁平按钮来做到这一点,而ConstrainedBox本身嵌入在SingleChildScrollView中。
我尝试将FlatButton嵌入到SingleChildScrollView中,如下所示。早些时候,我尝试使用SingleChildScrollView祖先将文本包装在扩展的小部件中,但这会导致运行时错误,因为滚动视图和扩展视图的要求发生冲突(据我所知)。
Widget contentScreen() {
return SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(),
child: FlatButton(
onPressed: () {
_toggleContent();
},
child:
Column(children: <Widget>[
Container(
child: Text(
"Lorem Ipsum....",
style: TextStyle(color: Colors.white, fontSize: 20))),
]
)
)
)
);
}
文本不会滚动。相反,它溢出并显示对角的黄色条。我没有我尝试过的列表,但是现在我正在使用上面的代码,但是没有预期的滚动行为。 :\
我尝试过:How to make the Scrollable text in flutter?
此:Make scrollable Text inside container in Flutter
这是how to make text or richtext scrollable in flutter?
FlatButton的行为是否有某些东西可以阻止滚动?如果是这样,如何解决该问题,仍然可以获得我想要的两种行为(滚动和点击以执行动作的能力)?
答案 0 :(得分:0)
您尝试过吗?为什么需要扩展小部件?
Container(
height: 20.0,
child: FlatButton(
onPressed: () {},
child: SingleChildScrollView(
child: Text('Lorem ipsum'),
),
),
),
手势探测器也应该可以正常工作。
答案 1 :(得分:-1)
Container(
height: 20.0,
child: FlatButton(
onPressed: () {},
child: SingleChildScrollView(
child: Text('Lorem ipsum'),
),
),
),