cache
This commit is contained in:
@@ -11,20 +11,25 @@ class Measure {
|
||||
: _measureMap = {},
|
||||
_textScaler = TextScaler.linear(textScaleFactor);
|
||||
|
||||
TextPainter computeText(Text text, {double? maxWidth}) {
|
||||
TextPainter computeText(Text text, {TextStyle? style, double? maxWidth}) {
|
||||
return TextPainter(
|
||||
text: TextSpan(text: text.data, style: text.style),
|
||||
text: TextSpan(text: text.data, style: text.style ?? style),
|
||||
maxLines: text.maxLines,
|
||||
textScaler: _textScaler,
|
||||
textDirection: text.textDirection ?? TextDirection.ltr,
|
||||
)..layout(maxWidth: maxWidth ?? double.infinity);
|
||||
}
|
||||
|
||||
Size computeTextSize(Text text, {double? maxWidth}) {
|
||||
final textPainter = computeText(text, maxWidth: maxWidth);
|
||||
Size computeTextSize(Text text, {TextStyle? style, double? maxWidth}) {
|
||||
final textPainter = computeText(text, style: style, maxWidth: maxWidth);
|
||||
return textPainter.size;
|
||||
}
|
||||
|
||||
bool computeTextIsOverflow(Text text, {TextStyle? style, double? maxWidth}) {
|
||||
final textPainter = computeText(text, style: style, maxWidth: maxWidth);
|
||||
return textPainter.didExceedMaxLines;
|
||||
}
|
||||
|
||||
double get bodyMediumHeight {
|
||||
return _measureMap.updateCacheValue(
|
||||
'bodyMediumHeight',
|
||||
|
||||
@@ -14,8 +14,11 @@ class TooltipText extends StatelessWidget {
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final maxWidth = constraints.maxWidth;
|
||||
final tp = globalState.measure.computeText(text, maxWidth: maxWidth);
|
||||
if (tp.didExceedMaxLines) {
|
||||
final isOverflow = globalState.measure.computeTextIsOverflow(
|
||||
text,
|
||||
maxWidth: maxWidth,
|
||||
);
|
||||
if (isOverflow) {
|
||||
return Tooltip(
|
||||
triggerMode: TooltipTriggerMode.longPress,
|
||||
preferBelow: false,
|
||||
|
||||
Reference in New Issue
Block a user