Warm tip: This article is reproduced from stackoverflow.com, please click
flutter text-widget

TextOverFlow.ellipsis in Widget Text not work

发布于 2020-03-27 15:44:28

enter image description here

my widget text Wrap inside Expanded, row, and Column

return Container(
          child: Expanded(
            flex: 9,
            child: GestureDetector(
              onTap: () {
                // .......
              },
              child: Container(
                color: Colors.transparent,
                child: Row(
                  children: <Widget>[
                    Padding(
                        padding: EdgeInsets.only(top: 15, bottom: 15),
                        child: Container(
                          width: 2,
                          color: Color(0XFF2B9FDC),
                        )),
                    Padding(
                      padding: EdgeInsets.only(left: 15),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: <Widget>[
                          Text( item.name,
                            overflow: TextOverflow.ellipsis,
                            maxLines: 2,
                          ),
                          Text(item.catgeory),
                          Text(item.price,
                            style: TextStyle(color: Colors.red),
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ),
        ); 

I got error : Another exception was thrown: A RenderFlex overflowed by 7.3 pixels on the right.

AnyOne can help?

Questioner
0917237
Viewed
115
A R 2020-01-31 17:39

Just wrap your container with Expanded and use flex property as per your design and let me know its working or not

 return Expanded(
      child: Container(
        child: GestureDetector(
          onTap: () {
            // .......
          },
          child: Container(
            color: Colors.transparent,
            child: Row(
              children: <Widget>[
                Padding(
                    padding: EdgeInsets.only(top: 15, bottom: 15),
                    child: Container(
                      width: 2,
                      color: Color(0XFF2B9FDC),
                    )),
                Padding(
                  padding: EdgeInsets.only(left: 15),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Text( item.name,
                        overflow: TextOverflow.ellipsis,
                        maxLines: 2,
                      ),
                      Text(item.catgeory),
                      Text(item.price,
                        style: TextStyle(color: Colors.red),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );