Banner

โœจ rich_highlight_text_codespark

Pub Version
GitHub

Highlight specific substrings within your Flutter Text widgets effortlessly. Whether it's a single word or multiple phrases, rich_highlight_text_codespark provides a seamless way to emphasize parts of your text with customizable styles.

๐ŸŽฏ Fully null-safe and optimized for performance.

๐Ÿš€ Features

  • โœ… Highlight single or multiple substrings
  • โœ… Support for case-sensitive and case-insensitive matching
  • โœ… Highlight modes: first occurrence, last occurrence, or all occurrences
  • โœ… Handles overlapping and adjacent matches gracefully
  • โœ… Customizable highlight styles
  • โœ… Seamless integration with existing Text widgets

๐Ÿ“ฆ Installation

Add the following to your pubspec.yaml:

dependencies:
  rich_highlight_text: ^1.0.0

Then, run:

flutter pub get

๐Ÿงช Usage

๐Ÿ” Highlight a Single Substring

import 'package:flutter/material.dart';
import 'package:rich_highlight_text/rich_highlight_text.dart';

Text(
  'Welcome to Flutter!',
  style: TextStyle(fontSize: 18),
).highlight(
  'Flutter',
  highlightStyle: TextStyle(color: Colors.blue, fontWeight: FontWeight.bold),
);
'Flutter is fun and powerful!'.toRichText(
  style: TextStyle(fontSize: 18),
  highlights: ['Flutter', 'powerful'],
  highlightStyle: TextStyle(color: Colors.orange, fontWeight: FontWeight.bold),
  onTap: (text) {
    print('Tapped: $text');
  },
);
Text(
  'Flutter is fun and powerful!',
  style: TextStyle(fontSize: 18),
).highlight(
  'Flutter',
  highlightStyle: TextStyle(
    color: Colors.blue,
    fontWeight: FontWeight.bold,
    decoration: TextDecoration.underline,
  ),
  onTap: (text) {
    ScaffoldMessenger.of(context).showSnackBar(
      SnackBar(content: Text('You tapped on "$text"!')),
    );
  },
);

โœจ Highlight Multiple Substrings

Text(
  'Flutter makes development faster and easier.',
  style: TextStyle(fontSize: 18),
).highlightMultiple(
  ['Flutter', 'faster', 'easier'],
  highlightStyle: TextStyle(color: Colors.green, fontWeight: FontWeight.bold),
);

๐ŸŽฏ Highlight Modes

  • HighlightMode.all: Highlights all occurrences (default)
  • HighlightMode.first: Highlights only the first occurrence
  • HighlightMode.last: Highlights only the last occurrence
Text(
  'Flutter is awesome. Flutter is fast.',
  style: TextStyle(fontSize: 18),
).highlight(
  'Flutter',
  highlightStyle: TextStyle(color: Colors.red),
  highlightMode: HighlightMode.first,
);

๐Ÿ“ธ Preview

Highlight Example 1

๐Ÿ› ๏ธ API Reference

highlight

Text highlight(
  String highlightText, {
  TextStyle? highlightStyle,
  bool caseSensitive = true,
  HighlightMode highlightMode = HighlightMode.all,
  // Additional Text parameters...
});

highlightMultiple

Text highlightMultiple(
  List<String> highlightTexts, {
  TextStyle? highlightStyle,
  bool caseSensitive = true,
  HighlightMode highlightMode = HighlightMode.all,
  // Additional Text parameters...
});

๐Ÿ“ˆ Roadmap

  • x Highlight single substring
  • x Highlight multiple substrings
  • x Support for different highlight modes
  • Support for regular expressions
  • Animation support for highlights
  • Integration with SelectableText

๐ŸŒ Internationalization

โœ… Supports Unicode and multilingual characters. ๐ŸŒ Fully compatible with languages like Arabic, Chinese, Hindi, and more.

๐Ÿ“‚ Example

Clone the repository and navigate to the example/ directory:

git clone https://github.com/Katayath-Sai-Kiran/rich_highlight_text.git
cd rich_highlight_text/example
flutter run

๐Ÿ™Œ Contributions

Contributions are welcome! Please open issues and submit pull requests for any features, bugs, or enhancements.

๐Ÿ‘จโ€๐Ÿ’ป Maintainer

Developed with โค๏ธ by Katayath Sai Kiran