extended_text icon indicating copy to clipboard operation
extended_text copied to clipboard

ExtendedText文本渲染错位

Open blueloveTH opened this issue 3 years ago • 10 comments

下图激活selection,可以看到,选中的位置和文本真实位置有一点错位,随着文本行数不断增加,这种错位逐渐累计,变得越来越明显。

Screenshot_2021-09-13-01-53-35-028_com example ex

该问题的复现方法:

import 'package:extended_text/extended_text.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("测试"),),
      body: ListView(
        children: [
          ExtendedText(
            "测试测试测试 ----\n   1123\n"*100,
            selectionEnabled: true,
            style: TextStyle(fontSize: 14),
          )
        ],
      ),
    );
  }
}

版本:Flutter 2.2.3 平台:Android(Windows似乎没有这个问题)

此外,ExtendedTextField也没有这个问题

blueloveTH avatar Sep 12 '21 17:09 blueloveTH

等官方重构之后,我会重新也重构新的,暂时不做处理了。

zmtzawqlp avatar Sep 13 '21 01:09 zmtzawqlp

等官方重构之后,我会重新也重构新的,暂时不做处理了。

啊....那要啥时候更新呀> < 现在有什么workaround吗

blueloveTH avatar Sep 13 '21 07:09 blueloveTH

官方的会吗

zmtzawqlp avatar Sep 13 '21 07:09 zmtzawqlp

官方的会吗

官方是指啥,我的项目用了ExtendedTextField和SpecialSpanBuilder,有办法兼容这些吗。

是在做一个类似论坛的显示,不可避免有长文本,所以挺着急的。错位之后,图片的显示也都不正常。

blueloveTH avatar Sep 13 '21 08:09 blueloveTH

官方就是flutter 官方的呢

zmtzawqlp avatar Sep 14 '21 01:09 zmtzawqlp

@zmtzawqlp 官方的不会,我的一款 App 元思笔记之前为了支持 Markdown 的渲染后拷贝切换到了 ExtendedText 后也遇到了,文本越长渲染偏差越明显。

shidenggui avatar Jan 30 '22 04:01 shidenggui

请问下这个问题有计划解决吗?如果有的话不知道有没有大概的时间表。

shidenggui avatar Mar 10 '22 07:03 shidenggui

你看看最新的版本也有这个问题吗。。这个问题不好调查。。整个绘制其实是 textpainter做的

zmtzawqlp avatar Mar 10 '22 09:03 zmtzawqlp

亲测把ExtendedRichText换成官方的Text.rich没有这个问题。

// extended_text.dart
// ...
    Widget result;
    if (selectionEnabled) {
      /*
      result = ExtendedTextSelection(
        textAlign: textAlign ?? defaultTextStyle.textAlign ?? TextAlign.start,
        textDirection: textDirection ??
            Directionality.of(
                context), // RichText uses Directionality.of to obtain a default if this is null.
        locale:
            locale, // RichText uses Localizations.localeOf to obtain a default if this is null
        softWrap: softWrap ?? defaultTextStyle.softWrap,
        overflow: overflow ?? defaultTextStyle.overflow,
        textScaleFactor:
            textScaleFactor ?? MediaQuery.textScaleFactorOf(context),
        maxLines: maxLines ?? defaultTextStyle.maxLines,
        text: innerTextSpan,
        selectionColor: selectionColor,
        dragStartBehavior: dragStartBehavior,
        onTap: onTap,
        data: (joinZeroWidthSpace ? data?.joinChar() : data) ??
            textSpanToActualText(innerTextSpan),
        textSelectionControls: selectionControls,
        textHeightBehavior:
            textHeightBehavior ?? defaultTextStyle.textHeightBehavior,
        textWidthBasis: textWidthBasis ?? defaultTextStyle.textWidthBasis,
        overFlowWidget: overflowWidget,
        strutStyle: strutStyle,
      );
      */
    } else {
      /*
      result = ExtendedRichText(
        textAlign: textAlign ?? defaultTextStyle.textAlign ?? TextAlign.start,
        textDirection: textDirection ??
            Directionality.of(
                context), // RichText uses Directionality.of to obtain a default if this is null.
        locale:
            locale, // RichText uses Localizations.localeOf to obtain a default if this is null
        softWrap: softWrap ?? defaultTextStyle.softWrap,
        overflow: overflow ?? defaultTextStyle.overflow,
        textScaleFactor:
            textScaleFactor ?? MediaQuery.textScaleFactorOf(context),
        maxLines: maxLines ?? defaultTextStyle.maxLines,
        text: innerTextSpan,
        textHeightBehavior:
            textHeightBehavior ?? defaultTextStyle.textHeightBehavior,
        textWidthBasis: textWidthBasis ?? defaultTextStyle.textWidthBasis,
        overflowWidget: overflowWidget,
        hasFocus: false,
        strutStyle: strutStyle,
      );
      if (overflowWidget != null) {
        result = RepaintBoundary(
          child: result,
        );
      }
      */
    }

    /*
    if (semanticsLabel != null) {
      result = Semantics(
        textDirection: textDirection,
        label: semanticsLabel,
        child: ExcludeSemantics(
          child: result,
        ),
      );
    }*/

    result = Text.rich(
      innerTextSpan,
      style: style,
      strutStyle: strutStyle,
      textAlign: textAlign ?? defaultTextStyle.textAlign ?? TextAlign.start,
      textDirection: textDirection ??
          Directionality.of(
              context), // RichText uses Directionality.of to obtain a default if this is null.
      locale: locale, // RichText uses Localizations.localeOf to obtain a default if this is null
      softWrap: softWrap ?? defaultTextStyle.softWrap,
      overflow: overflow ?? defaultTextStyle.overflow,
      textScaleFactor: textScaleFactor ?? MediaQuery.textScaleFactorOf(context),
      maxLines: maxLines ?? defaultTextStyle.maxLines,
      textWidthBasis: textWidthBasis ?? defaultTextStyle.textWidthBasis,
      textHeightBehavior: textHeightBehavior ?? defaultTextStyle.textHeightBehavior,
    );

    return result;
  }

blueloveTH avatar Mar 19 '22 08:03 blueloveTH

我试了下。当内容很长的时候。官方也会出现这个问题。

zmtzawqlp avatar Mar 27 '22 11:03 zmtzawqlp

please check it on lastest version, reopen if need.

zmtzawqlp avatar Jun 01 '23 05:06 zmtzawqlp