Flutter 使用和自定义Flatter ExtendedTextFeild Pakage后,当突出显示单词时,光标将转到文本字段的开头
当一个单词是从一个特定字符开始时,我想突出显示textfeild中的文本。为此,我使用了扩展文本字段pacage()。 我修改AtText类并创建HashText,以便突出显示从hash(#)开始的单词。但问题是,当我键入任何#单词或@word时,光标会移到行的开头。 AtText类是Flutter 使用和自定义Flatter ExtendedTextFeild Pakage后,当突出显示单词时,光标将转到文本字段的开头,flutter,dart,flutter-packages,Flutter,Dart,Flutter Packages,当一个单词是从一个特定字符开始时,我想突出显示textfeild中的文本。为此,我使用了扩展文本字段pacage()。 我修改AtText类并创建HashText,以便突出显示从hash(#)开始的单词。但问题是,当我键入任何#单词或@word时,光标会移到行的开头。 AtText类是 import 'package:extended_text_field/extended_text_field.dart'; import 'package:flutter/gestures.dart'; imp
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,
actualText: atText,
start: start,
style: textStyle,
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, 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,
actualText: atText,
start: start,
style: textStyle,
recognizer: (TapGestureRecognizer()
..onTap = () {
if (onTap != null) onTap(atText);
}));
}
}