行RenderFlex在右侧溢出了76个像素

时间:2019-01-14 09:35:26

标签: dart flutter

下面是我的代码,我总是在适当大小的情况下溢出一些像素。我也在玩Expanded和Fixable小部件以及行和列的mainAxisSize。

查看代码:

Widget productDisplayListView(List<Products> listOfProduct, int index) {
    return Container(
      margin: EdgeInsets.all(7),
      child: Container(
        child: Card(
          elevation: 4,
          child: Container(
            padding: EdgeInsets.all(6),
            child: Row(
              mainAxisSize: MainAxisSize.min,
              mainAxisAlignment: MainAxisAlignment.start,
              children: <Widget>[
                Container(
                  height: 110,
                  width: 90,
                  child: Image.network(
                    listOfProduct[index].thumbnail ?? '',
                    fit: BoxFit.cover,
                  ),
                ),
                Container(
                  padding: EdgeInsets.all(5),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      Row(
                        mainAxisSize: MainAxisSize.min,
                        children: <Widget>[
                          Container(
                            padding: EdgeInsets.zero,
                            margin: EdgeInsets.zero,
                            height: 20,
                            width: 20,
                            child: Icon(
                              Icons.crop_square,
                              color: Colors.red,
                              size: 18,
                            ),
                          ),
                          Flexible(
                            child: Text(
                              'The overflowing RenderFlex has an orientation of Axis.horizontal.',
                              overflow: TextOverflow.ellipsis,
                              softWrap: true,
                              style: TextStyle(
                                  fontSize: 13,
                                  fontWeight: FontWeight.w600,
                                  color: Theme.of(context).primaryColor),
                            ),
                          )
                        ],
                      ),
                      SizedBox(height: 5),
                      Text(
                        'The overflowing RenderFlex has an orientation of Axis.horizontal.',
                        maxLines: 1,
                        style: TextStyle(
                            fontSize: 12,
                            fontWeight: FontWeight.w500,
                            color: Colors.grey),
                      ),
                      SizedBox(height: 5),
                      Text(
                        '₹${listOfProduct[index].price ?? ''}',
                        style: TextStyle(
                            fontSize: 13,
                            fontWeight: FontWeight.w700,
                            color: Colors.black),
                      )
                    ],
                  ),
                )
              ],
            ),
          ),
        ),
      ),
    );
  }

enter image description here

我尝试了许多Que./Ans。在stackOverFlow上,但是没有成功。

2 个答案:

答案 0 :(得分:2)

更新的代码具有固定的溢出错误。必须在您的小部件树中进行很大的更改。

Widget productDisplayListView() {
return Card(
  elevation: 4,
  child: Container(
    padding: EdgeInsets.all(6),
    child: Row(
      children: <Widget>[
        Container(
          height: 110,
          width: 90,
          child: Image.network(
            'https://placeimg.com/250/250/any',
            fit: BoxFit.cover,
          ),
        ),
        SizedBox(
          width: 5.0,
        ),
        Flexible(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              MergeSemantics(
                child: Row(
                  children: <Widget>[
                    Icon(
                      Icons.crop_square,
                      color: Colors.red,
                      size: 18,
                    ),
                    Flexible(
                      child: Text(
                        'The overflowing RenderFlex has an orientation of Axis.horizontal.',
                        overflow: TextOverflow.ellipsis,
                        softWrap: true,
                        style: TextStyle(
                            fontSize: 13,
                            fontWeight: FontWeight.w600,
                            color: Theme.of(context).primaryColor),
                      ),
                    )
                  ],
                ),
              ),
              SizedBox(height: 5),
              Text(
                'The overflowing RenderFlex has an orientation of Axis.horizontal.',
                maxLines: 1,
                style: TextStyle(
                    fontSize: 12,
                    fontWeight: FontWeight.w500,
                    color: Colors.grey),
              ),
              SizedBox(height: 5),
              Text(
                '₹ 10,000',
                style: TextStyle(
                    fontSize: 13,
                    fontWeight: FontWeight.w700,
                    color: Colors.black),
              )
            ],
          ),
        )
      ],
    ),
  ),
);
}

输出:

enter image description here

答案 1 :(得分:0)

检查行添加列小部件。如果任何行或列小部件具有单个灵活子级,将发生错误

这样做可以解决您的问题:-

<execution>