搜索插件、代码仓与 APP 分类

detectable_text_field 封面
插件详情v3.0.2

detectable_text_field

带有检测功能的 TextField。您可以检测话题标签、@符号、URL 或任何您想要的内容。有助于开发类似 Twitter 的应用。对 hashtagable 的优化。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
3540
喜欢数
165
Pub 分数
130

安装插件

flutter pub add detectable_text_field

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个 Flutter 文本字段,可实时检测并高亮显示特定模式,如标签、@提及、URL 和自定义正则表达式模式。专为构建类似 Twitter 的社交媒体应用而设计,通过交互式文本解析增强用户输入体验。该包在前代产品 hashtagable 的基础上进行了优化,提供了更高的灵活性和可定制性。支持 Android、iOS、Web、macOS、Windows 和 Linux 等多个平台,非常适合跨平台富文本应用开发。

适合场景

  • 社交媒体应用开发
  • 实时文本模式检测
  • 类似 Twitter 的输入字段
  • 自定义文本高亮
  • 消息应用中的富文本编辑
  • 交互式 URL 和标签识别

主要特点

  • 支持自定义正则表达式模式检测
  • 实时文本解析
  • 可配置的高亮样式
  • 跨平台兼容性
  • 与现有 TextField 的轻松集成
  • 可扩展以支持其他模式类型

适合对象

  • 开发社交网络应用的开发者
  • 需要动态文本格式化的应用
  • 创建富文本输入组件的团队
  • 面向多平台的 Flutter 开发人员
  • 希望获得高级文本字段行为的用户

使用建议

  • 需要仔细配置正则表达式以用于自定义模式
  • 可能会影响复杂模式的性能
  • 除了基本用法外,文档有限
  • 未针对极长文本输入进行优化
  • 依赖外部 GitHub 仓库以获取更新

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

detectable_text_field

All Contributors

pub package License: MIT

Text widgets with detection features. You can detect hashtags, at sign, url, or anything you want. Helps you develop Twitter like app.

Refinement of hashtagable.

final

Usage

DetectableTextField
    DetectableTextField(
      detectionRegExp: detectionRegExp(),
      detectedStyle: TextStyle(
        fontSize: 20,
        color: Colors.blue,
      ),
    )
  • detectionRegExp decides the text to detect.
  • detectedStyle is the textStyle for detected text.
DetectableTextEditingController

DetectableTextEditingController allows you to listen to the typingDetection. Ideal for features like live hashtag or mention detection.


    final controller = DetectableTextEditingController(
      regExp: detectionRegExp(),
    );
    
    @override
    void initState() {
      super.initState();
      controller.addListener(() {
        setState(() {});
      });
    }
    
    @override
    Widget build(BuildContext context) {
      return Column(
        mainAxisSize: MainAxisSize.min,
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Text(
            'Typing detection: ${controller.typingDetection}',
          ),
          DetectableTextField(
            controller: controller,
          ),
        ],
      );
    }

DetectableTextEditingController extends TextEditingController, so you can use it with TextField, TextFormField or any other widgets that accept TextEditingController.

If you use flutter_hooks, useDetectableTextEditingController is also available.

DetectableText

If you want to use detection feature in the text only to display, use DetectableText.

    DetectableText(
      text: "#HashTag and @AtSign and https://pub.dev/packages/detectable_text_field",
      detectionRegExp: detectionRegExp(),
      detectedStyle: TextStyle(
        fontSize: 20,
        color: Colors.blue,
      ),
      basicStyle: TextStyle(
        fontSize: 20,
      ),
      onTap: (tappedText){
        print(tappedText);
      },
    )

Usage of the arguments like detectionRegExp are same as the ones in DetectableTextField.

The argument onTap(String) is called when user tapped a detected text.

detectionRegExp()

The widgets and methods in this package is expected to be used with RegExp.

The function detectionRegExp() returns sample regExp depending on the boolean arguments: hashtag , atSign, and url.They are all true by default.

If you see the API reference , you will see the function just returns the sample regular expressions below. You can use them directly if you want.

sample regExp hashtag atSign url
hashTagRegExp ○ × ×
atSignRegExp × ○ ×
urlRegExp × × ○
hashTagAtSignRegExp ○ ○ ×
hashTagUrlRegExp ○ × ○
AtSignUrlRegExp × ○ ○
hashTagAtSignUrlRegExp ○ ○ ○
  • The detection rules are almost same as X(formally twitter).
    1. It needs space before # or @.
    2. It stops # and @ detection if there's emoji or symbol.
  • The examples currently support six languages: English, Japanese, Korean, Spanish, Arabic, and Thai.
Customize with useful functions
  • Check if there are detections
  print(isDetected("Hello #World", hashTagRegExp));
// true

  print(isDetected("Hello World", hashTagRegExp));
// false

  • Extract detections from text

  final List<String> detections = extractDetections(
    "#Hello World #Flutter Dart #Thank you", 
    hashTagRegExp,
  );
  // ["#Hello", "#Flutter", "#Thank"]

If you have any requests or questions, please feel free to ask on github.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Santa Takahashi
Santa Takahashi

💻
Paresh Patil
Paresh Patil

💻
Joseph Muller
Joseph Muller

💻
Esteve Aguilera
Esteve Aguilera

💻
MATTYGILO
MATTYGILO

💻
Abdullahi A. Addow
Abdullahi A. Addow

💻
Social Jawn
Social Jawn

💻
xuxiaowei13
xuxiaowei13

💻
debuggerx01
debuggerx01

💻
furukaze-akane
furukaze-akane

💻
drown0315
drown0315

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目

暂无相关数据。