搜尋套件、儲存庫與 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 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。