Flutter 颤振:右侧的RenderFlex溢出了34个像素

Flutter 颤振:右侧的RenderFlex溢出了34个像素,flutter,Flutter,尝试在脚本下面运行时出错。我正在使用扩展小部件显示用户关注者 Expanded( flex: 1, child: Column( children: <Widget>[ Row( mainAxisSize: MainAxisSize.max,

尝试在脚本下面运行时出错。我正在使用扩展小部件显示用户关注者

Expanded(
                      flex: 1,
                      child: Column(
                        children: <Widget>[
                          Row(
                            mainAxisSize: MainAxisSize.max,
                            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                            children: <Widget>[
                              buildCountColumn("posts", postCount),
                              buildCountColumn("followers", followerCount),
                              buildCountColumn("following", followingCount),
                            ],
                          ),
                          Row(
                            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                            children: <Widget>[
                              buildProfileButton(),
                            ],
                          ),
                        ],
                      ),
                    ),
扩展(
弹性:1,
子:列(
儿童:[
划船(
mainAxisSize:mainAxisSize.max,
mainAxisAlignment:mainAxisAlignment.space,
儿童:[
buildCountColumn(“posts”,postCount),
buildCountColumn(“followers”,followerCount),
buildCountColumn(“以下”,以下计数),
],
),
划船(
mainAxisAlignment:mainAxisAlignment.space,
儿童:[
buildProfileButton(),
],
),
],
),
),

删除扩展的parentWidget,并为每个小部件获得一个扩展的
小部件

Column(
    children: <Widget>[
      Row(
        mainAxisSize: MainAxisSize.max,
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: <Widget>[
          Expanded(
            child: Container(
              color: Colors.blue,
              child: Text("Hello"),
            ),
          ),
          Expanded(
            child: Container(
              color: Colors.red,
              child: Text("Hello"),
            ),
          ),
          Expanded(
            child: Container(
              color: Colors.yellow,
              child: Text("Hello"),
            ),
          ),
        ],
      ),
      Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          Expanded(
            child: Container(
              color: Colors.green,
              child: Text("Hello"),
            ),
          ),
        ],
      ),
    ],
  ),
列(
儿童:[
划船(
mainAxisSize:mainAxisSize.max,
mainAxisAlignment:mainAxisAlignment.space,
儿童:[
扩大(
子:容器(
颜色:颜色,蓝色,
孩子:文本(“你好”),
),
),
扩大(
子:容器(
颜色:颜色,红色,
孩子:文本(“你好”),
),
),
扩大(
子:容器(
颜色:颜色,黄色,
孩子:文本(“你好”),
),
),
],
),
划船(
mainAxisAlignment:mainAxisAlignment.space,
crossAxisAlignment:crossAxisAlignment.center,
儿童:[
扩大(
子:容器(
颜色:颜色。绿色,
孩子:文本(“你好”),
),
),
],
),
],
),
您的**buildProfileButton()或行**正在创建比屏幕中可用空间更大的小部件; 两种解决方案:

  • 您可以将行放在listview中以使其可滚动
  • 将每一个都放在展开式中,如: 扩大( 子项:buildCountColumn(“posts”,postCount), ) 在屏幕上使用有限的可用大小->在所有孩子中平均分配 ::始终使用小于总屏幕宽度的扩展/列表视图/可滚动/小部件大小 对于灵活的行,您可以通过mediaQuery.of(context.size.width获得它