Search packages, repositories and app categories

detectable_text_field cover
Package detailsv3.0.2

detectable_text_field

TextField with detection features. You can detect hashtags, at sign, url or anything you want. Helps you develop Twitter like app. Refinement of hashtagable

AndroidiOSWebmacOSWindowsLinux
30-day downloads
3.5K
Likes
165
Pub points
130

Install package

flutter pub add detectable_text_field

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

A Flutter text field that detects and highlights specific patterns like hashtags, @mentions, URLs, and custom regex patterns in real time. Designed for building social media apps similar to Twitter, it enhances user input with interactive text parsing. The package refines the functionality of its predecessor, hashtagable, by offering greater flexibility and customization. It supports multiple platforms including Android, iOS, Web, macOS, Windows, and Linux, making it ideal for cross-platform rich-text applications.

Use cases

  • Social media app development
  • Real-time text pattern detection
  • Twitter-like input fields
  • Custom text highlighting
  • Rich text editing in messaging apps
  • Interactive URL and tag recognition

Key features

  • Supports custom regex pattern detection
  • Real-time text parsing
  • Configurable highlight styles
  • Cross-platform compatibility
  • Easy integration with existing TextField
  • Extensible for additional pattern types

Suitable for

  • Developers building social networking apps
  • Apps requiring dynamic text formatting
  • Teams creating rich-text input components
  • Flutter developers targeting multiple platforms
  • Users wanting advanced text field behavior

Considerations

  • Requires careful regex configuration for custom patterns
  • May impact performance with complex patterns
  • Limited documentation beyond basic usage
  • Not optimized for extremely long text inputs
  • Depends on external GitHub repository for updates

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

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!

Categories

Dependencies

Dependency list 1 items

Source repository

Projects using this package

No data available yet.