简体   繁体   English

底部溢出 99888 像素的 RenderFlex

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

I have met some issue on my "HomeScreen" but it's work before not sure what's going on it's not working right now.我在“HomeScreen”上遇到了一些问题,但在不确定发生了什么之前它可以正常工作,现在它不能正常工作。 Also have a doubt there because I've been add a container and the column also inside of the container why the column will overflow?还有一个疑问,因为我已经添加了一个容器,并且列也在容器内部,为什么列会溢出?

I would like to have a "Container" for display image on left side and right side for display "UserInformation" that fetch from database however it's showing column issue even though have been added "Flexible" or "Expanded" also not working.我想在左侧和右侧有一个用于显示图像的“容器”,用于显示从数据库中获取的“UserInformation”,但是它显示列问题,即使已添加“灵活”或“扩展”也不起作用。

主屏幕

"HomeScreen Display" “主屏幕显示”

  @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" The reason why creating this because I have to pass argument of "ID" to make sure once user click for the button and it will get the ID so once going for "ProfileScreen" could see his own profile. “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,
      ),
    );
  }
}

"After Used Solution " May I know why it will display out? “使用后的解决方案”我可以知道为什么它会显示出来吗? Thank you for your help谢谢您的帮助

在此处输入图像描述

Overflow is not the problem.溢出不是问题。 overflow is caused by the error widget in flutter.溢出是由 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),
                    ],
                  ),
                ),
          ),
        ],
      ),
    );
  }
}

The problem is that you have null value in your items fields.问题是您的项目字段中有 null 值。 To solve this change your text widgets as above.要解决此问题,请如上所述更改您的文本小部件。

The problem is that you have your ListView.builder as the child of a Column() and Columns does not scroll, change that column for a ListView and your issue sould be solved.问题是您将ListView.builder作为Column()的子级,并且 Columns 不会滚动,将该列更改为ListView并且您的问题将得到解决。

Also check if you are trying to access a null value and provide a default value for the text widget, a text widget's data can not be null.还要检查您是否尝试访问 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),
                ],
              ),
            ),
          ],
        ),
      ),

Regarding the duplicate list you get, check hat the value of profile.items.length is, because you are using that as the itemCount.关于您获得的重复列表,请检查 profile.items.length 的值,因为您将其用作 itemCount。

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

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