flutter_MyBilibili icon indicating copy to clipboard operation
flutter_MyBilibili copied to clipboard

danmakuTile的动画起止点问题

Open tagerjump opened this issue 4 years ago • 2 comments

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);
  }

tagerjump avatar Nov 17 '19 06:11 tagerjump

好的,谢谢。我尝试一下。

nekomiyaxneko avatar Nov 18 '19 08:11 nekomiyaxneko

可以删掉。。。重新配置了一下环境,空格又不会影响了 int spaceCount = ' '.allMatches(str).length; str = str.replaceAll(" ", ""); 很迷

tagerjump avatar Nov 20 '19 02:11 tagerjump