使用并自定义Flutter ExtendedTextFeild Pakage后,突出显示单词时,光标将转到文本字段的开头

问题描述

当单词从特定字符开始时,我想突出显示文本中的文本。为此,我使用了 extended_text_field pakage(https://pub.dev/packages/extended_text_field)。 我修改了AtText类并创建了HashText,以便应突出显示以hash(#)开头的单词。但是问题在于,当我键入任何#word或@word时,光标会移动到该行的开头。 AtText类是

import 'package:extended_text_field/extended_text_field.dart';
import 'package:Flutter/gestures.dart';
import 'package:Flutter/material.dart';

class AtText extends SpecialText {
  static const String flag = "@";
  final int start;

  /// whether show background for @somebody
  final bool showAtBackground;

  AtText(TextStyle textStyle,SpecialTextGestureTapCallback onTap,{this.showAtBackground: false,this.start})
      : super(
          flag," ",textStyle,);

  @override
  Inlinespan finishText() {
    TextStyle textStyle =
        this.textStyle?.copyWith(color: Colors.blue,fontSize: 16.0);

    final String atText = toString();

    return showAtBackground
        ? BackgroundTextSpan(
            background: Paint()..color = Colors.blue.withOpacity(0.15),text: atText,actualText: atText,start: start,///caret can move into special text
            deleteall: true,style: textStyle,recognizer: (TapGestureRecognizer()
              ..onTap = () {
                if (onTap != null) onTap(atText);
              }))
        : SpecialTextSpan(
            text: atText,recognizer: (TapGestureRecognizer()
              ..onTap = () {
                if (onTap != null) onTap(atText);
              }));
  }
}

HashText类是

import 'package:extended_text_field/extended_text_field.dart';
import 'package:Flutter/gestures.dart';
import 'package:Flutter/material.dart';

class HashText extends SpecialText {
  static const String flag = "#";
  final int start;

  /// whether show background for #something
  final bool showAtBackground;

  HashText(TextStyle textStyle,recognizer: (TapGestureRecognizer()
              ..onTap = () {
                if (onTap != null) onTap(atText);
              }));
  }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)