【发布时间】:2020-04-11 15:38:25
【问题描述】:
如何添加滚动以使多个文本答案可滚动?我尝试使用 SingleChildScrollView,但无法滚动,文本答案消失,页面不滚动。
class Answer extends StatelessWidget {
final Function selectHandler;
final String answerText;
Answer(this.selectHandler, this.answerText);
@override
Widget build(BuildContext context) {
return Container(
width: double.infinity,
margin: EdgeInsets.fromLTRB(10.0, 10.0, 10.0, 0),
child: RaisedButton(
padding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 16.0),
color: Color(0xfff4f4f4),
textColor: Color(0xff3a3535),
child: Text(answerText, style: TextStyle(
fontFamily: 'VT323', fontSize: 22)),
onPressed: selectHandler,
),
decoration: BoxDecoration(
// color: Color.fromARGB(255, 238, 238, 238),
boxShadow: [
BoxShadow(offset: Offset(10, 10),color: Color.fromARGB(80, 0, 0, 0),blurRadius: 10),
BoxShadow(offset: Offset(-10, -10),color: Color.fromARGB(150, 255, 255, 255),blurRadius: 10)
],
),
);
}
}
ListView.builder 在这里我得到以下错误:
"类型'String'不是类型'List'的子类型
class Answer extends StatelessWidget {
final Function selectHandler;
final List<String> answerText;
Answer(this.selectHandler, this.answerText);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
height: 60.0,
width: double.infinity,
margin: EdgeInsets.fromLTRB(10.0, 10.0, 10.0, 0),
decoration: BoxDecoration(
// color: Color.fromARGB(255, 238, 238, 238),
boxShadow: [
BoxShadow(
offset: Offset(10, 10),
color: Color.fromARGB(80, 0, 0, 0),
blurRadius: 10),
BoxShadow(
offset: Offset(-10, -10),
color: Color.fromARGB(150, 255, 255, 255),
blurRadius: 10,
),
],
),
child: ListView.builder(
itemBuilder: _buildAnswerItem,
itemCount: answerText.length,
),
),
);
}
Widget _buildAnswerItem( BuildContext context, int index) {
return RaisedButton(
padding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 16.0),
color: Color(0xfff4f4f4),
textColor: Color(0xff3a3535),
child: Text(answerText[index],
style: TextStyle(fontFamily: 'VT323', fontSize: 22)),
onPressed: selectHandler,
);
}
}
【问题讨论】:
-
你可以尝试使用ListView
-
@AnuroopSingh 你能告诉我我会怎么做吗?我也尝试过 ListView,但由于我是 Flutter 的新手,所以我无法让它正常工作。
标签: flutter