Skip to content

TextField and Text widget with detection features. You can detect hashtags, at sign, or anything you want.

License

Notifications You must be signed in to change notification settings

Perceive-Software-Solutions/detectable_text_field

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

detectable_text_field

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

As TextField

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

  • Other arguments are basically same as material TextField.

As ReadOnlyText

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

    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.

You can add some actions in this callback with the tapped text.

detectionRegExp()

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

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

If you do NOT want to detect atSign, you need to set the argument like this: detectionRegExp(atSign:false). It is same for other arguments.

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 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.

About

TextField and Text widget with detection features. You can detect hashtags, at sign, or anything you want.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Dart 98.3%
  • HTML 1.2%
  • Other 0.5%