Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 使用和自定义Flatter ExtendedTextFeild Pakage后,当突出显示单词时,光标将转到文本字段的开头_Flutter_Dart_Flutter Packages - Fatal编程技术网

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

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

当一个单词是从一个特定字符开始时,我想突出显示textfeild中的文本。为此,我使用了扩展文本字段pacage()。 我修改AtText类并创建HashText,以便突出显示从hash(#)开始的单词。但问题是,当我键入任何#单词或@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,
            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);
              }));
  }
}