flutter_MyBilibili
flutter_MyBilibili copied to clipboard
danmakuTile的动画起止点问题
danmaku_tile.dart中出了以下几处魔数,我研究了一下,提供几个改进思路,欢迎指正
controller = AnimationController(
duration: Duration(seconds: **15**),
vsync: this,
);
animation =
Tween(end: max-widget.danmaku.msg.length.toDouble() * **12**, begin: -widget.danmaku.msg.length.toDouble() * **15**)
其实window.physicalSize提供返回的大小并不正确(永远是屏幕分辨率),可用MediaQuery.of(context).size
替换试试看。
另外text大小可以测量,可以用MediaQuery.of(context).size,但要先渲染一个透明的text才能测
下面的方法似乎更好一点
Size _getTextSize(String str, TextStyle textStyle, BoxConstraints constrain){
//字符串的空格会直接造成函数返回空格出现前第一段字符串的大小,原因不明,所以删掉。
int spaceCount = ' '.allMatches(str).length;
str = str.replaceAll(" ", "");
RenderParagraph renderParagraph = RenderParagraph(
TextSpan(text: str, style: textStyle,),
textDirection: TextDirection.ltr,
);
renderParagraph.layout(constrain);
double width = renderParagraph.getMinIntrinsicWidth(textStyle.fontSize);
double height = renderParagraph.getMinIntrinsicHeight(textStyle.fontSize);
return Size(width, height);
}
好的,谢谢。我尝试一下。
可以删掉。。。重新配置了一下环境,空格又不会影响了 int spaceCount = ' '.allMatches(str).length; str = str.replaceAll(" ", ""); 很迷