
โจ rich_highlight_text_codespark
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

๐ ๏ธ 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 substringx
Highlight multiple substringsx
Support for different highlight modesSelectableText
๐ 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