Flutter 防止Text內容溢出產生警告(黃色塊)

Text內容過多時,屏幕上會出現溢出,即黃色塊

以下是解決方案

 Container(
                        alignment: Alignment.centerLeft,
                        width: px(120),
                        margin: EdgeInsets.only(left: px(50)),
                        child: Text(toK(count),
                            style: TextStyle(
                                fontSize: px(24),
                                color: Color(0xFFACB5CA),
                                fontFamily: Font.din,
                                fontWeight: FontWeight.bold),
                          maxLines: 1,
                          overflow: TextOverflow.ellipsis,
                         )),

外面套個Container,給定寬度,然後在裏面的Text加2個屬性即可
maxLines: 1, //做多支持一行
overflow: TextOverflow.ellipsis,// 內容過多顯示不下時,末尾顯示省略號

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章