使用并自定义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 (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...