I\'ve painted a shape for the background of my content of Text.
I want the background autoscale the Text, even the softWrap being true.>
from inspiring of the Günter Zöchbauer
List _calcLastLineEnd(String msg) {
// self-defined constraint
final constraints = BoxConstraints(
maxWidth: 800.0, // maxwidth calculated
minHeight: 30.0,
minWidth: 80.0,
);
final richTextWidget =
Text.rich(TextSpan(text: msg)).build(context) as RichText;
final renderObject = richTextWidget.createRenderObject(context);
renderObject.layout(constraints);
final boxes = renderObject.getBoxesForSelection(TextSelection(
baseOffset: 0, extentOffset: TextSpan(text: msg).toPlainText().length));
bool needPadding = false, needNextline = false;
if (boxes.length < 2 && boxes.last.right < 630) needPadding = true;
if (boxes.length < 2 && boxes.last.right > 630) needNextline = true;
if (boxes.length > 1 && boxes.last.right > 630) needNextline = true;
return [needPadding, needNextline];
}