英文:
Row not showing in listtile
问题
我正在尝试为论坛页面创建一个ListView,但在尾部下方和论坛数据获取不到的行下方无法显示列表磁贴的内容,我该如何解决这个问题?类没有错误,删除高度为19的SizedBox将导致溢出错误。
当前应用的图像:
代码:
Container(
margin: const EdgeInsets.symmetric(vertical: 20.0),
height: 900.0,
child: ListView.separated(
physics: NeverScrollableScrollPhysics(),
itemCount: forumdata.getfLength(),
separatorBuilder: (BuildContext context, int index) =>
const Divider(),
itemBuilder: (BuildContext context, int index) {
return ListTile(
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => ThreadPageScreen(
index: index,
),
),
);
},
visualDensity: VisualDensity(vertical: 4),
leading: CircleAvatar(
backgroundColor:
Color(forumdata.getfcolor(index)),
child: Icon(
forumdata.getIcon(index),
color: Color(forumdata.geticolor(index)),
),
),
trailing: SizedBox(
width: 300,
height: 300,
child: Padding(
padding:
EdgeInsets.only(left: 20),
child: Column(
children: [
Container(
child: Align(
alignment: Alignment.centerLeft,
child: Text(
forumdata.getTitle(index),
maxLines: 1,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 15,
color: Colors.blue),
),
),
),
Container(
child: Align(
alignment: Alignment.centerLeft,
child: Text(
forumdata.getDesc(index),
maxLines: 2,
),
),
),
Padding(
padding: EdgeInsets.only(left: 20),
child: SizedBox(
width: 300,
height: 19,
child: Row(
children: [
Container(
child: Padding(
padding:
EdgeInsets.only(
bottom: 20),
child: Row(
children: [
Text(
forumdata
.getnop(
index)
.toString() +
" posts " +
" ",
style:
TextStyle(
color: Colors
.grey,
fontSize: 3,
),
),
CircleAvatar(
child: Image
.network(
userdata.getProfileIcon(
forumdata
.getuser(index)),
),
),
Text(
" " +
forumdata
.getDateTime(
index),
style:
TextStyle(
color: Colors
.grey,
),
),
],
),
),
),
],
),
),
),
],
),
),
),
);
},
),
);
英文:
I am trying to make a listview for a forum page but for the row under trailing and under the row where forumdata.getnop and the other data cannot be displayed under the list tile how do I fix this? there is no error with the class as removing the sized box with height 19 will just make it have an overflow error.
image of current app : -
<img src="https://i.stack.imgur.com/BBiR5.png">
Code : -
Container(
margin: const EdgeInsets.symmetric(vertical: 20.0),
height: 900.0,
child: ListView.separated(
physics: NeverScrollableScrollPhysics(),
itemCount: forumdata.getfLength(),
separatorBuilder: (BuildContext context, int index) =>
const Divider(),
itemBuilder: (BuildContext context, int index) {
return ListTile(
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => ThreadPageScreen(
index: index,
)),
);
},
visualDensity: VisualDensity(vertical: 4),
leading: CircleAvatar(
backgroundColor:
Color(forumdata.getfcolor(index)),
child: Icon(
forumdata.getIcon(index),
color: Color(forumdata.geticolor(index)),
),
),
trailing: SizedBox(
width: 300,
height: 300,
child: Padding(
padding:
EdgeInsets.only(left: 20),
child: Column(
children: [
Container(
child: Align(
alignment: Alignment.centerLeft,
child: Text(
forumdata.getTitle(index),
maxLines: 1,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 15,
color: Colors.blue),
),
),
),
Container(
child: Align(
alignment: Alignment.centerLeft,
child: Text(
forumdata.getDesc(index),
maxLines: 2,
),
),
),
Padding(
padding: EdgeInsets.only(left: 20),
child: SizedBox(
width: 300,
height: 19,
child: Row(
children: [
Container(
child: Padding(
padding:
EdgeInsets.only(
bottom: 20),
child: Row(
children: [
Text(
forumdata
.getnop(
index)
.toString() +
" posts " +
" ",
style:
TextStyle(
color: Colors
.grey,
fontSize: 3,
),
),
CircleAvatar(
child: Image
.network(
userdata.getProfileIcon(
forumdata
.getuser(index)),
),
),
Text(
" " +
forumdata
.getDateTime(
index),
style:
TextStyle(
color: Colors
.grey,
),
),
],
),
),
),
],
),
),
),
],
),
),
),
);
答案1
得分: 0
从代码部分来看:
SizedBox
的高度是 19
,第二个 Row
上面的 padding
是 20
。因此,底部的填充完全隐藏了这个 row
。
英文:
On a quick view, From this section of code:
SizedBox(
width: 300,
height: 19,
child: Row(children: [
Container(
child:
Padding(padding: EdgeInsets.only(bottom: 20),
child: Row(
Height of the SizedBox
is 19
and the padding
above second Row
is 20
. Thus the bottom padding completely hide the row
.
答案2
得分: 0
trailing: SizedBox(
width: 300,
height: 300,
child: Padding(
/// 替换为以下内容
title: SizedBox(
width: MediaQuery.of(context).size.width,
child: Padding(
英文:
trailing: SizedBox(
width: 300,
height: 300,
child: Padding(
/// replace with this
title: SizedBox(
width: MediaQuery.of(context).size.width,
child: Padding(
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论