行未显示在列表瓷砖中

huangapple go评论127阅读模式
英文:

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) =&gt;
const Divider(),
itemBuilder: (BuildContext context, int index) {
return ListTile(
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) =&gt; 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() +
&quot; posts &quot; +
&quot; &quot;,
style:
TextStyle(
color: Colors
.grey,
fontSize: 3,
),
),
CircleAvatar(
child: Image
.network(
userdata.getProfileIcon(
forumdata
.getuser(index)),
),
),
Text(
&quot; &quot; +
forumdata
.getDateTime(
index),
style:
TextStyle(
color: Colors
.grey,
),
),
],
),
),
),
],
),
),
),
],
),
),
),
);

答案1

得分: 0

从代码部分来看:

SizedBox 的高度是 19,第二个 Row 上面的 padding20。因此,底部的填充完全隐藏了这个 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(

huangapple
  • 本文由 发表于 2023年1月9日 10:53:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/75052782.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定