
β¨ 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