pw.Text(descDiv, textAlign: pw.TextAlign.left, style:const pw.TextStyle(fontSize: 10)),
但是文本溢出不起作用
pw.Text(descDiv, textAlign: pw.TextAlign.left, style:const pw.TextStyle(fontSize: 10), overflow: pw.TextOverflow.ellipsis,),
有人帮助我吗??
你可以试试这个功能
String handleOverflow(String text, double maxWidth) {
const ellipsis = '...';
if (text.length <= 3 || maxWidth <= 0) {
return text;
}
final ellipsisWidth = ellipsis.characters.length * 5;
while (text.length > 1 && text.length * 5 > maxWidth - ellipsisWidth) {
text = text.substring(0, text.length - 1);
}
return text + ellipsis;
}
然后像这样使用它
pw.Text(
handleOverflow(descDiv, 200),
textAlign: pw.TextAlign.left,
style: pw.TextStyle(fontSize: 10),
)