tag_highlight_text 1.0.3 copy "tag_highlight_text: ^1.0.3" to clipboard
tag_highlight_text: ^1.0.3 copied to clipboard

This library will support highlight text by tags with specific styles and tap actions.

Tag Highlight Text Library #

This library will support highlight text by tags with specific styles and tap actions.

Usage #

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

Example #

Import the library

import 'package:tag_highlight_text/tag_highlight_text.dart';

You need use tags to mark highlight texts

final text = 'This is <highlight>Highlight <bold>Text</bold></highlight>. Click <link>here</link>';

After, call the TagHighlightText widget and define highlightBuilder to set style and tap actions for each tags.

TagHighlightText(
  text: text,
  highlightBuilder: (tagName) {
    switch (tagName) {
      case 'highlight':
        return HighlightData(
          style: TextStyle(
            color: Colors.red,
          ),
        );
      case 'bold':
        return HighlightData(
          style: TextStyle(
            fontWeight: FontWeight.bold,
          ),
        );
      case 'link':
        return HighlightData(
          style: TextStyle(
            color: Colors.blue,
            decoration: TextDecoration.underline,
          ),
          onTap: (text) {
            print('Click ' + text);
          },
        );
      return null;
    }
  },
  textStyle: TextStyle(
    color: Colors.black,
    fontSize: 18,
  ),
),

You can custom build content of mark highlight texts by builder

TagHighlightText(
  text: text,
  highlightBuilder: (tagName) {
    switch (tagName) {
      case 'highlight':
        return HighlightData(
          builder: (text) => WidgetSpan(
            child: CupertinoButton(
              onPressed: () {
                // TODO
              },
              child: Text(text),
            ),
          ),
        );
      return null;
    }
  },
  textStyle: TextStyle(
    color: Colors.black,
    fontSize: 18,
  ),
),
12
likes
150
points
1.06k
downloads

Publisher

unverified uploader

Weekly Downloads

This library will support highlight text by tags with specific styles and tap actions.

Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

flutter

More

Packages that depend on tag_highlight_text