Skip to content

Instantly share code, notes, and snippets.

@yizems
Last active March 13, 2019 01:42
Show Gist options
  • Save yizems/609c09c8e6509fbdf75f3b61f5a6abd0 to your computer and use it in GitHub Desktop.
Save yizems/609c09c8e6509fbdf75f3b61f5a6abd0 to your computer and use it in GitHub Desktop.
flutter : 计算文本总高度是否超出msxline 和 给定高度
https://github.com/leisim/auto_size_text/blob/master/lib/src/text_util.dart#L5
import 'dart:ui';
import 'package:flutter/widgets.dart';
bool checkTextFits(TextSpan text, Locale locale, double scale, int maxLines,
double maxWidth, double maxHeight) {
var tp = TextPainter(
text: text,
textAlign: TextAlign.left,
textDirection: TextDirection.ltr,
textScaleFactor: scale ?? 1,
maxLines: maxLines,
locale: locale,
);
tp.layout(maxWidth: maxWidth);
return !(tp.didExceedMaxLines ||
tp.height > maxHeight ||
tp.width > maxWidth);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment