繁体   English   中英

底部溢出 99888 像素的 RenderFlex

[英]A RenderFlex overflowed by 99888 pixels on the bottom

我在“HomeScreen”上遇到了一些问题,但在不确定发生了什么之前它可以正常工作,现在它不能正常工作。 还有一个疑问,因为我已经添加了一个容器,并且列也在容器内部,为什么列会溢出?

我想在左侧和右侧有一个用于显示图像的“容器”,用于显示从数据库中获取的“UserInformation”,但是它显示列问题,即使已添加“灵活”或“扩展”也不起作用。

主屏幕

“主屏幕显示”

  @override
  Widget build(BuildContext context) {
    final profile = Provider.of<UserProfileLogic>(context, listen: false);
    return Container(
      color: Colors.blue,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Container(
            padding: EdgeInsets.all(40),
            child: CircleAvatar(
              backgroundImage: AssetImage(
                "assets/images/Materials-25.png",
              ),
              radius: 70,
              child: FittedBox(
                fit: BoxFit.fitHeight,
              ),
            ),
          ),
          Flexible(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                ListView.builder(
                  shrinkWrap: true,
                  itemCount: profile.items.length,
                  itemBuilder: (_, i) => Column(
                    children: <Widget>[
                      Text(profile.items[i].username),
                      Text(profile.items[i].age.toString()),
                      Text(profile.items[i].gender),
                      Text(profile.items[i].bio),
                      SizedBox(
                        height: 50,
                      ),
                      UserProfileItem(profile.items[i].userprofileid),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}

“UserProfileItem.dart”创建这个的原因是因为我必须传递“ID”的参数以确保一旦用户单击按钮,它将获得 ID,因此一旦进入“ProfileScreen”就可以看到他自己的个人资料。

    class UserProfileItem extends StatelessWidget {
  final String id;

  UserProfileItem(this.id);

  @override
  Widget build(BuildContext context) {
    return RaisedButton(
      child: Text("Profile"),
      elevation: 6,
      onPressed: () => Navigator.of(context).pushNamed(
        ProfileScreen.routeName,
        arguments: id,
      ),
    );
  }
}

“使用后的解决方案”我可以知道为什么它会显示出来吗? 谢谢您的帮助

在此处输入图像描述

溢出不是问题。 溢出是由 flutter 中的错误小部件引起的。

 @override
  Widget build(BuildContext context) {
    final profile = Provider.of<UserProfileLogic>(context, listen: false);
    return Container(
      color: Colors.blue,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Container(
            padding: EdgeInsets.all(40),
            child: CircleAvatar(
              backgroundImage: AssetImage(
                "assets/images/Materials-25.png",
              ),
              radius: 70,
              child: FittedBox(
                fit: BoxFit.fitHeight,
              ),
            ),
          ),
          Expanded(
            child: ListView.builder(
                  itemCount: profile.items.length,
                  itemBuilder: (_, i) => Column(
                    children: <Widget>[
                  Text(profile?.items[i]?.username ?? "No user name"),
                  Text(profile?.items[i]?.age?.toString()  ?? "No age"),
                  Text(profile?.items[i]?.gender ?? "No gender"),
                  Text(profile?.items[i]?.bio ?? "No bio"),
                      SizedBox(
                        height: 50,
                      ),
                      UserProfileItem(profile.items[i].userprofileid),
                    ],
                  ),
                ),
          ),
        ],
      ),
    );
  }
}

问题是您的项目字段中有 null 值。 要解决此问题,请如上所述更改您的文本小部件。

问题是您将ListView.builder作为Column()的子级,并且 Columns 不会滚动,将该列更改为ListView并且您的问题将得到解决。

还要检查您是否尝试访问 null 值并为文本小部件提供默认值,文本小部件的数据不能是 null。

      Flexible(
        child: ListView(
          children: <Widget>[
            ListView.builder(
              shrinkWrap: true,
              itemCount: profile.items.length,
              itemBuilder: (_, i) => Column(
                children: <Widget>[
                  Text(profile?.items[i]?.username ?? "No username"),
                  Text(profile?.items[i]?.age?.toString()  ?? "No age"),
                  Text(profile?.items[i]?.gender ?? "No gender"),
                  Text(profile?.items[i]?.bio ?? "No bio"),
                  SizedBox(
                    height: 50,
                  ),
                  UserProfileItem(profile.items[i].userprofileid),
                ],
              ),
            ),
          ],
        ),
      ),

关于您获得的重复列表,请检查 profile.items.length 的值,因为您将其用作 itemCount。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM