Search packages, repositories and app categories

Package detailsv1.8.0

highlight_text

With this package you can highlight words and create specific styles and actions.

AndroidiOSWebmacOSWindowsLinux
30-day downloads
11K
Likes
133
Pub points
150

Install package

flutter pub add highlight_text

Package Overview

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

The highlight_text package enables developers to highlight specific words within text and apply custom styles and interactive actions. It is ideal for rich text displays where certain keywords need visual emphasis or functionality, such as clickable terms. The package supports multiple platforms including Android, iOS, Web, macOS, Windows, and Linux, making it versatile for cross-platform applications. With simple integration via Flutter pub add, it enhances user engagement through dynamic text interactions.

Use cases

  • Highlighting keywords in articles
  • Creating interactive text elements
  • Enhancing search result previews
  • Displaying styled mentions or hashtags
  • Building rich text editors
  • Implementing clickable word actions

Key features

  • Customizable highlight styles
  • Support for tap gestures on highlighted words
  • Cross-platform compatibility
  • Easy integration with Flutter
  • Flexible text rendering
  • Configurable highlight colors and effects

Suitable for

  • Content-heavy apps
  • Educational applications
  • Interactive documentation
  • Social media features
  • Search and filter interfaces
  • User-generated content platforms

Considerations

  • Performance impact with large text blocks
  • Limited built-in styling options beyond basic customization
  • Requires careful handling of nested widgets
  • May need additional logic for complex interactions
  • Not optimized for real-time collaborative editing
  • Best suited for moderate text complexity

Original README

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

Highlight Text Plugin

A flutter package to highlight words from a text.

Usage

To use this package, add highlight_text as a dependency in your pubspec.yaml file.

Getting Started

With this package you can highlight words and create specific actions for each highlighted word, you can customize the style of each word separately or create a unique style for all of them, you can also customize the style of the rest of the text.

Example

Import the highlight library

import 'package:highlight_text/highlight_text.dart';

You should use the HighlightedWord class to specify the dictionary words in a Map object

Map<String, HighlightedWord> words = {
    "Flutter": HighlightedWord(
        onTap: () {
            print("Flutter");
        },
        textStyle: textStyle,
    ),
    "open-source": HighlightedWord(
        onTap: () {
            print("open-source");
        },
        textStyle: textStyle,
    ),
    "Android": HighlightedWord(
        onTap: () {
            print("Android");
        },
        textStyle: textStyle,
    ),
};

Now you can call the TextHighlight widget

TextHighlight(
    text: text, // You need to pass the string you want the highlights
    words: words, // Your dictionary words
    textStyle: TextStyle( // You can set the general style, like a Text()
        fontSize: 20.0,
        color: Colors.black,
    ),
    textAlign: TextAlign.justify, // You can use any attribute of the RichText widget
),

Package example image

1.1.0 Update

Now you can customize better the words you highlight, just like a Container. It was added decoration and padding fields to HighlightedWord object, so you can do whatever you want to customize it.

HighlightedWord(
    onTap: () {},
    textStyle: textStyle,
    decoration: BoxDecoration(
        color: Colors.green,
        borderRadius: BorderRadius.circular(50),
    ),
    padding: EdgeInsets.all(8.0),
),

1.2.0 Breaking changes

enableCaseSensitive renamed to matchCase to be clearer about what it does

TextHighlight(
    text: text,
    words: words,
    matchCase: true // will highlight only exactly the same string
),

Categories

Source repository

Projects using this package