Last active
March 13, 2019 01:42
-
-
Save yizems/609c09c8e6509fbdf75f3b61f5a6abd0 to your computer and use it in GitHub Desktop.
flutter : 计算文本总高度是否超出msxline 和 给定高度
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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